8000 bug #48092 Fix the notification email theme for asynchronously dispat… · symfony/symfony@e1641da · GitHub
[go: up one dir, main page]

Skip to content

Commit e1641da

Browse files
committed
bug #48092 Fix the notification email theme for asynchronously dispatched emails (krisbuist)
This PR was merged into the 4.4 branch. Discussion ---------- Fix the notification email theme for asynchronously dispatched emails | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT 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. Commits ------- 4b843d1 Fix the notification email theme for asynchronously dispatched emails
2 parents 9b22123 + 4b843d1 commit e1641da

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Symfony/Bridge/Twig/Mime/NotificationEmail.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,20 @@ private function getExceptionAsString($exception): string
210210
*/
211211
public function __serialize(): array
212212
{
213-
return [$this->context, parent::__serialize()];
213+
return [$this->context, $this->theme, parent::__serialize()];
214214
}
215215

216216
/**
217217
FA3F * @internal
218218
*/
219219
public function __unserialize(array $data): void
220220
{
221-
[$this->context, $parentData] = $data;
221+
if (3 === \count($data)) {
222+
[$this->context, $this->theme, $parentData] = $data;
223+
} else {
224+
// Backwards compatibility for deserializing data structures that were serialized without the theme
225+
[$this->context, $parentData] = $data;
226+
}
222227

223228
parent::__unserialize($parentData);
224229
}

src/Symfony/Bridge/Twig/Tests/Mime/NotificationEmailTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function testSerialize()
4646
->importance(NotificationEmail::IMPORTANCE_HIGH)
4747
->action('Bar', 'http://example.com/')
4848
->context(['a' => 'b'])
49+
->theme('example')
4950
));
5051
$this->assertEquals([
5152
'importance' => NotificationEmail::IMPORTANCE_HIGH,
@@ -57,6 +58,8 @@ public function testSerialize()
5758
'raw' => true,
5859
'a' => 'b',
5960
], $email->getContext());
61+
62+
$this->assertSame('@email/example/notification/body.html.twig', $email->getHtmlTemplate());
6063
}
6164

6265
public function testTheme()

0 commit comments

Comments
 (0)
0