From cdd43fb792ad5a602e13cd0f20f8dedc074277bc Mon Sep 17 00:00:00 2001 From: Akshay Kumar Date: Thu, 12 Jan 2023 22:20:28 +0530 Subject: [PATCH] Misc. code reformatting & bug fixes for sending emails from workflow events of type user --- Controller/Authentication.php | 10 +++++----- Services/EmailService.php | 9 +-------- Workflow/Actions/{ => User}/MailUser.php | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 24 deletions(-) rename Workflow/Actions/{ => User}/MailUser.php (78%) diff --git a/Controller/Authentication.php b/Controller/Authentication.php index e9338af63..2897e641a 100644 --- a/Controller/Authentication.php +++ b/Controller/Authentication.php @@ -82,15 +82,16 @@ public function forgotPassword(Request $request) { $entityManager = $this->getDoctrine()->getManager(); $recaptchaDetails = $this->recaptchaService->getRecaptchaDetails(); + if ($request->getMethod() == 'POST') { - if ($recaptchaDetails && $recaptchaDetails->getIsActive() == true && $this->recaptchaService->getReCaptchaResponse($request->request->get('g-recaptcha-response')) - ) { + if ($recaptchaDetails && $recaptchaDetails->getIsActive() == true && $this->recaptchaService->getReCaptchaResponse($request->request->get('g-recaptcha-response'))) { $this->addFlash('warning', $this->translator->trans("Warning ! Please select correct CAPTCHA !")); } else { $user = new User(); $form = $this->createFormBuilder($user,['csrf_protection' => false]) - ->add('email',EmailType::class) - ->getForm(); + ->add('email',EmailType::class) + ->getForm() + ; $form->submit(['email' => $request->request->get('forgot_password_form')['email']]); $form->handleRequest($request); @@ -110,7 +111,6 @@ public function forgotPassword(Request $request) $this->addFlash('success', $this->translator->trans('Please check your mail for password update')); return $this->redirect($this->generateUrl('helpdesk_knowledgebase')); - } else { $this->addFlash('warning', $this->translator->trans('This email address is not registered with us')); } diff --git a/Services/EmailService.php b/Services/EmailService.php index 8a31291cf..65cb45f8a 100644 --- a/Services/EmailService.php +++ b/Services/EmailService.php @@ -483,7 +483,6 @@ public function processEmailContent($content, array $emailPlaceholders = [], $is public function sendMail($subject, $content, $recipient, array $headers = [], $mailboxEmail = null, array $attachments = [], $cc = [], $bcc = []) { - $error_check = false; if (empty($mailboxEmail)) { // Send email on behalf of support helpdesk $supportEmail = $this->container->getParameter('uvdesk.support_email.id'); @@ -507,7 +506,6 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m return; } } catch (\Exception $e) { - $error_check = true; // @TODO: Log exception - Mailbox not found return; } @@ -519,7 +517,6 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m $mailer = $this->container->get('swiftmailer.mailer' . (('default' == $mailerID) ? '' : ".$mailerID")); $mailer->getTransport()->setPassword(base64_decode($mailer->getTransport()->getPassword())); } catch (\Exception $e) { - $error_check = true; // @TODO: Log exception - Mailer not found return; } @@ -588,12 +585,8 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m return "<$messageId>"; } catch (\Exception $e) { - $error_check = true; // @TODO: Log exception - } - - if ($error_check == true) { - $this->session->getFlashBag()->add('warning', $this->container->get('translator')->trans('Warning ! Swiftmailer not working. An error has occurred while sending emails!')); + $this->session->getFlashBag()->add('warning', $this->container->get('translator')->trans('Warning! Swiftmailer not working. An error has occurred while sending emails!')); } return null; diff --git a/Workflow/Actions/MailUser.php b/Workflow/Actions/User/MailUser.php similarity index 78% rename from Workflow/Actions/MailUser.php rename to Workflow/Actions/User/MailUser.php index 0f53372af..9cea11e42 100644 --- a/Workflow/Actions/MailUser.php +++ b/Workflow/Actions/User/MailUser.php @@ -1,6 +1,6 @@ getUser(); $entityManager = $container->get('doctrine.orm.entity_manager'); - if (!$event instanceof AgentActivity && !$event instanceof CustomerActivity) { + $emailTemplate = $entityManager->getRepository(EmailTemplates::class)->findOneById($value); + + if (empty($user) || empty($emailTemplate)) { + // @TODO: Send default email template return; - } else { - $user = $event->getUser(); - $emailTemplate = $entityManager->getRepository(EmailTemplates::class)->findOneById($value); - - if (empty($user) || empty($emailTemplate)) { - // @TODO: Send default email template - return; - } } $emailPlaceholders = $container->get('email.service')->getEmailPlaceholderValues($user);