Skip to content

Commit

Permalink
Merge pull request #9409 from seamuslee001/CRM-19303
Browse files Browse the repository at this point in the history
CRM-19303
  • Loading branch information
colemanw authored Nov 21, 2016
2 parents 26d1d80 + f08eb39 commit 7f57eaf
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Utils/System/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ public function getDefaultFileStorage() {
$filesURL = $baseURL . "sites/$siteName/files/civicrm/";
}
else {
$filesURL = $baseURL . "sites/default/files/civicrm/";
$filesURL = $config->userSystem->checkMultisite($civicrm_root, $baseURL);
}
}
elseif ($config->userFramework == 'UnitTests') {
Expand Down
88 changes: 88 additions & 0 deletions CRM/Utils/System/DrupalBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,92 @@ public function parseDrupalSiteName($civicrm_root) {
return $siteName;
}

/**
* @var $basepath String cached basepath to prevent having to parse it repeatedly.
*/
protected $basepath;

/**
* @var $filesUrl String holds resolved path.
*/
protected $filesUrl;

/**
* checkBasePath - Returns root directory with respect to $civicrm_root
*
* @param $root String
* @param $seek String
*/
public function checkBasePath($root, $seek = "/sites/") {
if (!isset($this->basepath)) {
$this->basepath = substr($root, 0, stripos($root, $seek) + 1);
}

return $this->basepath;
}

/**
* check if files exist in path. Just a simple helper function for viewing
* existence of sites.
*
* @param $basepath string
* @param $basepath string
*/
private function checkFilesExists($basepath, $folder) {
return file_exists("{$basepath}sites/$folder/files/civicrm/");
}

/**
* Returns the concatenated url for existing path.
*
* @param $baseUrl string
* @param $folder string
*/
private function getUrl($baseUrl, $folder) {
return "{$baseUrl}sites/$folder/files/civicrm/";
}

/**
* Returns the location of /sites/SITENAME/files/civicrm depending
* on system configuration.
*
* @fixed CRM-19303
* @param $root string
* @param $baseUrl string
* @param $default string
*/
public function checkMultisite($root, $baseUrl, $default = "default") {
if (isset($this->filesUrl)) {
return $this->filesUrl;
}

$basepath = $this->checkBasePath($root);
$correct = NULL;
if ($this->checkFilesExists($root, $default)) {
$correct = $default;
}
else {
//Check for any other directories if default doesn't exist.
$folders = scandir($basepath . 'sites/');
foreach ($folders as $folder) {
//Ignore hidden directories/files...
if (strpos($folder, '.') === 0 || $folder == 'all') {
continue;
}
//Check if it is a directory
if (!is_dir($basepath . 'sites/' . $folder)) {
continue;
}

//Check if files path exists...
if ($this->checkFilesExists($basepath, $folder)) {
$correct = $folder;
break;
}
}
}
$this->filesUrl = self::getUrl($baseUrl, $correct);
return $this->filesUrl;
}

}

0 comments on commit 7f57eaf

Please sign in to comment.