Skip to content
Snippets Groups Projects
Commit b946839a authored by Theresa Grannum's avatar Theresa Grannum Committed by Adam G-H
Browse files

Issue #3277562 by tedbow, phenaproxima, percoction, mherman-pro: "Site is in...

Issue #3277562 by tedbow, phenaproxima, percoction, mherman-pro: "Site is in maintenance mode" message still appears even after the update is complete
parent 0886b28a
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ namespace Drupal\automatic_updates\Controller; ...@@ -4,6 +4,7 @@ namespace Drupal\automatic_updates\Controller;
use Drupal\automatic_updates\BatchProcessor; use Drupal\automatic_updates\BatchProcessor;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\package_manager\Validator\PendingUpdatesValidator; use Drupal\package_manager\Validator\PendingUpdatesValidator;
...@@ -74,6 +75,17 @@ class UpdateController extends ControllerBase { ...@@ -74,6 +75,17 @@ class UpdateController extends ControllerBase {
// previously not in maintenance mode. // previously not in maintenance mode.
if (!$request->getSession()->remove(BatchProcessor::MAINTENANCE_MODE_SESSION_KEY)) { if (!$request->getSession()->remove(BatchProcessor::MAINTENANCE_MODE_SESSION_KEY)) {
$this->state()->set('system.maintenance_mode', FALSE); $this->state()->set('system.maintenance_mode', FALSE);
// @todo Remove once the core bug that shows the maintenance mode
// message after the site is out of maintenance mode is fixed in
// https://www.drupal.org/i/3279246.
$messages = $this->messenger()->messagesByType(MessengerInterface::TYPE_STATUS);
$messages = array_filter($messages, function (string $message) {
return !str_starts_with($message, (string) $this->t('Operating in maintenance mode.'));
});
$this->messenger()->deleteByType(MessengerInterface::TYPE_STATUS);
foreach ($messages as $message) {
$this->messenger()->addStatus($message);
}
} }
} }
$this->messenger()->addStatus($message); $this->messenger()->addStatus($message);
......
...@@ -579,7 +579,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -579,7 +579,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertUpdateStagedTimes(1); $this->assertUpdateStagedTimes(1);
$this->assertUpdateReady('9.8.1'); $this->assertUpdateReady('9.8.1');
// Confirm that the site was put into maintenance mode if needed. // Confirm that the site was put into maintenance mode if needed.
$this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on); $this->assertMaintenanceMode($maintenance_mode_on);
$page->pressButton('Continue'); $page->pressButton('Continue');
$this->checkForMetaRefresh(); $this->checkForMetaRefresh();
$assert_session->addressEquals('/admin/reports/updates'); $assert_session->addressEquals('/admin/reports/updates');
...@@ -589,7 +589,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -589,7 +589,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertTrue($state->get(PreApplyEvent::class . '.system.maintenance_mode')); $this->assertTrue($state->get(PreApplyEvent::class . '.system.maintenance_mode'));
$assert_session->pageTextContainsOnce('Update complete!'); $assert_session->pageTextContainsOnce('Update complete!');
// Confirm the site was returned to the original maintenance mode state. // Confirm the site was returned to the original maintenance mode state.
$this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on); $this->assertMaintenanceMode($maintenance_mode_on);
} }
/** /**
...@@ -678,6 +678,25 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -678,6 +678,25 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
return $message; return $message;
} }
/**
* Asserts maintenance is the expected value and correct message appears.
*
* @param bool $expected_maintenance_mode
* Whether maintenance mode is expected to be on or off.
*/
private function assertMaintenanceMode(bool $expected_maintenance_mode): void {
$this->assertSame($this->container->get('state')
->get('system.maintenance_mode'), $expected_maintenance_mode);
if ($expected_maintenance_mode) {
$this->assertSession()
->pageTextContains('Operating in maintenance mode.');
}
else {
$this->assertSession()
->pageTextNotContains('Operating in maintenance mode.');
}
}
/** /**
* Asserts that no update buttons exist. * Asserts that no update buttons exist.
*/ */
......
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