From 937575ebee4f757a7821228d565552db477fe82e Mon Sep 17 00:00:00 2001
From: Angie Byron <webchick@24967.no-reply.drupal.org>
Date: Mon, 3 Jan 2011 02:53:07 +0000
Subject: [PATCH] #976328 by bfroehle, dww: Fixed Update manager should not
 take you out of maintenance mode unless you asked it to

---
 modules/update/update.authorize.inc | 36 ++++++++++++++++++-----------
 modules/update/update.manager.inc   |  2 ++
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/modules/update/update.authorize.inc b/modules/update/update.authorize.inc
index 16029568b025..978fee4a42c1 100644
--- a/modules/update/update.authorize.inc
+++ b/modules/update/update.authorize.inc
@@ -182,7 +182,8 @@ function update_authorize_update_batch_finished($success, $results) {
     // update data and recompute our status, so prevent show bogus results.
     _update_authorize_clear_update_status();
 
-    if ($offline) {
+    // Take the site out of maintenance mode if it was previously that way.
+    if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) {
       variable_set('maintenance_mode', FALSE);
       $page_message = array(
         'message' => t('Update was completed successfully. Your site has been taken out of maintenance mode.'),
@@ -213,6 +214,9 @@ function update_authorize_update_batch_finished($success, $results) {
   $results['tasks'][] = t('Your modules have been downloaded and updated.');
   $results['tasks'][] = t('<a href="@update">Run database updates</a>', array('@update' => base_path() . 'update.php'));
 
+  // Unset the variable since it is no longer needed.
+  unset($_SESSION['maintenance_mode']);
+
   // Set all these values into the SESSION so authorize.php can display them.
   $_SESSION['authorize_results']['success'] = $success;
   $_SESSION['authorize_results']['page_message'] = $page_message;
@@ -235,18 +239,21 @@ function update_authorize_install_batch_finished($success, $results) {
     }
   }
   $offline = variable_get('maintenance_mode', FALSE);
-  if ($success && $offline) {
-    variable_set('maintenance_mode', FALSE);
-    $page_message = array(
-      'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'),
-      'type' => 'status',
-    );
-  }
-  elseif ($success && !$offline) {
-    $page_message = array(
-      'message' => t('Installation was completed successfully.'),
-      'type' => 'status',
-    );
+  if ($success) {
+    // Take the site out of maintenance mode if it was previously that way.
+    if ($offline && isset($_SESSION['maintenance_mode']) && $_SESSION['maintenance_mode'] == FALSE) {
+      variable_set('maintenance_mode', FALSE);
+      $page_message = array(
+        'message' => t('Installation was completed successfully. Your site has been taken out of maintenance mode.'),
+        'type' => 'status',
+      );
+    }
+    else {
+      $page_message = array(
+        'message' => t('Installation was completed successfully.'),
+        'type' => 'status',
+      );
+    }
   }
   elseif (!$success && !$offline) {
     $page_message = array(
@@ -261,6 +268,9 @@ function update_authorize_install_batch_finished($success, $results) {
     );
   }
 
+  // Unset the variable since it is no longer needed.
+  unset($_SESSION['maintenance_mode']);
+
   // Set all these values into the SESSION so authorize.php can display them.
   $_SESSION['authorize_results']['success'] = $success;
   $_SESSION['authorize_results']['page_message'] = $page_message;
diff --git a/modules/update/update.manager.inc b/modules/update/update.manager.inc
index 9f0fb8cb72bb..4f55b1b5b34d 100644
--- a/modules/update/update.manager.inc
+++ b/modules/update/update.manager.inc
@@ -397,6 +397,8 @@ function update_manager_update_ready_form($form, &$form_state) {
  * @see system_authorized_get_url()
  */
 function update_manager_update_ready_form_submit($form, &$form_state) {
+  // Store maintenance_mode setting so we can restore it when done.
+  $_SESSION['maintenance_mode'] = variable_get('maintenance_mode', FALSE);
   if ($form_state['values']['maintenance_mode'] == TRUE) {
     variable_set('maintenance_mode', TRUE);
   }
-- 
GitLab