diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 5e38a973cca8fbe56c94a1493484baf02c849a88..6933dc8690c9e2777f7f645d106c3fc5631d5f0e 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -220,7 +220,7 @@ function _drupal_log_error($error, $fatal = FALSE) { // Generate a backtrace containing only scalar argument values. $message .= '<pre class="backtrace">' . Error::formatBacktrace($backtrace) . '</pre>'; } - if (\Drupal::hasService('session_manager')) { + if (\Drupal::hasService('session')) { // Message display is dependent on sessions being available. drupal_set_message(SafeMarkup::set($message), $class, TRUE); } diff --git a/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php b/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php index 083dd6cff4fc8e536f7a3ae999c23f6465f2b6f6..c0b111566eb199a406ac8f3e79bb677d0c7ad4bb 100644 --- a/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php +++ b/core/lib/Drupal/Core/Access/CsrfTokenGenerator.php @@ -63,7 +63,7 @@ public function __construct(PrivateKey $private_key, MetadataBag $session_metada * 'drupal_private_key' configuration variable. * * @see \Drupal\Core\Site\Settings::getHashSalt() - * @see \Drupal\Core\Session\SessionManager::start() + * @see \Symfony\Component\HttpFoundation\Session\SessionInterface::start() */ public function get($value = '') { $seed = $this->sessionMetadata->getCsrfTokenSeed(); diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 8202cd6077c4e28bd73925cb0ab10310efdf9dbf..d21a8fa3f618553574d9f689f6dbc6c30e4aee9e 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -746,21 +746,21 @@ protected function getKernelParameters() { */ protected function initializeContainer($rebuild = FALSE) { $this->containerNeedsDumping = FALSE; - $session_manager_started = FALSE; + $session_started = FALSE; if (isset($this->container)) { // Save the id of the currently logged in user. if ($this->container->initialized('current_user')) { $current_user_id = $this->container->get('current_user')->id(); } - // If there is a session manager, close and save the session. - if ($this->container->initialized('session_manager')) { - $session_manager = $this->container->get('session_manager'); - if ($session_manager->isStarted()) { - $session_manager_started = TRUE; - $session_manager->save(); + // If there is a session, close and save it. + if ($this->container->initialized('session')) { + $session = $this->container->get('session'); + if ($session->isStarted()) { + $session_started = TRUE; + $session->save(); } - unset($session_manager); + unset($session); } } @@ -786,8 +786,8 @@ protected function initializeContainer($rebuild = FALSE) { $this->attachSynthetic($container); $this->container = $container; - if ($session_manager_started) { - $this->container->get('session_manager')->start(); + if ($session_started) { + $this->container->get('session')->start(); } // The request stack is preserved across container rebuilds. Reinject the diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index 75a548442dbe2f50be73eab1b9c93ab212818422..06ae369b9da25d07bd57caef0861cd335b82faac 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -1326,12 +1326,14 @@ protected function refreshVariables() { * Return TRUE if the user is logged in, FALSE otherwise. */ protected function drupalUserIsLoggedIn(UserInterface $account) { - if (!isset($account->sessionId)) { - return FALSE; + $logged_in = FALSE; + + if (isset($account->sessionId)) { + $session_handler = $this->container->get('session_handler.storage'); + $logged_in = (bool) $session_handler->read($account->sessionId); } - // The session ID is hashed before being stored in the database. - // @see \Drupal\Core\Session\SessionHandler::read() - return (bool) db_query("SELECT sid FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid AND u.default_langcode = 1 WHERE s.sid = :sid", array(':sid' => Crypt::hashBase64($account->sessionId)))->fetchField(); + + return $logged_in; } } diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index a5dd73ece6e19c5c2a258d1babc7dd93ff2bf3f3..2cf859af2b5398841c2c1cc4ddd6a8ea004e886f 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -573,19 +573,13 @@ protected function drupalLogin(AccountInterface $account) { * The user account object to check. */ protected function drupalUserIsLoggedIn($account) { - if (!isset($account->session_id)) { - return FALSE; - } - $session_id = $account->session_id; - $request_stack = $this->container->get('request_stack'); - $request = $request_stack->getCurrentRequest(); - $cookies = $request->cookies->all(); - foreach ($this->cookies as $name => $value) { - $cookies[$name] = $value['value']; - } - $request_stack->push($request->duplicate(NULL, NULL, NULL, $cookies)); - $logged_in = (bool) $this->container->get('session_manager')->getSaveHandler()->read($session_id); - $request_stack->pop(); + $logged_in = FALSE; + + if (isset($account->session_id)) { + $session_handler = $this->container->get('session_handler.storage'); + $logged_in = (bool) $session_handler->read($account->session_id); + } + return $logged_in; } diff --git a/core/modules/system/core.api.php b/core/modules/system/core.api.php index a156905f4d7a25998548ef6a6142425f1b50720f..145d7664d089d15e681610276b346154a8a7855b 100644 --- a/core/modules/system/core.api.php +++ b/core/modules/system/core.api.php @@ -972,10 +972,8 @@ * - Session: Information about individual users' interactions with the site, * such as whether they are logged in. This is really "state" information, but * it is not stored the same way so it's a separate type here. Session - * information is managed via the session_manager service in Drupal, which - * implements \Drupal\Core\Session\SessionManagerInterface. See the - * @link container Services topic @endlink for more information about - * services. + * information is available from the Request object. The session implements + * \Symfony\Component\HttpFoundation\Session\SessionInterface. * - State: Information of a temporary nature, generally machine-generated and * not human-edited, about the current state of your site. Examples: the time * when Cron was last run, whether node access permissions need rebuilding, diff --git a/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php b/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php index b17d9a0684cc25e090b898710ef788d2ef5505f3..510b36f9994c94f42f95bd492be80c8982902c6f 100644 --- a/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php +++ b/core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php @@ -33,11 +33,14 @@ public function get() { /** * Prints the stored session value to the screen. * + * @param \Symfony\Component\HttpFoundation\Request $request + * The incoming request. + * * @return string * A notification message. */ - public function getFromSessionObject() { - $value = \Drupal::request()->getSession()->get("session_test_key"); + public function getFromSessionObject(Request $request) { + $value = $request->getSession()->get("session_test_key"); return empty($value) ? [] : ['#markup' => $this->t('The current value of the stored session variable is: %val', array('%val' => $value))]; @@ -46,15 +49,18 @@ public function getFromSessionObject() { /** * Print the current session ID. * + * @param \Symfony\Component\HttpFoundation\Request $request + * The incoming request. + * * @return string * A notification message with session ID. */ - public function getId() { + public function getId(Request $request) { // Set a value in $_SESSION, so that SessionManager::save() will start // a session. $_SESSION['test'] = 'test'; - \Drupal::service('session_manager')->save(); + $request->getSession()->save(); return ['#markup' => 'session_id:' . session_id() . "\n"]; } @@ -142,19 +148,22 @@ public function isLoggedIn() { /** * Returns the trace recorded by test proxy session handlers as JSON. * + * @param \Symfony\Component\HttpFoundation\Request $request + * The incoming request. + * * @return \Symfony\Component\HttpFoundation\JsonResponse * The response. */ - public function traceHandler() { + public function traceHandler(Request $request) { // Start a session if necessary, set a value and then save and close it. - \Drupal::service('session_manager')->start(); + $request->getSession()->start(); if (empty($_SESSION['trace-handler'])) { $_SESSION['trace-handler'] = 1; } else { $_SESSION['trace-handler']++; } - \Drupal::service('session_manager')->save(); + $request->getSession()->save(); // Collect traces and return them in JSON format. $trace = \Drupal::service('session_test.session_handler_proxy_trace')->getArrayCopy();