Skip to content
Snippets Groups Projects
Commit e778b9e0 authored by herbdool's avatar herbdool
Browse files

#4127 move Drupal stuff in getCiviSourceStorage to Drupal userSystem class

parent fa243019
Branches
Tags
No related merge requests found
......@@ -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.
......
......@@ -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
*/
......
......@@ -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');
......
......@@ -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),
];
}
}
......@@ -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.
*
......
......@@ -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
*/
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment