#585628: provide a mechanism to keep anonymous sessions open for a given duration.

From:  <>


---

 includes/session.inc |   24 ++++++++++++++++++++++++
 update.php           |    5 +++++
 2 files changed, 29 insertions(+), 0 deletions(-)


diff --git includes/session.inc includes/session.inc
index fee6ec2..396c5c7 100644
--- includes/session.inc
+++ includes/session.inc
@@ -233,6 +233,11 @@ function drupal_session_commit() {
     return;
   }
 
+  // Expire the keep if possible.
+  if (isset($_SESSION['drupal_keep']) && ($_SESSION['drupal_keep'] > REQUEST_TIME)) {
+    unset($_SESSION['drupal_keep']);
+  }
+
   if (empty($user->uid) && empty($_SESSION)) {
     // There is no session data to store, destroy the session if it was
     // previously started.
@@ -263,6 +268,25 @@ function drupal_session_started($set = NULL) {
 }
 
 /**
+ * Keep the current user's session open for a given length of time.
+ *
+ * @param $duration The length the session needs to remain open, in seconds.
+ */
+function drupal_session_keep($duration) {
+  $new_timestamp = REQUEST_TIME + $duration;
+  if (!isset($_SESSION['drupal_keep']) || ($new_timestamp > $_SESSION['drupal_keep'])) {
+    $_SESSION['drupal_keep'] = $new_timestamp;
+  }
+}
+
+/**
+ * Stop keeping the current user's session open.
+ */
+function drupal_session_keep_reset() {
+  unset($_SESSION['drupal_keep']);
+}
+
+/**
  * Called when an anonymous user becomes authenticated or vice-versa.
  */
 function drupal_session_regenerate() {
diff --git update.php update.php
index 6151cad..5e3c9e6 100644
--- update.php
+++ update.php
@@ -359,5 +359,10 @@ else {
 if (isset($output) && $output) {
   // We defer the display of messages until all updates are done.
   $progress_page = ($batch = batch_get()) && isset($batch['running']);
+
+  // Commit the session data, force the session to stay open for 15 minutes.
+  drupal_session_keep(300);
+  drupal_session_commit();
+
   print theme('update_page', $output, !$progress_page);
 }
