Commit 3403e54b authored by totten's avatar totten

CRM-19303 - Drupal - Restore getCiviSourceStorage()

This partially reverts changes made under CRM-19303:
 * The changes to `getDefaultFileStorage()` are preserved
 * The changes to `getCiviSourceStorage()` are reverted
 * To avoid conflicts, `parseDrupalSiteName()` has been split into the older `parseDrupalSiteNameFromRoot()` and the newer `parseDrupalSiteNameFromRequest()`.
   (IMHO, `parseDrupalSiteNameFromRequest()` is more correct, but `parseDrupalSiteNameFromRoot()` is more compatible with existing deployments).

As discussed in [PR #10513](https://github.com/civicrm/civicrm-core/pull/10513#issuecomment-310506829),
we should stop trying so hard to autodetect these things.  We'll treat the
auto-detection stuff as legacy, and should shift toward a simpler/flatter arrangement
which encourages paths/URLs to be stored in `civicrm.settings.php`.
parent 84906ea9
......@@ -639,6 +639,23 @@ abstract class CRM_Utils_System_Base {
elseif ($config->userFramework == 'WordPress') {
$userFrameworkResourceURL = CIVICRM_PLUGIN_URL . "civicrm/";
}
elseif ($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 = NULL;
}
......
......@@ -58,30 +58,6 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
$this->supports_form_extensions = TRUE;
}
/**
* @inheritDoc
*/
public function getCiviSourceStorage() {
global $civicrm_root;
// Don't use $config->userFrameworkBaseURL; it has garbage on it.
// More generally, we shouldn't be using $config here.
if (!defined('CIVICRM_UF_BASEURL')) {
throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
}
$cmsUrl = CIVICRM_UF_BASEURL;
if (CRM_Utils_System::isSSL()) {
$cmsUrl = str_replace('http://', 'https://', $cmsUrl);
}
$civiRelPath = CRM_Utils_File::relativize(realpath($civicrm_root), realpath($this->cmsRootPath()));
$civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
return array(
'url' => CRM_Utils_File::addTrailingSlash($civiUrl, '/'),
'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
);
}
/**
* @inheritdoc
*/
......@@ -89,7 +65,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
$config = CRM_Core_Config::singleton();
$baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$siteName = $this->parseDrupalSiteName('/files/civicrm');
$siteName = $this->parseDrupalSiteNameFromRequest('/files/civicrm');
if ($siteName) {
$filesURL = $baseURL . "sites/$siteName/files/civicrm/";
}
......@@ -590,6 +566,37 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
return user_load($userID);
}
/**
* Parse the name of the drupal site.
*
* @param string $civicrm_root
*
* @return null|string
* @deprecated
*/
public function parseDrupalSiteNameFromRoot($civicrm_root) {
$siteName = NULL;
if (strpos($civicrm_root,
DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules'
) === FALSE
) {
$startPos = strpos($civicrm_root,
DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR
);
$endPos = strpos($civicrm_root,
DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR
);
if ($startPos && $endPos) {
// if component is in sites/SITENAME/modules
$siteName = substr($civicrm_root,
$startPos + 7,
$endPos - $startPos - 7
);
}
}
return $siteName;
}
/**
* Determine if Drupal multi-site applies to the current request -- and,
* specifically, determine the name of the multisite folder.
......@@ -600,7 +607,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base {
* string, e.g. `bar.example.com` if using multisite.
* NULL if using the default site.
*/
private function parseDrupalSiteName($flagFile = '') {
private function parseDrupalSiteNameFromRequest($flagFile = '') {
$phpSelf = array_key_exists('PHP_SELF', $_SERVER) ? $_SERVER['PHP_SELF'] : '';
$httpHost = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : '';
if (empty($httpHost)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment