Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19303 - Consolidate getCiviSourceStorage and getDefaultFileStorage functions #9458

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 18 additions & 75 deletions CRM/Utils/System/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,108 +552,51 @@ public function getDefaultSiteSettings($dir) {
/**
* Determine the default location for file storage.
*
* 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 Civi gets it from config data.
*
* @return array
* - url: string. ex: "http://example.com/sites/foo.com/files/civicrm"
* - path: string. ex: "/var/www/sites/foo.com/files/civicrm"
*/
public function getDefaultFileStorage() {
global $civicrm_root;
$config = CRM_Core_Config::singleton();
$baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);

$filesURL = NULL;
$filesPath = NULL;

if ($config->userFramework == 'Joomla') {
// gross hack
// we need to remove the administrator/ from the end
$tempURL = str_replace("/administrator/", "/", $baseURL);
$filesURL = $tempURL . "media/civicrm/";
}
elseif ($this->is_drupal) {
$siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
if ($siteName) {
$filesURL = $baseURL . "sites/$siteName/files/civicrm/";
}
else {
$filesURL = $baseURL . "sites/default/files/civicrm/";
}
}
elseif ($config->userFramework == 'UnitTests') {
$filesURL = $baseURL . "sites/default/files/civicrm/";
}
else {
throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
}

$cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsPath = $this->cmsRootPath();
$filesPath = CRM_Utils_File::baseFilePath();
$filesRelPath = CRM_Utils_File::relativize($filesPath, $cmsPath);
$filesURL = rtrim($cmsUrl, '/') . '/' . ltrim($filesRelPath, ' /');
return array(
'url' => $filesURL,
'path' => CRM_Utils_File::baseFilePath(),
'url' => CRM_Utils_File::addTrailingSlash($filesURL, '/'),
'path' => CRM_Utils_File::addTrailingSlash($filesPath),
);
}

/**
* 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.
// More generally, we 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);
}

if ($config->userFramework == 'Joomla') {
$userFrameworkResourceURL = $baseURL . "components/com_civicrm/civicrm/";
}
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->parseDrupalSiteName($civicrm_root);
if ($siteName) {
$civicrmDirName = trim(basename($civicrm_root));
$userFrameworkResourceURL = $baseURL . "sites/$siteName/modules/$civicrmDirName/";
}
}
else {
$userFrameworkResourceURL = NULL;
}
$cmsPath = $this->cmsRootPath();

// $config = CRM_Core_Config::singleton();
// overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsUrl = CIVICRM_UF_BASEURL;
if (CRM_Utils_System::isSSL()) {
$cmsUrl = str_replace('http://', 'https://', $cmsUrl);
}
$civiRelPath = CRM_Utils_File::relativize(realpath($civicrm_root), realpath($cmsPath));
$civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
return array(
'url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL),
'url' => CRM_Utils_File::addTrailingSlash($civiUrl, '/'),
'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
);
}
Expand Down
48 changes: 0 additions & 48 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,54 +72,6 @@ public function setTitle($title, $pageTitle = NULL) {
}
}

/**
* Moved from CRM_Utils_System_Base
*/
public function getDefaultFileStorage() {
$config = CRM_Core_Config::singleton();
$cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsPath = $this->cmsRootPath();
$filesPath = CRM_Utils_File::baseFilePath();
$filesRelPath = CRM_Utils_File::relativize($filesPath, $cmsPath);
$filesURL = rtrim($cmsUrl, '/') . '/' . ltrim($filesRelPath, ' /');
return array(
'url' => CRM_Utils_File::addTrailingSlash($filesURL, '/'),
'path' => CRM_Utils_File::addTrailingSlash($filesPath),
);
}

/**
* Determine the location of the CiviCRM source tree.
*
* @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;

// 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');
}

$cmsPath = $this->cmsRootPath();

// $config = CRM_Core_Config::singleton();
// overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsUrl = CIVICRM_UF_BASEURL;
if (CRM_Utils_System::isSSL()) {
$cmsUrl = str_replace('http://', 'https://', $cmsUrl);
}
$civiRelPath = CRM_Utils_File::relativize(realpath($civicrm_root), realpath($cmsPath));
$civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
return array(
'url' => CRM_Utils_File::addTrailingSlash($civiUrl, '/'),
'path' => CRM_Utils_File::addTrailingSlash($civicrm_root),
);
}

/**
* @inheritDoc
*/
Expand Down