From 4b843d1eeae5e3b8b62affbcc08fa9e9acf72b0a Mon Sep 17 00:00:00 2001 From: Kris Buist Date: Thu, 3 Nov 2022 10:41:56 +0100 Subject: [PATCH] Fix the notification email theme for asynchronously dispatched emails When the `\Symfony\Component\Mailer\Messenger\SendEmailMessage` is dispatched asynchronously, the email message is serialised and unserialised. The theme that was set on the `NotificationEmail` was not included in the serialisation, causing the value to return back to the default after deserialisation. --- src/Symfony/Bridge/Twig/Mime/NotificationEmail.php | 9 +++++++-- .../Bridge/Twig/Tests/Mime/NotificationEmailTest.php | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php index 1a58aa5e5e5bc..382928a982da2 100644 --- a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php @@ -210,7 +210,7 @@ private function getExceptionAsString($exception): string */ public function __serialize(): array { - return [$this->context, parent::__serialize()]; + return [$this->context, $this->theme, parent::__serialize()]; } /** @@ -218,7 +218,12 @@ public function __serialize(): array */ public function __unserialize(array $data): void { - [$this->context, $parentData] = $data; + if (3 === \count($data)) { + [$this->context, $this->theme, $parentData] = $data; + } else { + // Backwards compatibility for deserializing data structures that were serialized without the theme + [$this->context, $parentData] = $data; + } parent::__unserialize($parentData); } diff --git a/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php b/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php index 6c5b4a4bf579e..0b55ca01d6b3e 100644 --- a/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php @@ -46,6 +46,7 @@ public function testSerialize() ->importance(NotificationEmail::IMPORTANCE_HIGH) ->action('Bar', 'http://example.com/') ->context(['a' => 'b']) + ->theme('example') )); $this->assertEquals([ 'importance' => NotificationEmail::IMPORTANCE_HIGH, @@ -57,6 +58,8 @@ public function testSerialize() 'raw' => true, 'a' => 'b', ], $email->getContext()); + + $this->assertSame('@email/example/notification/body.html.twig', $email->getHtmlTemplate()); } public function testTheme() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy