From d074981c3c1e5ac81362efc308620bf6b50a4838 Mon Sep 17 00:00:00 2001 From: "Robert J. Lang" Date: Sat, 28 May 2022 16:10:26 -0700 Subject: [PATCH] Issue 8: move session start into CMS-specific classes. --- CRM/Utils/System.php | 12 ------------ CRM/Utils/System/Drupal.php | 8 ++++++++ CRM/Utils/System/Drupal8.php | 8 ++++++++ CRM/Utils/System/Joomla.php | 8 ++++++++ CRM/Utils/System/Soap.php | 8 ++++++++ CRM/Utils/System/WordPress.php | 8 ++++++++ 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 4514547628..72946f43ee 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -754,18 +754,6 @@ class CRM_Utils_System { public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { $config = CRM_Core_Config::singleton(); - /* Before we do any loading, let's start the session and write to it. - * We typically call authenticate only when we need to bootstrap the CMS - * directly via Civi and hence bypass the normal CMS auth and bootstrap - * process typically done in CLI and cron scripts. See: CRM-12648 - * - * Q: Can we move this to the userSystem class so that it can be tuned - * per-CMS? For example, when dealing with UnitTests UF, does it need to - * do this session write since the original issue was for Drupal. - */ - $session = CRM_Core_Session::singleton(); - $session->set('civicrmInitSession', TRUE); - return $config->userSystem->authenticate($name, $password, $loadCMSBootstrap, $realPath); } diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 34742a094f..eebbcf7fa2 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -315,6 +315,14 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { require_once 'DB.php'; + /* Before we do any loading, let's start the session and write to it. + * We typically call authenticate only when we need to bootstrap the CMS + * directly via Civi and hence bypass the normal CMS auth and bootstrap + * process typically done in CLI and cron scripts. See: CRM-12648 + */ + $session = CRM_Core_Session::singleton(); + $session->set('civicrmInitSession', TRUE); + $config = CRM_Core_Config::singleton(); $ufDSN = CRM_Utils_SQL::autoSwitchDSN($config->userFrameworkDSN); diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index df27c0d9e4..605c7ab04c 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -316,6 +316,14 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { + /* Before we do any loading, let's start the session and write to it. + * We typically call authenticate only when we need to bootstrap the CMS + * directly via Civi and hence bypass the normal CMS auth and bootstrap + * process typically done in CLI and cron scripts. See: CRM-12648 + */ + $session = CRM_Core_Session::singleton(); + $session->set('civicrmInitSession', TRUE); + $system = new CRM_Utils_System_Drupal8(); $system->loadBootStrap([], FALSE); diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 2d163d17ac..91dd8b6e23 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -325,6 +325,14 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { require_once 'DB.php'; + /* Before we do any loading, let's start the session and write to it. + * We typically call authenticate only when we need to bootstrap the CMS + * directly via Civi and hence bypass the normal CMS auth and bootstrap + * process typically done in CLI and cron scripts. See: CRM-12648 + */ + $session = CRM_Core_Session::singleton(); + $session->set('civicrmInitSession', TRUE); + $config = CRM_Core_Config::singleton(); $user = NULL; diff --git a/CRM/Utils/System/Soap.php b/CRM/Utils/System/Soap.php index 90a04c6686..4c9c633507 100644 --- a/CRM/Utils/System/Soap.php +++ b/CRM/Utils/System/Soap.php @@ -75,6 +75,14 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { * @inheritDoc */ public function authenticate($name, $pass) { + /* Before we do any loading, let's start the session and write to it. + * We typically call authenticate only when we need to bootstrap the CMS + * directly via Civi and hence bypass the normal CMS auth and bootstrap + * process typically done in CLI and cron scripts. See: CRM-12648 + */ + $session = CRM_Core_Session::singleton(); + $session->set('civicrmInitSession', TRUE); + if (isset(self::$ufClass)) { $className = self::$ufClass; $result =& $className::authenticate($name, $pass); diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 66942c8ced..d5e4e5dabf 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -542,6 +542,14 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { + /* Before we do any loading, let's start the session and write to it. + * We typically call authenticate only when we need to bootstrap the CMS + * directly via Civi and hence bypass the normal CMS auth and bootstrap + * process typically done in CLI and cron scripts. See: CRM-12648 + */ + $session = CRM_Core_Session::singleton(); + $session->set('civicrmInitSession', TRUE); + $config = CRM_Core_Config::singleton(); if ($loadCMSBootstrap) { -- 2.25.1