From 423755b019a09111b971e36c53e2557e2f5a704f Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 16 Dec 2025 22:41:57 +0100 Subject: page emails, application du RGPD: table email et nettoyeur, renommage de $id_email --- src/EmailService.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/EmailService.php') diff --git a/src/EmailService.php b/src/EmailService.php index 1bcca0f..8671817 100644 --- a/src/EmailService.php +++ b/src/EmailService.php @@ -65,16 +65,36 @@ class EmailService // copie en BDD if(!$test_email){ - $db_email = new Email($email, Config::$email_dest, $message); + $db_email = new Email($name, $email, Config::$email_dest, $message); $entityManager->persist($db_email); + self::updateLastContactDate($entityManager, $email); $entityManager->flush(); } return true; } catch(Exception $e){ - return false; - //echo "Le message n'a pas pu être envoyé. Erreur : {$mail->ErrorInfo}"; + echo "Le message n'a pas pu être envoyé. Erreur : {$e}
{$mail->ErrorInfo}"; + return false; } } + + static public function updateLastContactDate(EntityManager $entityManager, string $sender): void + { + foreach($entityManager->getRepository('App\Entity\Email')->findAll() as $email){ + $email->getSenderAddress() === $sender ? $email->updateLastContactDate() : null; + } + } + + // peut être appelée par bin/clean_emails_cron.php + static public function cleanEmails(EntityManager $entityManager): void + { + $emails = $entityManager->getRepository('App\Entity\Email')->findAll(); + foreach($emails as $email){ + if($email->getDeletionDate() < new \DateTime()){ + $entityManager->remove($email); + } + } + $entityManager->flush(); + } } \ No newline at end of file -- cgit v1.2.3