feat(EmailCommand): Ajoute une commande pour purger les emails supprimés.

 feat(ansible): Ajoute une tâche cron pour purger les emails supprimés.
♻️ refactor(CustomerController): Ajoute la restauration d'une boite mail.
This commit is contained in:
Serreau Jovann
2025-09-27 15:27:33 +02:00
parent 384a61717e
commit 95c1a665ad
3 changed files with 69 additions and 1 deletions

View File

@@ -202,7 +202,13 @@
hour: "21"
job: "php {{ path }}/bin/console mainframe:cron:customer"
user: root
- name: "Cron Task purge email delete"
cron:
name: "Mainframe - Purge customer"
minute: "0"
hour: "21"
job: "php {{ path }}/bin/console mainframe:cron:email"
user: root
- name: "Cron Task sync"
ansible.builtin.cron:
name: "Mainframe - Sync"

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Command;
use App\Entity\Account;
use App\Entity\Customer;
use App\Entity\CustomerDnsEmail;
use App\Service\Generator\TempPasswordGenerator;
use App\Service\Mailer\Event\CreatedAdminEvent;
use Doctrine\ORM\EntityManagerInterface;
use Exbil\MailCowAPI;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
#[AsCommand(name: 'mainframe:cron:email')]
class EmailCommand extends Command
{
public function __construct(private readonly EventDispatcherInterface $eventDispatcher, private readonly EntityManagerInterface $entityManager, ?string $name = null)
{
parent::__construct($name);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title("Purge all mail delete");
foreach ($this->entityManager->getRepository(CustomerDnsEmail::class)->findBy(['isDeleted'=>true]) as $delete) {
$io->info("Delete account - ".$delete->getEmail());
$client = new MailCowAPI('mail.esy-web.dev',$_ENV['MAILCOW_KEY']);
$email = $delete->getEmail()."@".$delete->getDns()->getNdd();
try {
$client->mailBoxes()->deleteMailBox([$email]);
} catch (\Exception $e) {
$io->error($e);
}
$this->entityManager->remove($delete);
}
$this->entityManager->flush();
return Command::SUCCESS;
}
}

View File

@@ -278,6 +278,18 @@ class CustomerController extends AbstractController
return $this->redirectToRoute('artemis_intranet_customer_view',['id'=>$customer->getId(),'current'=>'order','currentOrder'=>'d']);
}
}
if($request->query->has('idEmailRestore')) {
$emailDelete = $entityManager->getRepository(CustomerDnsEmail::class)->find($request->query->get('idEmailRestore'));
$emailDelete->setIsDeleted(false);
$entityManager->persist($emailDelete);
$entityManager->flush();
$loggerService->log("RESTORE","Restauration de la boite mail - ".$emailDelete->getEmail());
$this->addFlash("success","Restauration de la boite mail");
return $this->redirectToRoute('artemis_intranet_customer_view',['id'=>$customer->getId(),'current'=>'email','idNdd'=>$emailDelete->getDns()->getId()]);
}
if($request->query->has('idEmailDelete')) {
$emailDelete = $entityManager->getRepository(CustomerDnsEmail::class)->find($request->query->get('idEmailDelete'));
$emailDelete->setIsDeleted(true);