From 4d4d87f13d0f68fed9862a1fb2179155218fc435 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Fri, 12 Nov 2021 16:53:57 -0500 Subject: [PATCH] fix session change in drupal 9.2 --- CRM/Core/Key.php | 2 +- CRM/Utils/System/Base.php | 9 +++++++++ CRM/Utils/System/Drupal8.php | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Key.php b/CRM/Core/Key.php index 3e7826f2c7..58b0a3912c 100644 --- a/CRM/Core/Key.php +++ b/CRM/Core/Key.php @@ -67,7 +67,7 @@ class CRM_Core_Key { $session = CRM_Core_Session::singleton(); self::$_sessionID = $session->get('qfSessionID'); if (!self::$_sessionID) { - self::$_sessionID = session_id(); + self::$_sessionID = CRM_Core_Config::singleton()->userSystem->getSessionId(); $session->set('qfSessionID', self::$_sessionID); } } diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index a2bf46e7a1..f163aea7dd 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -1019,6 +1019,15 @@ abstract class CRM_Utils_System_Base { session_start(); } + /** + * This exists because of https://www.drupal.org/node/3006306 where + * they changed so that they don't start sessions for anonymous, but we + * want that. + */ + public function getSessionId() { + return session_id(); + } + /** * Get role names * diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 06db470714..3cf29f4498 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -848,6 +848,20 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { } } + /** + * @inheritdoc + */ + public function getSessionId() { + if (\Drupal::hasContainer()) { + $session = \Drupal::service('session'); + if (!$session->has('civicrm.tempstore.sessionid')) { + $session->set('civicrm.tempstore.sessionid', \Drupal\Component\Utility\Crypt::randomBytesBase64()); + } + return $session->get('civicrm.tempstore.sessionid'); + } + return ''; + } + /** * Load the user object. * -- 2.25.1