diff --git a/core/includes/session.inc b/core/includes/session.inc index e29216a..bd77cdc 100644 --- a/core/includes/session.inc +++ b/core/includes/session.inc @@ -7,14 +7,12 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Session\SessionHandler; -use Drupal\Core\Session\UserSession; use Drupal\Core\Utility\Error; /** * Initializes the session handler, starting a session if needed. */ function drupal_session_initialize() { - /** @var UserSession $user */ global $user; if (drupal_is_cli()) { @@ -86,7 +84,6 @@ function drupal_session_start() { * If an anonymous user already have an empty session, destroy it. */ function drupal_session_commit() { - /** @var UserSession $user */ global $user; if (!drupal_save_session() || drupal_is_cli()) { @@ -94,7 +91,7 @@ function drupal_session_commit() { return; } - if ($user->isAnonymous() && empty($_SESSION)) { + if ($user && $user->isAnonymous() && empty($_SESSION)) { // There is no session data to store, destroy the session if it was // previously started. if (drupal_session_started()) { @@ -127,7 +124,7 @@ function drupal_session_started($set = NULL) { if (isset($set)) { $session_started = $set; } - return $session_started && \PHP_SESSION_ACTIVE === session_status(); + return $session_started && session_status() === \PHP_SESSION_ACTIVE; } /** diff --git a/core/lib/Drupal/Core/Authentication/Provider/Cookie.php b/core/lib/Drupal/Core/Authentication/Provider/Cookie.php index 7c6c5fb..ae108dc 100644 --- a/core/lib/Drupal/Core/Authentication/Provider/Cookie.php +++ b/core/lib/Drupal/Core/Authentication/Provider/Cookie.php @@ -44,7 +44,7 @@ public function authenticate(Request $request) { * {@inheritdoc} */ public function cleanup(Request $request) { - drupal_session_commit(); # + drupal_session_commit(); } /** diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index 97ff354..80adf12 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -34,6 +34,13 @@ class SessionHandler implements \SessionHandlerInterface, DestructableInterface protected $connection; /** + * An array containing the sid and data from last read. + * + * @var array + */ + protected $lastRead; + + /** * Constructs a new SessionHandler instance. * * @param \Symfony\Component\HttpFoundation\Request $request @@ -118,9 +125,8 @@ public function read($sid) { $user = new UserSession(); } - // Store the session that was read for comparison in _drupal_session_write(). - $last_read = &drupal_static('drupal_session_last_read'); - $last_read = array( + // Store the session that was read for comparison in self::write(). + $this->lastRead = array( 'sid' => $sid, 'value' => $user->session, ); @@ -141,8 +147,7 @@ public function write($sid, $value) { return TRUE; } // Check whether $_SESSION has been changed in this request. - $last_read = &drupal_static('drupal_session_last_read'); - $is_changed = !isset($last_read) || $last_read['sid'] != $sid || $last_read['value'] !== $value; + $is_changed = empty($this->lastRead) || $this->lastRead['sid'] != $sid || $this->lastRead['value'] !== $value; // For performance reasons, do not update the sessions table, unless // $_SESSION has changed or more than 180 has passed since the last update.