Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/drupal#149 Override sessionStart function for Drupal8 using appro… #19044

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

seamuslee001
Copy link
Contributor

…priate session functions

Overview

This overrides the sessionStart function to fix Session already started errors when running cron.php and as per the Drupal Documentation

Before

deprecated methods from DrupalBase.php used for Drupal8/9

After

Correct Session functions used for Drupal8/9

ping @demeritcowboy @KarinG @mglaman @MikeyMJCO

@civibot
Copy link

civibot bot commented Nov 25, 2020

(Standard links)

@civibot civibot bot added the master label Nov 25, 2020
Copy link
Contributor

@mglaman mglaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick mobile review. I'm take a look later to see the original base method. Overall it looks good. You may not need to call migrate directly as Drupal has some weird handling already for lazy started sessions

*/
public function sessionStart() {
if (\Drupal::hasContainer()) {
$session = \Drupal::request()->getSession();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to grab from session service than the request session. I've seen some weirdness otherwise. Can't fully explain why, as kids usually the same reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, the parent class has this:


  /**
   * Start a new session.
   */
  public function sessionStart() {
    session_start();
  }

If you look at the session manager in Drupal, which is what $session->start() calls, you'll see it's safe for existing started sessions: https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/lib/Drupal/Core/Session/SessionManager.php#L106

This is regenerate, which migrate calls: https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/lib/Drupal/Core/Session/SessionManager.php#L207

I don't know if this code actually should call migrate over ->start() directly.

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 @mglaman once you are both happy with this PR please merge it @seamuslee001

…priate session functions

Use Drupal Session service and don't worry about calling migrate
@seamuslee001
Copy link
Contributor Author

@mglaman Matt does this look right to you now?

@mglaman
Copy link
Contributor

mglaman commented Nov 30, 2020

Looks good to me, @seamuslee001 !

@seamuslee001
Copy link
Contributor Author

Merging as per @mglaman comment and @eileenmcnaughton 's comment

@seamuslee001 seamuslee001 merged commit afee4fc into civicrm:master Nov 30, 2020
@seamuslee001 seamuslee001 deleted the dev_drupal_149 branch November 30, 2020 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants