/** * {@inheritdoc} */ public function destroy($sid) { global $user; // Nothing to do if we are not allowed to change the session. if (!$this->sessionManager->isEnabled()) { return TRUE; } $is_https = $this->requestStack->getCurrentRequest()->isSecure(); // Delete session data. $this->connection->delete('sessions')->condition($is_https ? 'ssid' : 'sid', Crypt::hashBase64($sid))->execute(); // Reset $_SESSION and $user to prevent a new session from being started // in \Drupal\Core\Session\SessionManager::save(). $_SESSION = array(); $user = new AnonymousUserSession(); // Unset the session cookies. $this->deleteCookie($this->getName()); if ($is_https) { $this->deleteCookie($this->sessionManager->getInsecureName(), FALSE); } elseif ($this->sessionManager->isMixedMode()) { $this->deleteCookie('S' . $this->getName(), TRUE); } // Remove obsolete sessions. $this->cleanupObsoleteSessions(); return TRUE; }
/** * {@inheritdoc} */ public function run() { // Allow execution to continue even if the request gets cancelled. @ignore_user_abort(TRUE); // Prevent session information from being saved while cron is running. $original_session_saving = $this->sessionManager->isEnabled(); $this->sessionManager->disable(); // Force the current user to anonymous to ensure consistent permissions on // cron runs. $original_user = $this->currentUser->getAccount(); $this->currentUser->setAccount(new AnonymousUserSession()); // Try to allocate enough time to run all the hook_cron implementations. drupal_set_time_limit(240); $return = FALSE; // Try to acquire cron lock. if (!$this->lock->acquire('cron', 900.0)) { // Cron is still running normally. $this->logger->warning('Attempting to re-run cron while it is already running.'); } else { $this->invokeCronHandlers(); $this->setCronLastTime(); // Release cron lock. $this->lock->release('cron'); // Return TRUE so other functions can check if it did run successfully $return = TRUE; } // Process cron queues. $this->processQueues(); // Restore the user. $this->currentUser->setAccount($original_user); if ($original_session_saving) { $this->sessionManager->enable(); } return $return; }