Skip to content
Snippets Groups Projects
Commit bdc38a94 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Adam G-H
Browse files

Issue #3366499 by kunal.sachdev, phenaproxima: In CronUpdateStage if...

Issue #3366499 by kunal.sachdev, phenaproxima: In CronUpdateStage if postApply() fails no update email will be sent
parent d9210f6f
No related branches found
No related tags found
2 merge requests!989Issue #3356804 by phenaproxima: Flag a warning during status check if the...,!913Issue #3366499: In CronUpdateStage if postApply() fails no update email will be sent
...@@ -355,28 +355,28 @@ class CronUpdateStage extends UpdateStage implements CronInterface { ...@@ -355,28 +355,28 @@ class CronUpdateStage extends UpdateStage implements CronInterface {
$this->claim($stage_id); $this->claim($stage_id);
$this->logger->info(
'Drupal core has been updated from %previous_version to %target_version',
[
'%previous_version' => $installed_version,
'%target_version' => $target_version,
]
);
// Send notifications about the successful update.
$mail_params = [
'previous_version' => $installed_version,
'updated_version' => $target_version,
];
foreach ($this->statusCheckMailer->getRecipients() as $recipient => $langcode) {
$this->mailManager->mail('automatic_updates', 'cron_successful', $recipient, $langcode, $mail_params);
}
// Run post-apply tasks in their own try-catch block so that, if anything // Run post-apply tasks in their own try-catch block so that, if anything
// raises an exception, we'll log it and proceed to destroy the stage as // raises an exception, we'll log it and proceed to destroy the stage as
// soon as possible (which is also what we do in ::performUpdate()). // soon as possible (which is also what we do in ::performUpdate()).
try { try {
$this->postApply(); $this->postApply();
$this->logger->info(
'Drupal core has been updated from %previous_version to %target_version',
[
'%previous_version' => $installed_version,
'%target_version' => $target_version,
]
);
// Send notifications about the successful update.
$mail_params = [
'previous_version' => $installed_version,
'updated_version' => $target_version,
];
foreach ($this->statusCheckMailer->getRecipients() as $recipient => $langcode) {
$this->mailManager->mail('automatic_updates', 'cron_successful', $recipient, $langcode, $mail_params);
}
} }
catch (\Throwable $e) { catch (\Throwable $e) {
$this->logger->error($e->getMessage()); $this->logger->error($e->getMessage());
......
...@@ -462,6 +462,33 @@ END; ...@@ -462,6 +462,33 @@ END;
$this->assertRegularCronRun(FALSE); $this->assertRegularCronRun(FALSE);
} }
/**
* Tests that a success email is sent even when post-apply tasks fail.
*/
public function testEmailSentIfPostApplyFails(): void {
$this->getStageFixtureManipulator()->setCorePackageVersion('9.8.1');
$exception = new \Exception('Error during running post-apply tasks!');
TestSubscriber1::setException($exception, PostApplyEvent::class);
$this->container->get('cron')->run();
$this->assertRegularCronRun(FALSE);
$this->assertTrue($this->logger->hasRecord($exception->getMessage(), (string) RfcLogLevel::ERROR));
// Ensure we sent a success email to all recipients, even though post-apply
// tasks failed.
$expected_body = <<<END
Congratulations!
Drupal core was automatically updated from 9.8.0 to 9.8.1.
This e-mail was sent by the Automatic Updates module. Unattended updates are not yet fully supported.
If you are using this feature in production, it is strongly recommended for you to visit your site and ensure that everything still looks good.
END;
$this->assertMessagesSent("Drupal core was successfully updated", $expected_body);
}
/** /**
* Tests that regular cron runs if not update is available. * Tests that regular cron runs if not update is available.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment