Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 645c724

Browse filesBrowse files
committed
Clear context in original message before dispatch
1 parent 59ec120 commit 645c724
Copy full SHA for 645c724

File tree

1 file changed

+5
-8
lines changed
Filter options

1 file changed

+5
-8
lines changed

‎src/Symfony/Component/Mailer/Mailer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Mailer.php
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,24 @@ public function send(RawMessage $message, Envelope $envelope = null): void
4545
return;
4646
}
4747

48-
$clonedMessage = clone $message;
49-
50-
// When dispatching a message using messenger, we clear the context to prevent serialization errors
51-
if ($clonedMessage instanceof TemplatedEmail) {
52-
$clonedMessage->context([]);
53-
}
54-
$clonedEnvelope = null !== $envelope ? clone $envelope : Envelope::create($clonedMessage);
55-
5648
$stamps = [];
5749
if (null !== $this->dispatcher) {
5850
// The dispatched event here has `queued` set to `true`; the goal is NOT to render the message, but to let
5951
// listeners do something before a message is sent to the queue.
6052
// We are using a cloned message as we still want to dispatch the **original** message, not the one modified by listeners.
6153
// That's because the listeners will run again when the email is sent via Messenger by the transport (see `AbstractTransport`).
6254
// Listeners should act depending on the `$queued` argument of the `MessageEvent` instance.
55+
$clonedMessage = clone $message;
56+
$clonedEnvelope = null !== $envelope ? clone $envelope : Envelope::create($clonedMessage);
6357
$event = new MessageEvent($clonedMessage, $clonedEnvelope, (string) $this->transport, true);
6458
$this->dispatcher->dispatch($event);
6559
$stamps = $event->getStamps();
6660
}
6761

6862
try {
63+
if ($message instanceof TemplatedEmail) {
64+
$message->context([]);
65+
}
6966
$this->bus->dispatch(new SendEmailMessage($message, $envelope), $stamps);
7067
} catch (HandlerFailedException $e) {
7168
foreach ($e->getNestedExceptions() as $nested) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.