✨ 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:
@@ -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"
|
||||
|
||||
50
src/Command/EmailCommand.php
Normal file
50
src/Command/EmailCommand.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user