aboutsummaryrefslogtreecommitdiff
path: root/src/EmailService.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/EmailService.php')
-rw-r--r--src/EmailService.php26
1 files changed, 23 insertions, 3 deletions
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
65 65
66 // copie en BDD 66 // copie en BDD
67 if(!$test_email){ 67 if(!$test_email){
68 $db_email = new Email($email, Config::$email_dest, $message); 68 $db_email = new Email($name, $email, Config::$email_dest, $message);
69 $entityManager->persist($db_email); 69 $entityManager->persist($db_email);
70 self::updateLastContactDate($entityManager, $email);
70 $entityManager->flush(); 71 $entityManager->flush();
71 } 72 }
72 73
73 return true; 74 return true;
74 } 75 }
75 catch(Exception $e){ 76 catch(Exception $e){
76 return false; 77 echo "Le message n'a pas pu être envoyé. Erreur : {$e} <br> {$mail->ErrorInfo}";
77 //echo "Le message n'a pas pu être envoyé. Erreur : {$mail->ErrorInfo}"; 78 return false;
78 } 79 }
79 } 80 }
81
82 static public function updateLastContactDate(EntityManager $entityManager, string $sender): void
83 {
84 foreach($entityManager->getRepository('App\Entity\Email')->findAll() as $email){
85 $email->getSenderAddress() === $sender ? $email->updateLastContactDate() : null;
86 }
87 }
88
89 // peut être appelée par bin/clean_emails_cron.php
90 static public function cleanEmails(EntityManager $entityManager): void
91 {
92 $emails = $entityManager->getRepository('App\Entity\Email')->findAll();
93 foreach($emails as $email){
94 if($email->getDeletionDate() < new \DateTime()){
95 $entityManager->remove($email);
96 }
97 }
98 $entityManager->flush();
99 }
80} \ No newline at end of file 100} \ No newline at end of file