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 - Refactor getDefaultFileStorage() function #9445

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
41 changes: 3 additions & 38 deletions CRM/Utils/System/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,50 +552,15 @@ 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"
* @throws \CRM_Core_Exception
*/
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)");
}

return array(
'url' => $filesURL,
'path' => CRM_Utils_File::baseFilePath(),
);
throw new CRM_Core_Exception("Failed to locate default file storage ($config->userFramework)");
return array();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions CRM/Utils/System/DrupalBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,18 @@ public function parseDrupalSiteName($civicrm_root) {
return $siteName;
}

/**
* @inheritDoc
*/
public function getDefaultFileStorage() {
$path = CRM_Utils_File::baseFilePath();
$drupalRoot = $this->cmsRootPath();
$url = CRM_Utils_System::url(trim(str_replace($drupalRoot, '', $path), '\\/'), NULL, TRUE);

return array(
'url' => CRM_Utils_File::addTrailingSlash($url, '/'),
'path' => $path,
);
}

}
18 changes: 18 additions & 0 deletions CRM/Utils/System/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,22 @@ public function synchronizeUsers() {
);
}

/**
* @inheritDoc
*/
public function getDefaultFileStorage() {
$config = CRM_Core_Config::singleton();
$baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);

// gross hack
// we need to remove the administrator/ from the end
$tempURL = str_replace("/administrator/", "/", $baseURL);
$filesURL = $tempURL . "media/civicrm/";

return array(
'url' => $filesURL,
'path' => CRM_Utils_File::baseFilePath(),
);
}

}
12 changes: 12 additions & 0 deletions CRM/Utils/System/UnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,16 @@ public function getLoginURL($destination = '') {
throw new Exception("Method not implemented: getLoginURL");
}

/**
* @inheritDoc
*/
public function getDefaultFileStorage() {
$config = CRM_Core_Config::singleton();

return array(
'url' => $config->userFrameworkBaseURL . "sites/default/files/civicrm/",
'path' => CRM_Utils_File::baseFilePath(),
);
}

}
2 changes: 1 addition & 1 deletion CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setTitle($title, $pageTitle = NULL) {
}

/**
* Moved from CRM_Utils_System_Base
* @inheritDoc
*/
public function getDefaultFileStorage() {
$config = CRM_Core_Config::singleton();
Expand Down