From 192e70df296dad68e12961dfd2b35e7e7d007fbb Mon Sep 17 00:00:00 2001 From: phenaproxima <phenaproxima@205645.no-reply.drupal.org> Date: Tue, 18 Oct 2022 15:57:44 +0000 Subject: [PATCH] Issue #3315798 by phenaproxima, tedbow: Post-apply always fails during cron --- src/CronUpdater.php | 9 +++++++++ tests/src/Build/CoreUpdateTest.php | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/CronUpdater.php b/src/CronUpdater.php index 5239aa9161..5af93a252d 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -280,6 +280,15 @@ class CronUpdater extends Updater { * An empty 200 response if the post-apply tasks succeeded. */ public function handlePostApply(string $stage_id, string $installed_version, string $target_version): Response { + $owner = $this->tempStore->getMetadata(static::TEMPSTORE_LOCK_KEY) + ->getOwnerId(); + // Reload the tempstore with the correct owner ID so we can claim the stage. + // We use \Drupal::service() here because, given what we inherit from the + // parent class, there's no clean way to inject the shared tempstore + // factory. + $this->tempStore = \Drupal::service('tempstore.shared') + ->get('package_manager_stage', $owner); + $this->claim($stage_id); // Run post-apply tasks in their own try-catch block so that, if anything diff --git a/tests/src/Build/CoreUpdateTest.php b/tests/src/Build/CoreUpdateTest.php index e0e49cf5ef..55f1ebcfbc 100644 --- a/tests/src/Build/CoreUpdateTest.php +++ b/tests/src/Build/CoreUpdateTest.php @@ -121,11 +121,30 @@ class CoreUpdateTest extends UpdateTestBase { */ public function testCron(string $template): void { $this->createTestProject($template); + // Install dblog so we can check if any errors were logged during the update. + $this->installModules(['dblog']); $this->visit('/admin/reports/status'); $mink = $this->getMink(); - $mink->assertSession()->pageTextContains('Your site is ready for automatic updates.'); - $mink->getSession()->getPage()->clickLink('Run cron'); + $page = $mink->getSession()->getPage(); + $assert_session = $mink->assertSession(); + + $assert_session->pageTextContains('Your site is ready for automatic updates.'); + $page->clickLink('Run cron'); + $assert_session->statusCodeEquals(200); + + // There should be log messages, but no errors or warnings should have been + // logged by Automatic Updates. + $this->visit('/admin/reports/dblog'); + $assert_session->pageTextNotContains('No log messages available.'); + $page->selectFieldOption('Type', 'automatic_updates'); + $page->selectFieldOption('Severity', 'Emergency', TRUE); + $page->selectFieldOption('Severity', 'Alert', TRUE); + $page->selectFieldOption('Severity', 'Critical', TRUE); + $page->selectFieldOption('Severity', 'Warning', TRUE); + $page->pressButton('Filter'); + $assert_session->pageTextContains('No log messages available.'); + $this->assertUpdateSuccessful('9.8.1'); } -- GitLab