Commit a108bf0f authored by alexpott's avatar alexpott

Issue #2478119 by znerol, andypost: Replace references to Session Manager with...

Issue #2478119 by znerol, andypost: Replace references to Session Manager with references to Session
parent dc53be5b
......@@ -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);
}
......
......@@ -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();
......
......@@ -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
......
......@@ -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;
}
}
......@@ -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;
}
......
......@@ -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,
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment