|
|
@@ -10,6 +10,8 @@ use Symfony\Component\Mailer\MailerInterface;
|
|
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|
|
use Symfony\Component\Mime\Address;
|
|
|
use Symfony\Component\Mime\Email as SymfonyEmail;
|
|
|
+use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
+use Throwable;
|
|
|
|
|
|
#[AsMessageHandler(priority: 1)]
|
|
|
class OrganizationCreationHandler
|
|
|
@@ -19,19 +21,25 @@ class OrganizationCreationHandler
|
|
|
private readonly MailerInterface $symfonyMailer,
|
|
|
) {}
|
|
|
|
|
|
+ /**
|
|
|
+ * @throws Throwable
|
|
|
+ * @throws TransportExceptionInterface
|
|
|
+ * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
|
|
+ */
|
|
|
public function __invoke(OrganizationCreationCommand $organizationCreationCommand): void
|
|
|
{
|
|
|
$organizationCreationRequest = $organizationCreationCommand->getOrganizationCreationRequest();
|
|
|
+ $mail = ['subject' => '', 'content' => ''];
|
|
|
|
|
|
try {
|
|
|
$organization = $this->organizationFactory->create($organizationCreationRequest);
|
|
|
|
|
|
- $subject = 'New organization created';
|
|
|
- $message = 'The organization "' . $organization->getName() . '" has been created successfully.';
|
|
|
+ $mail['subject'] = 'New organization created';
|
|
|
+ $mail['content'] = 'The organization "' . $organization->getName() . '" has been created successfully.';
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
- $subject = 'Organization creation : an error occured';
|
|
|
- $message = 'An error occured while creating the new organization : \n' . $e->getMessage();
|
|
|
+ $mail['subject'] = 'Organization creation : an error occured';
|
|
|
+ $mail['content'] = 'An error occured while creating the new organization : \n' . $e->getMessage();
|
|
|
throw $e;
|
|
|
|
|
|
} finally {
|
|
|
@@ -41,8 +49,8 @@ class OrganizationCreationHandler
|
|
|
->replyTo('mail.report@opentalent.fr')
|
|
|
->returnPath(Address::create('mail.report@opentalent.fr'))
|
|
|
->to($organizationCreationRequest->getSendConfirmationEmailAt())
|
|
|
- ->subject($subject)
|
|
|
- ->text($message);
|
|
|
+ ->subject($mail['subject'])
|
|
|
+ ->text($mail['content']);
|
|
|
$this->symfonyMailer->send($symfonyMail);
|
|
|
}
|
|
|
}
|