diff --git a/src/Controller/PollController.php b/src/Controller/PollController.php index 26476f2..3567909 100644 --- a/src/Controller/PollController.php +++ b/src/Controller/PollController.php @@ -257,11 +257,18 @@ class PollController extends AbstractController { // public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) { public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_vote' ) { $em = $this->getDoctrine()->getRepository( Owner::class ); - $foundOwner = $em->find( 1 ); - $poll = $foundOwner->getPolls()[ 0 ]; - $comment = $foundOwner->getComments()[ 0 ]; + $foundOwner = $em->findOneByEmail( $emailChoice ); + if($foundOwner){ + $poll = $foundOwner->getPolls()[ 0 ]; + $comment = $foundOwner->getComments()[ 0 ]; + + $sent = $mail_service->sendCreationMailAction( $foundOwner, $poll ); + if($sent){ + return $this->json(["message"=>"test email sent!"],200); + } + } + return $this->json(["message"=>"user with this email was not found"],400); - $mail_service->sendCreationMailAction( $foundOwner, $poll ); } diff --git a/src/Service/MailService.php b/src/Service/MailService.php index 9b3ef31..bd2ba1a 100644 --- a/src/Service/MailService.php +++ b/src/Service/MailService.php @@ -32,12 +32,11 @@ class MailService { /** * @param Owner $foundOwner - * @param Poll $poll - * @param Mailer $mailer + * @param Poll|null $poll * * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface */ - public function sendCreationMailAction( Owner $foundOwner, Poll $poll) { + public function sendCreationMailAction( Owner $foundOwner, Poll $poll = null) { // anti spam , limit to every minute TODO @@ -45,7 +44,7 @@ class MailService { 'owner' => $foundOwner, 'from' => 'ne-pas-repondre@framadate-api.cipherbliss.com', 'poll' => $poll, - 'title' => 'Création de sondage - ' . $poll->getTitle(), + 'title' => 'Création de sondage - ' . ($poll? $poll->getTitle() : $poll), 'email_template' => 'emails/creation-mail.html.twig', ]; @@ -103,6 +102,9 @@ class MailService { */ public function sendMailWithVars( $config ) { + if(!$config['poll']){ + $config['poll'] = new Poll(); + } $emailChoicesTemplates = [ 'creation_poll' => 'creation-mail.html.twig', 'edit_poll' => 'modification-notification-mail.html.twig',