From e778b9e05c306c639306260fc60a98803e14d24f Mon Sep 17 00:00:00 2001 From: Herb v/d Dool Date: Wed, 15 Feb 2023 13:23:20 -0500 Subject: [PATCH] dev/core#4127 move Drupal stuff in getCiviSourceStorage to Drupal userSystem class --- CRM/Utils/System/Base.php | 49 +-------------------------------- CRM/Utils/System/DrupalBase.php | 38 +++++++++++++++++++++++++ CRM/Utils/System/Joomla.php | 2 +- CRM/Utils/System/Soap.php | 16 +++++++++++ CRM/Utils/System/Standalone.php | 16 +++++++++++ CRM/Utils/System/UnitTests.php | 16 +++++++++++ CRM/Utils/System/WordPress.php | 2 +- 7 files changed, 89 insertions(+), 50 deletions(-) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 0b88f721b2..e06d2834ca 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -649,58 +649,11 @@ abstract class CRM_Utils_System_Base { /** * Determine the location of the CiviCRM source tree. * - * FIXME: - * 1. This was pulled out from a bigger function. It should be split - * into even smaller pieces and marked abstract. - * 2. This would be easier to compute by a calling a CMS API, but - * for whatever reason we take the hard way. - * * @return array * - url: string. ex: "http://example.com/sites/all/modules/civicrm" * - path: string. ex: "/var/www/sites/all/modules/civicrm" */ - public function getCiviSourceStorage() { - global $civicrm_root; - $config = CRM_Core_Config::singleton(); - - // Don't use $config->userFrameworkBaseURL; it has garbage on it. - // More generally, w shouldn't be using $config here. - if (!defined('CIVICRM_UF_BASEURL')) { - throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); - } - $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/'); - if (CRM_Utils_System::isSSL()) { - $baseURL = str_replace('http://', 'https://', $baseURL); - } - - // @todo this function is only called / code is only reached when is_drupal is true - move this to the drupal classes - // and don't implement here. - if ($this->is_drupal) { - // Drupal setting - // check and see if we are installed in sites/all (for D5 and above) - // we dont use checkURL since drupal generates an error page and throws - // the system for a loop on lobo's macosx box - // or in modules - $cmsPath = $config->userSystem->cmsRootPath(); - $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '', - str_replace('\\', '/', $civicrm_root) - ); - - $siteName = $config->userSystem->parseDrupalSiteNameFromRoot($civicrm_root); - if ($siteName) { - $civicrmDirName = trim(basename($civicrm_root)); - $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/"; - } - } - else { - $userFrameworkResourceURL = ''; - } - - return [ - 'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL, '/'), - 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), - ]; - } + abstract public function getCiviSourceStorage():array; /** * Perform any post login activities required by the CMS. diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index e65c03d200..dd74c1cd80 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -321,6 +321,44 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } } + /** + * @inheritdoc + */ + public function getCiviSourceStorage():array { + global $civicrm_root; + $config = CRM_Core_Config::singleton(); + + // Don't use $config->userFrameworkBaseURL; it has garbage on it. + // More generally, w shouldn't be using $config here. + if (!defined('CIVICRM_UF_BASEURL')) { + throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); + } + $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/'); + if (CRM_Utils_System::isSSL()) { + $baseURL = str_replace('http://', 'https://', $baseURL); + } + + // Check and see if we are installed in sites/all (for D5 and above). + // We dont use checkURL since drupal generates an error page and throws + // the system for a loop on lobo's macosx box + // or in modules. + $cmsPath = $config->userSystem->cmsRootPath(); + $userFrameworkResourceURL = $baseURL . str_replace("$cmsPath/", '', + str_replace('\\', '/', $civicrm_root) + ); + + $siteName = $config->userSystem->parseDrupalSiteNameFromRoot($civicrm_root); + if ($siteName) { + $civicrmDirName = trim(basename($civicrm_root)); + $userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/"; + } + + return [ + 'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL, '/'), + 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), + ]; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index f5b2bb007b..c01c771b15 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -968,7 +968,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { * - url: string. ex: "http://example.com/sites/all/modules/civicrm" * - path: string. ex: "/var/www/sites/all/modules/civicrm" */ - public function getCiviSourceStorage() { + public function getCiviSourceStorage():array { global $civicrm_root; if (!defined('CIVICRM_UF_BASEURL')) { throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); diff --git a/CRM/Utils/System/Soap.php b/CRM/Utils/System/Soap.php index 4c9c633507..28242abec1 100644 --- a/CRM/Utils/System/Soap.php +++ b/CRM/Utils/System/Soap.php @@ -122,4 +122,20 @@ class CRM_Utils_System_Soap extends CRM_Utils_System_Base { throw new \RuntimeException("Not implemented"); } + /** + * @inheritdoc + */ + public function getCiviSourceStorage():array { + global $civicrm_root; + + if (!defined('CIVICRM_UF_BASEURL')) { + throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); + } + + return [ + 'url' => CRM_Utils_File::addTrailingSlash('', '/'), + 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), + ]; + } + } diff --git a/CRM/Utils/System/Standalone.php b/CRM/Utils/System/Standalone.php index c973ac8381..e9b7355a28 100644 --- a/CRM/Utils/System/Standalone.php +++ b/CRM/Utils/System/Standalone.php @@ -301,6 +301,22 @@ class CRM_Utils_System_Standalone extends CRM_Utils_System_Base { return TRUE; } + /** + * @inheritdoc + */ + public function getCiviSourceStorage(): array { + global $civicrm_root; + + if (!defined('CIVICRM_UF_BASEURL')) { + throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); + } + + return [ + 'url' => CRM_Utils_File::addTrailingSlash('', '/'), + 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), + ]; + } + /** * Determine the location of the CMS root. * diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index 868367da48..089d4e0325 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -60,6 +60,22 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { return TRUE; } + /** + * @inheritdoc + */ + public function getCiviSourceStorage(): array { + global $civicrm_root; + + if (!defined('CIVICRM_UF_BASEURL')) { + throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); + } + + return [ + 'url' => CRM_Utils_File::addTrailingSlash('', '/'), + 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root), + ]; + } + /** * @inheritDoc */ diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index b2abc31194..784ea14c0f 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -200,7 +200,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { * - url: string. ex: "http://example.com/sites/all/modules/civicrm" * - path: string. ex: "/var/www/sites/all/modules/civicrm" */ - public function getCiviSourceStorage() { + public function getCiviSourceStorage():array { global $civicrm_root; // Don't use $config->userFrameworkBaseURL; it has garbage on it. -- 2.25.1