Skip to content

Commit 8272a44

Browse files
Milton Zuritaseamuslee001
Milton Zurita
authored andcommitted
Fixed: CRM-19303
Instead of assuming the default folder exists, it checks, if not it will search nearby directories for the files.
1 parent 9affa2b commit 8272a44

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

CRM/Utils/System/Base.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ public function getDefaultFileStorage() {
582582
$filesURL = $baseURL . "sites/$siteName/files/civicrm/";
583583
}
584584
else {
585-
$filesURL = $baseURL . "sites/default/files/civicrm/";
585+
$filesURL = $config->userSystem->checkMultisite($civicrm_root, $baseURL);
586586
}
587587
}
588588
elseif ($config->userFramework == 'UnitTests') {

CRM/Utils/System/DrupalBase.php

+79
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,83 @@ public function parseDrupalSiteName($civicrm_root) {
568568
return $siteName;
569569
}
570570

571+
/**
572+
* @var $basepath String cached basepath to prevent having to parse it repeatedly.
573+
**/
574+
protected $basepath;
575+
576+
/**
577+
* @var $filesUrl String holds resolved path.
578+
**/
579+
protected $filesUrl;
580+
581+
/**
582+
* checkBasePath - Returns root directory with respect to $civicrm_root
583+
*
584+
* @param $root String
585+
* @param $seek String
586+
**/
587+
public function checkBasePath($root, $seek = "/sites/")
588+
{
589+
if(!isset($this->basepath)) {
590+
$this->basepath = substr($root, 0, stripos($root, $seek)+1);
591+
}
592+
593+
return $this->basepath;
594+
}
595+
596+
/**
597+
* check if files exist in path. Just a simple helper function for viewing
598+
* existence of sites.
599+
*
600+
* @param $basepath string
601+
* @param $basepath string
602+
**/
603+
private function checkFilesExists($basepath, $folder) {
604+
return file_exists("{$basepath}sites/$folder/files/civicrm/");
605+
}
606+
607+
/**
608+
* Returns the concatenated url for existing path.
609+
*
610+
* @param $baseUrl string
611+
* @param $folder string
612+
**/
613+
private function getUrl($baseUrl, $folder) {
614+
return "{$baseUrl}sites/$folder/files/civicrm/";
615+
}
616+
617+
/**
618+
* Returns the location of /sites/SITENAME/files/civicrm depending
619+
* on system configuration.
620+
*
621+
* @fixed CRM-19303
622+
* @param $root string
623+
* @param $baseUrl string
624+
* @param $default string
625+
**/
626+
public function checkMultisite($root, $baseUrl, $default = "default") {
627+
if(isset($this->filesUrl)) return $this->filesUrl;
628+
629+
$basepath = $this->checkBasePath($root);
630+
$correct = null;
631+
if($this->checkFilesExists($root, $default)) {
632+
$correct = $default;
633+
}
634+
else {
635+
//Check for any other directories if default doesn't exist.
636+
$folders = scandir($basepath.'sites/');
637+
foreach($folders as $folder) {
638+
//Ignore hidden directories/files...
639+
if(strpos($folder,'.') === 0 || $folder == 'all') continue;
640+
//Check if it is a directory
641+
if(!is_dir($basepath.'sites/'.$folder)) continue;
642+
643+
//Check if files path exists...
644+
if($this->checkFilesExists($basepath, $folder)) {
645+
$correct = $folder;
646+
break;
647+
}
648+
}
649+
}
571650
}

0 commit comments

Comments
 (0)