From 421901f7fe4115490926b9d7d45c3c62aaf637de Mon Sep 17 00:00:00 2001
From: tedbow <tedbow@240860.no-reply.drupal.org>
Date: Wed, 2 Mar 2022 12:59:32 +0000
Subject: [PATCH] Issue #3266633 by tedbow: We don't currently actually set
 maintenance mode

---
 automatic_updates.routing.yml                            | 9 +++++++++
 src/Form/UpdateReady.php                                 | 2 +-
 .../automatic_updates_test.routing.yml                   | 4 ++++
 tests/src/Functional/ReadinessValidationTest.php         | 1 +
 tests/src/Functional/UpdaterFormTest.php                 | 6 ++++++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/automatic_updates.routing.yml b/automatic_updates.routing.yml
index c076655240..7c3d0a5e8b 100644
--- a/automatic_updates.routing.yml
+++ b/automatic_updates.routing.yml
@@ -5,6 +5,8 @@ automatic_updates.update_readiness:
     _title: 'Update readiness checking'
   requirements:
     _permission: 'administer software updates'
+  options:
+    _maintenance_access: TRUE
 automatic_updates.confirmation_page:
   path: '/admin/automatic-update-ready/{stage_id}'
   defaults:
@@ -13,12 +15,16 @@ automatic_updates.confirmation_page:
   requirements:
     _permission: 'administer software updates'
     _access_update_manager: 'TRUE'
+  options:
+    _maintenance_access: TRUE
 automatic_updates.finish:
   path: '/automatic-update/finish'
   defaults:
     _controller: '\Drupal\automatic_updates\Controller\UpdateController::onFinish'
   requirements:
     _permission: 'administer software updates'
+  options:
+    _maintenance_access: TRUE
 # Links to our updater form appear in three different sets of local tasks. To ensure the breadcrumbs and paths are
 # consistent with the other local tasks in each set, we need two separate routes to the same form.
 automatic_updates.report_update:
@@ -30,6 +36,7 @@ automatic_updates.report_update:
     _permission: 'administer software updates'
   options:
     _admin_route: TRUE
+    _maintenance_access: TRUE
 automatic_updates.module_update:
   path: '/admin/modules/automatic-update'
   defaults:
@@ -39,6 +46,7 @@ automatic_updates.module_update:
     _permission: 'administer software updates'
   options:
     _admin_route: TRUE
+    _maintenance_access: TRUE
 automatic_updates.theme_update:
   path: '/admin/theme/automatic-update'
   defaults:
@@ -48,3 +56,4 @@ automatic_updates.theme_update:
     _permission: 'administer software updates'
   options:
     _admin_route: TRUE
+    _maintenance_access: TRUE
diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php
index 6fd63c3fab..5c15518cdc 100644
--- a/src/Form/UpdateReady.php
+++ b/src/Form/UpdateReady.php
@@ -174,7 +174,7 @@ class UpdateReady extends FormBase {
     $session = $this->getRequest()->getSession();
     // Store maintenance_mode setting so we can restore it when done.
     $session->set('maintenance_mode', $this->state->get('system.maintenance_mode'));
-    if ($form_state->getValue('maintenance_mode') === TRUE) {
+    if ($form_state->getValue('maintenance_mode')) {
       $this->state->set('system.maintenance_mode', TRUE);
       // @todo unset after updater. After db update?
     }
diff --git a/tests/modules/automatic_updates_test/automatic_updates_test.routing.yml b/tests/modules/automatic_updates_test/automatic_updates_test.routing.yml
index bf9090ff7a..a25a826a86 100644
--- a/tests/modules/automatic_updates_test/automatic_updates_test.routing.yml
+++ b/tests/modules/automatic_updates_test/automatic_updates_test.routing.yml
@@ -5,9 +5,13 @@ automatic_updates_test.metadata:
     _controller: '\Drupal\automatic_updates_test\TestController::metadata'
   requirements:
     _access: 'TRUE'
+  options:
+    _maintenance_access: TRUE
 automatic_updates_test.update:
   path: '/automatic-update-test/update/{to_version}'
   defaults:
     _controller: '\Drupal\automatic_updates_test\TestController::update'
   requirements:
     _access: 'TRUE'
+  options:
+    _maintenance_access: TRUE
diff --git a/tests/src/Functional/ReadinessValidationTest.php b/tests/src/Functional/ReadinessValidationTest.php
index 877f98f551..072429fd49 100644
--- a/tests/src/Functional/ReadinessValidationTest.php
+++ b/tests/src/Functional/ReadinessValidationTest.php
@@ -64,6 +64,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
       'administer site configuration',
       'administer software updates',
       'access administration pages',
+      'access site in maintenance mode',
     ]);
     $this->createTestValidationResults();
     $this->drupalLogin($this->reportViewerUser);
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index 69093a54d9..0b9c505055 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -401,10 +401,16 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->checkForMetaRefresh();
     $this->assertUpdateStagedTimes(1);
     $this->assertUpdateReady();
+    $this->assertNotTrue($this->container->get('state')->get('system.maintenance_mode'));
     $page->pressButton('Continue');
     $this->checkForMetaRefresh();
     $assert_session = $this->assertSession();
     $assert_session->addressEquals('/admin/reports/updates');
+    // Assert that the site was put into maintenance mode.
+    // @todo Add test coverage to ensure that site is taken back out of
+    //   maintenance if it was not originally in maintenance mode when the
+    //   update started in https://www.drupal.org/i/3265057.
+    $this->assertTrue($this->container->get('state')->get('system.maintenance_mode'));
     $assert_session->pageTextContainsOnce('Update complete!');
   }
 
-- 
GitLab