Problem/Motivation

Now that Symfony sessions are in place and available from $request->getSession(), core should be updated that it uses that instead of accessing $_SESSION directly. Benefits for doing that is a) code depending on the session will get easier to test b) Session::get()/Session::set() takes care of starting the session automatically. That way we can eliminate direct access to the session_manager in most places.

Proposed resolution

Fix any occurence of the $_SESSION superglobal. Except in the following cases:

No change (legacy code):

core/lib/Drupal/Core/Messenger/LegacyMessenger.php
core/modules/simpletest/src/TestBase.php

LegacyMessenger will be removed in #2928994: Remove \Drupal\Core\Messenger\LegacyMessenger

No change (SessionManager and compatibility tests for $_SESSION superglobal):

core/lib/Drupal/Core/Session/SessionManager.php
core/modules/system/tests/modules/session_test/src/Controller/SessionTestController.php
core/modules/system/tests/modules/session_test/src/EventSubscriber/SessionTestSubscriber.php
core/modules/system/tests/src/Functional/Session/SessionTest.php

Other issue: #3109970: Convert uses of $_SESSION in forms and batch

core/includes/batch.inc
core/includes/form.inc
core/lib/Drupal/Core/Form/FormBuilder.php

Other issue: #3109042: Convert uses of $_SESSION in update module and authorize subsystem

core/authorize.php
core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php
core/modules/system/system.module
core/modules/system/tests/src/Functional/System/SystemAuthorizeTest.php
core/modules/update/src/Form/UpdateReady.php
core/modules/update/update.authorize.inc
core/modules/update/update.manager.inc

Other issue: #3109600: Convert uses of $_SESSION in language module

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php

Other issue: #3109971: Use $this->request in ViewsExecutable::getExposedInput() consistently

core/modules/views/src/ViewExecutable.php

Remaining tasks

  • Scope
  • Patch
  • Review
  • Commit
  • User interface changes

    API changes

+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -122,9 +126,9 @@ public static function getLogLevelClassMap() {
-  public function overview() {
+  public function overview(Request $request) {

@@ -306,12 +310,16 @@ public function eventDetails($event_id) {
-  protected function buildFilterQuery() {
+  protected function buildFilterQuery(Request $request) {

+++ b/core/modules/migrate_drupal_ui/src/Controller/MigrateController.php
@@ -12,12 +13,14 @@ class MigrateController extends ControllerBase {
-  public function showLog() {
+  public function showLog(Request $request) {

+++ b/core/modules/user/src/Controller/UserController.php
@@ -223,7 +225,7 @@ public function getResetPassForm(Request $request, $uid) {
-  public function resetPassLogin($uid, $timestamp, $hash) {
+  public function resetPassLogin($uid, $timestamp, $hash, Request $request) {
CommentFileSizeAuthor
#102 interdiff_100-102.txt539 bytesraman.b
#102 2473875-102.patch37.94 KBraman.b
#100 interdiff.txt1.94 KBznerol
#100 2473875-100.patch37.71 KBznerol
#98 2473875-98.patch36.61 KBznerol
#94 2473875-94.patch36.35 KBandypost
#94 interdiff.txt1.17 KBandypost
#87 2473875-86.patch36.26 KBandypost
#85 interdiff-85.txt0 bytesznerol
#85 2473875-85.diff36.2 KBznerol
#82 2473875-82.diff34.21 KBznerol
#80 interdiff-80.txt1.5 KBznerol
#80 2473875-clean-80.diff41.1 KBznerol
#77 2473875-77.patch42.61 KBandypost
#77 interdiff.txt5.77 KBandypost
#75 2473875-clean-74.patch42.65 KBznerol
#72 2473875-clean-72.patch50.22 KBznerol
#69 interdiff-68.txt713 bytesznerol
#68 2473875-68.patch74.05 KBznerol
#68 2473875-68.patch74.05 KBznerol
#66 2473875-66.patch73.63 KBznerol
#66 interdiff-66.txt1.54 KBznerol
#63 2473875-63.patch72.73 KBznerol
#63 interdiff-63.txt2.46 KBznerol
#58 2473875-58.patch70.52 KBznerol
#58 interdiff-55-58.txt5.2 KBznerol
#56 interdiff-56.txt2.16 KBznerol
#56 2473875-56.patch67.49 KBznerol
#55 interdiff-55.txt1.13 KBznerol
#55 2473875-55.patch66.34 KBznerol
#52 2473875-52.patch65.94 KBznerol
#49 2473875-49.patch65.88 KBandypost
#49 interdiff.txt1.84 KBandypost
#46 2473875-46.patch65.88 KBandypost
#46 interdiff.txt1.04 KBandypost
#45 2473875-45.patch65.73 KBandypost
#45 interdiff.txt1.78 KBandypost
#44 2473875-44.patch66.5 KBandypost
#44 interdiff-38.txt9.89 KBandypost
#43 interdiff.txt3.07 KBamit.drupal
#43 2473875-43.patch68.81 KBamit.drupal
#42 interdiff.txt3.08 KBamit.drupal
#42 2473875-42.patch68.83 KBamit.drupal
#38 2473875-38.patch66.43 KBkim.pepper
#38 2473875-38-interdiff.txt1.06 KBkim.pepper
#36 2473875-36.patch66.71 KBkim.pepper
#36 2473875-36-interdiff.txt2.25 KBkim.pepper
#34 interdiff.txt1.3 KBznerol
#34 2473875-34.patch65.29 KBznerol
#32 2473875-33.patch65.41 KBznerol
#29 2473875-29.patch67.68 KBalexpott
#29 27-29-interdiff.txt727 bytesalexpott
#27 2473875-27.patch67.68 KBalexpott
#27 26-27-interdiff.txt11.89 KBalexpott
#26 2473875-26.patch58.22 KBalexpott
#26 25-26-interdiff.txt3.34 KBalexpott
#25 2473875-25.patch58.24 KBalexpott
#25 23-25-interdiff.txt1.53 KBalexpott
#23 2473875-23.patch56.71 KBalexpott
#23 20-23-interdiff.txt4.05 KBalexpott
#20 2473875-20.patch55.74 KBalexpott
#20 18-20-interdiff.txt4.14 KBalexpott
#18 2473875-18.patch55.59 KBalexpott
#18 16-18-interdiff.txt1.71 KBalexpott
#16 2473875-16.patch55.46 KBalexpott
#3 2473875-session-usage-3.patch16.15 KBandypost
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

znerol’s picture

Issue summary: View changes
Issue tags: +Novice
andypost’s picture

Status: Active » Needs review
FileSize
16.15 KB

Initial patch, converted: batch, authorize session vars

Suppose we need to split this one into sub-issues on per session key usage

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 3: 2473875-session-usage-3.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

all failures are caused by
Fatal error: Call to a member function has() on a non-object in /.../sites/default/files/checkout/core/lib/Drupal/Core/Form/FormBuilder.php on line 193

znerol’s picture

That's likely because there is no session object on the request in the simpletest parent site. Seems like it is necessary to fix base test classes before.

znerol’s picture

Status: Needs review » Postponed
Issue tags: -Novice
mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Status: Postponed » Active

No reason for this to be postponed

alexpott’s picture

Status: Active » Needs review
FileSize
55.46 KB

Did some work on this... there are still two files with runtime $_SESSION usages. And lots of comments.

Status: Needs review » Needs work

The last submitted patch, 16: 2473875-16.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
FileSize
1.71 KB
55.59 KB

Whoops.

Status: Needs review » Needs work

The last submitted patch, 18: 2473875-18.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
FileSize
4.14 KB
55.74 KB

Some fixes.

alexpott’s picture

Version: 8.5.x-dev » 8.6.x-dev

This is a task and therefore for 8.6.x

Status: Needs review » Needs work

The last submitted patch, 20: 2473875-20.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
FileSize
4.05 KB
56.71 KB

Some more fixes.

Status: Needs review » Needs work

The last submitted patch, 23: 2473875-23.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
58.24 KB

Here's the last fix. The only usages of $_SESSION left are in \Drupal\Core\Messenger\LegacyMessenger which is deprecated and I think we can't really touch. And \Drupal\Core\Session\SessionManager where I think we need to very carefully think about what we change. Imo I think we could do that in a follow-up as I think we'll need to add tests for legacy $_SESSION support.

alexpott’s picture

Some minor tidy-ups after reviewing the patch.

alexpott’s picture

Fixing all the comments - mostly $_SESSION becomes the user's session

andypost’s picture

As few places are refactored maybe use to normalize calls to hasSession() & operations on session data... otoh it looks more like follow-up

  1. +++ b/core/includes/database.inc
    @@ -1039,12 +1039,12 @@ function db_ignore_replica() {
    +  if (count($connection_info) > 1 && \Drupal::request()->hasSession()) {
    ...
    -    $_SESSION['ignore_replica_server'] = REQUEST_TIME + $duration;
    +    \Drupal::request()->getSession()->set('ignore_replica_server', REQUEST_TIME + $duration);
    
    +++ b/core/lib/Drupal/Core/EventSubscriber/ReplicaDatabaseIgnoreSubscriber.php
    @@ -34,12 +34,13 @@ public function checkReplicaServer(GetResponseEvent $event) {
    +    if ($request->hasSession() && $request->getSession()->has('ignore_replica_server')) {
    +      if ($request->getSession()->get('ignore_replica_server') >= REQUEST_TIME) {
    ...
    +        $request->getSession()->remove('ignore_replica_server');
    

    Affects #2286235: Deprecate db_ignore_replica() and convert it to service

  2. +++ b/core/modules/system/tests/modules/menu_test/src/Access/AccessCheck.php
    @@ -17,12 +35,9 @@ class AccessCheck implements AccessInterface {
    -    if (!isset($_SESSION['menu_test'])) {
    -      $result = AccessResult::allowed();
    ...
    -      $result = AccessResult::allowedIf($_SESSION['menu_test'] < 2);
    ...
    +    $result = AccessResult::allowedIf(
    +      $this->requestStack->getMasterRequest()->getSession()->get('menu_test', 0) < 2
    

    why master request, looks other checks & cache contexts use current request

alexpott’s picture

Re #28

  1. Sure whichever gets in first means the second one will need a re-roll. The changes in both issues are very similar so no harm done.
  2. This can't matter as we're not going to be calling this test access handler in a sub request but changed anyway as I have no reason why I went for getMasterRequest()

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

znerol’s picture

Status: Needs review » Needs work

The last submitted patch, 32: 2473875-33.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

Status: Needs work » Needs review
FileSize
65.29 KB
1.3 KB

Fix some bad merges.

Status: Needs review » Needs work

The last submitted patch, 34: 2473875-34.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
2.25 KB
66.71 KB

Fixes some test fails.

Status: Needs review » Needs work

The last submitted patch, 36: 2473875-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
1.06 KB
66.43 KB

Hmm. Seem to have uncovered an issue with BigPipe...

Status: Needs review » Needs work

The last submitted patch, 38: 2473875-38.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kim.pepper’s picture

Not sure what this means:

Fatal error: Uncaught session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /tmp)

andypost’s picture

It means that comment test creates session but something now trying to save it

amit.drupal’s picture

Status: Needs work » Needs review
FileSize
68.83 KB
3.08 KB

Update #38

amit.drupal’s picture

Fix issues and update patch.

andypost’s picture

Clean-up against #38
Comment test fails because of placeholder generation for comment form, guess big pipe fails for the same reason
Still not clear how to fix

@amit.drupal no reason to change legacy manager & session manager because they are backward compatibility

andypost’s picture

FileSize
1.78 KB
65.73 KB

Fix comment test - accessing not started session with has() or remove() caused this bug

andypost’s picture

FileSize
1.04 KB
65.88 KB

Proper fix

The last submitted patch, 44: 2473875-44.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mglaman’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs a reroll

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.84 KB
65.88 KB

context changed, reroll

meantime, probably batch needs own session bag, also few checks for session started and exists, still confusing

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

znerol’s picture

znerol’s picture

znerol’s picture

also few checks for session started and exists, still confusing

I agree, it is confusing. We have the following methods to check different aspects of the session / session cookie:

<?php
Request::hasSession()
?>

Tests whether a session object is on the request. This will return TRUE even for anonymous requests which do not have a session open unless when run from CLI, or when there is a problem with the container, a subrequest or some broken test. This value is populated in \Drupal\Core\StackMiddleware\Session::handle().

In general if you need this method, then most probably there is something wrong with the request (or you are running from CLI).

<?php
Request::hasPreviousSession()
?>

Checks whether the session cookie is on the request. TBH I do not know a use case for that one.

<?php
SessionConfiguration::hasSession()
?>

This is the same as above, but doesn't require the session subsystem. It is used, e.g., in Drupal\Core\PageCache\RequestPolicy\NoSessionOpen

Not sure what this means:

Fatal error: Uncaught session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /tmp)

It looks like some session data is remaining after the test. Also it looks like the default PHP session save handler is in place during the test. That simply saves the session as a file in the temporary directory. I haven't figured out yet whether or not this is good or bad (during tests). Let's figure that one out.

znerol’s picture

Issue tags: -Needs reroll
znerol’s picture

Remove call to hasSession() from batch.inc.

znerol’s picture

The case in CommentDefaultFormatterCacheTagsTest is quite funny. That one just fabricates a new Session(); out of thin air. As a consequence that session object is associated with the default Symfony storage (aka NativeSessionStorage) instead of the Drupal specific SessionManager one.

It might be possible to pass in a new MockArraySessionStorage() as the first parameter, but I guess we are better off by just sticking with the Drupal implementation. That means, adding the system module to the test and also installing the sessions table.

Note that it is legitimate that FormBuilder::buildForm() unconditionally checks/removes the batch_form_state session variable. It needs to retrieve/clear the value from the database in all cases (if there is one). It cannot know whether the value is there before actually checking for it...

Status: Needs review » Needs work

The last submitted patch, 56: 2473875-56.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

FileSize
5.2 KB
70.52 KB

It might be possible to pass in a new MockArraySessionStorage() as the first parameter, but I guess we are better off by just sticking with the Drupal implementation. That means, adding the system module to the test and also installing the sessions table.

Well, I guessed wrong. If we want to be able to transparently use the session in kernel tests without needing to set up the database etc. in every single test, then it is necessary to actually have a working implementation by default. This patch adds a SessionManagerMemory relying on MockArraySessionStorage. Interdiff is against #55.

znerol’s picture

Status: Needs work » Needs review
andypost’s picture

+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -535,6 +535,11 @@ public function register(ContainerBuilder $container) {
+      ->register('session_manager.memory', 'Drupal\Core\Session\SessionManagerMemory')

I'd better keep this class out of core if it's used only in tests

znerol’s picture

I'd better keep this class out of core if it's used only in tests

True. Depending on whether this gets complex or not, I also consider splitting the addition out of this issue.

Status: Needs review » Needs work

The last submitted patch, 58: 2473875-58.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

Status: Needs work » Needs review
FileSize
2.46 KB
72.73 KB

Actually add the session to the request in FormTestBase and KernelTestBase.

znerol’s picture

Depending on whether this gets complex or not, I also consider splitting the addition out of this issue.

We already have an issue for that: #2484991: Add the session to the request in KernelTestBase, BrowserTestBase, and drush

Status: Needs review » Needs work

The last submitted patch, 63: 2473875-63.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

Status: Needs work » Needs review
FileSize
1.54 KB
73.63 KB

Make session available in functional tests via FunctionalTestSetupTrait as well and also start it (this is in order to mimic the behavior of the session middleware).

Status: Needs review » Needs work

The last submitted patch, 66: 2473875-66.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

Status: Needs work » Needs review
FileSize
74.05 KB
74.05 KB

FunctionalTestSetupTrait::rebuildContainer() calls prepareRequestForGenerator(). That function used to be important before run-tests.sh was migrated to populate the request stack in #2869573: Remove usages of deprecated DrupalKernel::prepareLegacyRequest().

Since prepareRequestForGenerator() pushes a new request on the stack without also setting the session, code running after that will end up without a session on the request.

Maybe we can get away by just removing the invocation of the problematic method from rebuildContainer().

znerol’s picture

FileSize
713 bytes

The last submitted patch, 68: 2473875-68.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

znerol’s picture

Let's split up this task into the following smaller bits:

  • Convert everything which is straight forward and clean to implement in this issue. Clean means: invoking has(), get(), set(), remove() on the session retrieved from the request. No $request->hasSession() and isStarted(), etc.
  • Split out modification of test base classes / traits into #2484991: Add the session to the request in KernelTestBase, BrowserTestBase, and drush
  • Leave alone batch, form API, installer, authorize, etc. for the moment and track them in individual issues.
znerol’s picture

Convert all occurrences of $_SESSION access in non-problematic classes, individual tests and modules.

znerol’s picture

Status: Needs review » Needs work

The last submitted patch, 72: 2473875-clean-72.patch, failed testing. View results

znerol’s picture

Remove hunks in the following files:

core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php
core/modules/system/system.module
core/modules/system/tests/src/Functional/System/SystemAuthorizeTest.php
core/modules/update/src/Form/UpdateReady.php

Will transfer them to the other issue.

andypost’s picture

It looks great, just noted that views plugin could use request from a view's method...
Will check it deeper cos when pager was converted we hit few places with workarounds

andypost’s picture

Here's clean-up for calls and views, file one more follow-up #3109109: AccountForm should read pass-reset-token only from query string

andypost’s picture

  1. +++ b/core/modules/dblog/src/Controller/DbLogController.php
    @@ -122,9 +126,9 @@ public static function getLogLevelClassMap() {
    +  public function overview(Request $request) {
    
    @@ -306,12 +310,16 @@ public function eventDetails($event_id) {
    +  protected function buildFilterQuery(Request $request) {
    
    +++ b/core/modules/migrate_drupal_ui/src/Controller/MigrateController.php
    @@ -12,12 +13,14 @@ class MigrateController extends ControllerBase {
    +  public function showLog(Request $request) {
    
    +++ b/core/modules/user/src/Controller/UserController.php
    @@ -223,7 +225,7 @@ public function getResetPassForm(Request $request, $uid) {
    -  public function resetPassLogin($uid, $timestamp, $hash) {
    +  public function resetPassLogin($uid, $timestamp, $hash, Request $request) {
    

    The only changes with BC affected, but looks they are totally valid

  2. +++ b/core/tests/Drupal/KernelTests/Core/Database/ReplicaKillSwitchTest.php
    @@ -27,12 +26,14 @@ public function testSystemInitIgnoresSecondaries() {
    +    $request = \Drupal::request();
    +    $request->setSession(\Drupal::service('session'));
    ...
    -    $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
    +    $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
    

    this change is not clear - why URL removed in previous hunk

znerol’s picture

this change is not clear - why URL removed in previous hunk

Oh, this is a KernelTests. So maybe better move those changes over to #2484991: Add the session to the request in KernelTestBase, BrowserTestBase, and drush and fix them over there using the new in memory session.

znerol’s picture

Move hunk in ReplicaKillSwitchTest to the other issue.

znerol’s picture

index 1555f9c06b..e1cb4aa642 100644
--- a/core/modules/system/tests/modules/session_test/session_test.module
--- a/core/modules/system/tests/modules/session_test/session_test.module
+++ b/core/modules/system/tests/modules/session_test/session_test.module

index 84978c9474..0a4edbc53d 100644
--- a/core/modules/system/tests/modules/session_test/session_test.routing.yml
+++ b/core/modules/system/tests/modules/session_test/session_test.routing.yml

index 1094522eab..8e9585840c 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

Do not delete tests verifying backward compatibility with $_SESSION superglobal.

znerol’s picture

Removed hunks in session_test module and SessionTest.php browser test.

jibran’s picture

If the patch is ready then can we please update the issue summary?

znerol’s picture

Issue summary: View changes
znerol’s picture

Fix docs in service parameter definition.

andypost’s picture

martin107’s picture

Status: Needs review » Reviewed & tested by the community

1) I have visually scanned the patch. All the conversions are clean... I see dependency injection where appropriate.

2) The text of all converted comments looks ok to me.

3) I have looked at the testbot output no additional coding standard errors introduced.

4) I searched an could not find any more instances of $SESSION in the codebase.

5) I think the convention of dropping $SESSION variables is a really good idea.
Plus in a really hand-wavey way it is an essential first step if we want ReactPHP style persistent threads.. in the future - and what ever approach we take. [ dreaming of Drupal22 ]

I think this is ready

znerol’s picture

Thanks for the review @martin107.

4) I searched an could not find any more instances of $SESSION in the codebase.

Note that you need to look for $_SESSION (including the underscore). Even after this patch, there will still remain a couple of occurrences. The reasons for the exceptions and follow-ups are noted in the issue summary.

JeroenT’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record
+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -123,9 +127,9 @@ public static function getLogLevelClassMap() {
-  public function overview() {
+  public function overview(Request $request) {

@@ -314,12 +318,16 @@ public function eventDetails($event_id) {
-  protected function buildFilterQuery() {
-    if (empty($_SESSION['dblog_overview_filter'])) {
+  protected function buildFilterQuery(Request $request) {

+++ b/core/modules/migrate_drupal_ui/src/Controller/MigrateController.php
@@ -12,12 +13,14 @@ class MigrateController extends ControllerBase {
-  public function showLog() {
-    $_SESSION['dblog_overview_filter'] = [];
-    $_SESSION['dblog_overview_filter']['type'] = ['migrate_drupal_ui' => 'migrate_drupal_ui'];
+  public function showLog(Request $request) {
+    $request->getSession()->set('dblog_overview_filter', ['type' => ['migrate_drupal_ui' => 'migrate_drupal_ui']]);

+++ b/core/modules/user/src/Controller/UserController.php
@@ -219,7 +221,7 @@ public function getResetPassForm(Request $request, $uid) {
-  public function resetPassLogin($uid, $timestamp, $hash) {
+  public function resetPassLogin($uid, $timestamp, $hash, Request $request) {

We need a CR to cover this controller change. As controllers they don't have a BC promise so we can make these changes but it is important that we announce them.

Other than the missing CR this change looks great! Once the CR exists for adding the request to these controllers then we're good to go.

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Created draft change record: https://www.drupal.org/node/3115716

andypost’s picture

Version: 8.9.x-dev » 9.1.x-dev

It should be commited to 9.1 first

andypost’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.17 KB
36.35 KB

Re-roll for 9.1 and fix pass by reference

martin107’s picture

Issue tags: -Needs change record

CR looks good to me.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

znerol’s picture

Assigned: Unassigned » znerol
Status: Needs review » Needs work
Issue tags: +Needs reroll
znerol’s picture

Assigned: znerol » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
36.61 KB

Status: Needs review » Needs work

The last submitted patch, 98: 2473875-98.patch, failed testing. View results

znerol’s picture

Status: Needs work » Needs review
FileSize
37.71 KB
1.94 KB

Fix reroll fail in MigrateController.php and update UserAccountFormPasswordResetTest.php to set the session on the request.

Status: Needs review » Needs work

The last submitted patch, 100: 2473875-100.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
FileSize
37.94 KB
539 bytes

Addressing the remaining test failure

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joachim’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/system/src/Controller/DbUpdateController.php
@@ -396,6 +396,12 @@ protected function results(Request $request) {
+    // Retrieve and remove session information.
+    $session = $request->getSession();
+    $update_results = $session->remove('update_results');
+    $update_success = $session->remove('update_success');
+    $session->remove('update_ignore_warnings');
+

I find the use of remove() to get the values a bit weird, but that's a nitpick.

  • catch committed 492b7a1 on 9.3.x
    Issue #2473875 by znerol, alexpott, andypost, kim.pepper, amit.drupal,...
catch’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -WSCCI
+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -123,9 +127,9 @@ public static function getLogLevelClassMap() {
    * @see Drupal\dblog\Controller\DbLogController::eventDetails()
    */
-  public function overview() {
+  public function overview(Request $request) {
 

This is the closest thing in the patch to an API change. The only case this could cause an issue is if someone subclassed the controller, and then called parent::overview(), I can't see this being done (much less likely than with a plugin implementation), and even if it is, it's well within @internal policy to change in a minor release. We have an change record already, so that's fine.

I find the use of remove() to get the values a bit weird, but that's a nitpick.

Same here, but also ::get() followed by ::remove() seems redundant, so best left as-is I think.

Committed 492b7a1 and pushed to 9.3.x. Thanks!

andypost’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cilefen’s picture

Sorry for the noise but we have a good report about this issue causing a regression #3260652: Feature "Remember the last selection" for views exposed filters doesn't work anymore