Skip to content

Commit 9936be6

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: Fix #36973: Command description consistency Render email once
2 parents 4fa4380 + 888d492 commit 9936be6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

Command/DebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function configure()
6060
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'Show details for all entries matching this filter'),
6161
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (text or json)', 'text'),
6262
])
63-
->setDescription('Shows a list of twig functions, filters, globals and tests')
63+
->setDescription('Show a list of twig functions, filters, globals and tests')
6464
->setHelp(<<<'EOF'
6565
The <info>%command.name%</info> command outputs a list of twig functions,
6666
filters, globals and tests.

Command/LintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(Environment $twig)
4848
protected function configure()
4949
{
5050
$this
51-
->setDescription('Lints a template and outputs encountered errors')
51+
->setDescription('Lint a template and outputs encountered errors')
5252
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5353
->addOption('show-deprecations', null, InputOption::VALUE_NONE, 'Show deprecations as errors')
5454
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')

Mime/BodyRenderer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public function render(Message $message): void
4646
}
4747

4848
$messageContext = $message->getContext();
49+
50+
$previousRenderingKey = $messageContext[__CLASS__] ?? null;
51+
unset($messageContext[__CLASS__]);
52+
$currentRenderingKey = md5(serialize([$messageContext, $message->getTextTemplate(), $message->getHtmlTemplate()]));
53+
if ($previousRenderingKey === $currentRenderingKey) {
54+
return;
55+
}
56+
4957
if (isset($messageContext['email'])) {
5058
throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', get_debug_type($message)));
5159
}
@@ -66,6 +74,7 @@ public function render(Message $message): void
6674
if (!$message->getTextBody() && null !== $html = $message->getHtmlBody()) {
6775
$message->text($this->convertHtmlToText(\is_resource($html) ? stream_get_contents($html) : $html));
6876
}
77+
$message->context($message->getContext() + [__CLASS__ => $currentRenderingKey]);
6978
}
7079

7180
private function convertHtmlToText(string $html): string

Tests/Mime/BodyRendererTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ public function testRenderWithContextReservedEmailEntry()
7979
$this->prepareEmail('Text', '', ['email' => 'reserved!']);
8080
}
8181

82+
public function testRenderedOnce()
83+
{
84+
$twig = new Environment(new ArrayLoader([
85+
'text' => 'Text',
86+
]));
87+
$renderer = new BodyRenderer($twig);
88+
$email = (new TemplatedEmail())
89+
90+
91+
;
92+
$email->textTemplate('text');
93+
94+
$renderer->render($email);
95+
$this->assertEquals('Text', $email->getTextBody());
96+
97+
$email->text('reset');
98+
99+
$renderer->render($email);
100+
$this->assertEquals('reset', $email->getTextBody());
101+
}
102+
82103
private function prepareEmail(?string $text, ?string $html, array $context = []): TemplatedEmail
83104
{
84105
$twig = new Environment(new ArrayLoader([

0 commit comments

Comments
 (0)