From 8272a44f66230151fdf5752f94d8d48b6ae3138c Mon Sep 17 00:00:00 2001 From: Milton Zurita Date: Fri, 16 Sep 2016 03:38:50 -0500 Subject: [PATCH 1/5] Fixed: CRM-19303 Instead of assuming the default folder exists, it checks, if not it will search nearby directories for the files. --- CRM/Utils/System/Base.php | 2 +- CRM/Utils/System/DrupalBase.php | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index b3f8dcb4435b..b053e547fda4 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -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') { diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 3129073181ed..fa10d9564a64 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -568,4 +568,83 @@ 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; + } + } + } } From 0fb2ca0d47dc006e69ae37b89fdd93563b1ba9c0 Mon Sep 17 00:00:00 2001 From: Milton Zurita Date: Mon, 26 Sep 2016 22:29:39 -0500 Subject: [PATCH 2/5] CRM-19303 - Style Fixes --- CRM/Utils/System/DrupalBase.php | 80 +++++++++++++++++---------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index fa10d9564a64..1f50aa3d5bb7 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -569,82 +569,84 @@ public function parseDrupalSiteName($civicrm_root) { } /** - * @var $basepath String cached basepath to prevent having to parse it repeatedly. - **/ + * @var $basepath String cached basepath to prevent having to parse it repeatedly. + */ protected $basepath; /** - * @var $filesUrl String holds resolved path. - **/ + * @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); + * 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 - **/ + * 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 - **/ + * 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 - **/ + * 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; + if(isset($this->filesUrl)) + return $this->filesUrl; $basepath = $this->checkBasePath($root); $correct = null; - if($this->checkFilesExists($root, $default)) { + if ($this->checkFilesExists($root, $default)) { $correct = $default; } else { //Check for any other directories if default doesn't exist. - $folders = scandir($basepath.'sites/'); + $folders = scandir($basepath . 'sites/'); foreach($folders as $folder) { //Ignore hidden directories/files... - if(strpos($folder,'.') === 0 || $folder == 'all') continue; + if (strpos($folder, '.') === 0 || $folder == 'all') + continue; //Check if it is a directory - if(!is_dir($basepath.'sites/'.$folder)) continue; + if (!is_dir($basepath . 'sites/' . $folder)) + continue; //Check if files path exists... - if($this->checkFilesExists($basepath, $folder)) { + if ($this->checkFilesExists($basepath, $folder)) { $correct = $folder; break; } } + } } -} From 43d849873e9e06b7b9e73f67270cea496eace2a7 Mon Sep 17 00:00:00 2001 From: Milton Zurita Date: Mon, 26 Sep 2016 22:36:29 -0500 Subject: [PATCH 3/5] CRM-19303: Final Style Changes. Other warnings not in my modifications. Line# 40-51 --- CRM/Utils/System/DrupalBase.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 1f50aa3d5bb7..62ddbbbdf7f3 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -623,18 +623,18 @@ private function getUrl($baseUrl, $folder) { * @param $default string */ public function checkMultisite($root, $baseUrl, $default = "default") { - if(isset($this->filesUrl)) + if (isset($this->filesUrl)) return $this->filesUrl; $basepath = $this->checkBasePath($root); - $correct = null; + $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) { + foreach ($folders as $folder) { //Ignore hidden directories/files... if (strpos($folder, '.') === 0 || $folder == 'all') continue; @@ -650,3 +650,4 @@ public function checkMultisite($root, $baseUrl, $default = "default") { } } } +} From 75c21cd07c23285470bc9761fb9411c265430eb0 Mon Sep 17 00:00:00 2001 From: Milton Zurita Date: Mon, 26 Sep 2016 22:39:06 -0500 Subject: [PATCH 4/5] CRM-19303: Small changes to remove inline control structures. --- CRM/Utils/System/DrupalBase.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 62ddbbbdf7f3..19806af4c8e5 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -623,8 +623,9 @@ private function getUrl($baseUrl, $folder) { * @param $default string */ public function checkMultisite($root, $baseUrl, $default = "default") { - if (isset($this->filesUrl)) + if (isset($this->filesUrl)) { return $this->filesUrl; + } $basepath = $this->checkBasePath($root); $correct = NULL; @@ -636,11 +637,13 @@ public function checkMultisite($root, $baseUrl, $default = "default") { $folders = scandir($basepath . 'sites/'); foreach ($folders as $folder) { //Ignore hidden directories/files... - if (strpos($folder, '.') === 0 || $folder == 'all') + if (strpos($folder, '.') === 0 || $folder == 'all') { continue; + } //Check if it is a directory - if (!is_dir($basepath . 'sites/' . $folder)) + if (!is_dir($basepath . 'sites/' . $folder)) { continue; + } //Check if files path exists... if ($this->checkFilesExists($basepath, $folder)) { @@ -650,4 +653,5 @@ public function checkMultisite($root, $baseUrl, $default = "default") { } } } + } From f08eb399ad13c458fea65f66f85c72be85f5697f Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 15 Oct 2016 11:54:43 +1100 Subject: [PATCH 5/5] Fix Jenkins Failure --- CRM/Utils/System/DrupalBase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index 19806af4c8e5..e898b3200200 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -652,6 +652,8 @@ public function checkMultisite($root, $baseUrl, $default = "default") { } } } + $this->filesUrl = self::getUrl($baseUrl, $correct); + return $this->filesUrl; } }