From 37b395e8cfec1ebfc33973669e93cd3585c4bdd9 Mon Sep 17 00:00:00 2001 From: Dan Cruson Date: Wed, 24 Sep 2014 12:32:34 -0400 Subject: [PATCH] CRM-15365 - Windows Directory Fixes CRM-15365 - Fix problems with adjusting directories through the UI --- .../Form/Setting/UpdateConfigBackend.php | 10 ++- CRM/Core/BAO/ConfigSetting.php | 85 ++++++++++++++----- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/CRM/Admin/Form/Setting/UpdateConfigBackend.php b/CRM/Admin/Form/Setting/UpdateConfigBackend.php index f543c17962..7fadf6264b 100644 --- a/CRM/Admin/Form/Setting/UpdateConfigBackend.php +++ b/CRM/Admin/Form/Setting/UpdateConfigBackend.php @@ -135,10 +135,18 @@ class CRM_Admin_Form_Setting_UpdateConfigBackend extends CRM_Admin_Form_Setting //CRM-5679 foreach ($params as $name => & $val) { if ($val && in_array($name, array( - 'newBaseURL', 'newBaseDir', 'newSiteName'))) { + 'newBaseDir', 'newSiteName'))) { $val = CRM_Utils_File::addTrailingSlash($val); } } + + //CRM-15365 - Fix BaseURL to avoid wrong trailing slash on Windows installs + foreach ($params as $name => & $val) { + if ($val && in_array($name, array( + 'newBaseURL'))) { + $val = CRM_Utils_File::addTrailingSlash($val,"/"); + } + } $from = array($this->_oldBaseURL, $this->_oldBaseDir); $to = array(trim($params['newBaseURL']), diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 3d728a0d87..34a8509e62 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -383,11 +383,25 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|civicrm/templates_c/.*$|', - '', - $config->templateCompileDir - ); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if(DIRECTORY_SEPARATOR == '\\') + { + $dir = preg_replace( + '|civicrm[/\\\\]templates_c[/\\\\].*$|', + '', + $config->templateCompileDir + ); + } + else + { + $dir = preg_replace( + '|civicrm/templates_c/.*$|', + '', + $config->templateCompileDir + ); + } + $siteRoot = preg_replace( '|/media/civicrm/.*$|', '', @@ -404,11 +418,25 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|civicrm/templates_c/.*$|', - '', - $config->templateCompileDir - ); + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if(DIRECTORY_SEPARATOR == '\\') + { + $dir = preg_replace( + '|civicrm[/\\\\]templates_c[/\\\\].*$|', + '', + $config->templateCompileDir + ); + } + else + { + $dir = preg_replace( + '|civicrm/templates_c/.*$|', + '', + $config->templateCompileDir + ); + } + $siteRoot = preg_replace( '|/wp-content/plugins/files/civicrm/.*$|', '', @@ -425,12 +453,25 @@ class CRM_Core_BAO_ConfigSetting { // lets use imageUploadDir since we dont mess around with its values // in the config object, lets kep it a bit generic since folks // might have different values etc - $dir = preg_replace( - '|/files/civicrm/.*$|', - '/files/', - $config->imageUploadDir - ); - + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if(DIRECTORY_SEPARATOR == '\\') + { + $dir = preg_replace( + '|[/\\\\]files[/\\\\]civicrm[/\\\\].*$|', + '\\\\files\\\\', + $config->imageUploadDir + ); + } + else + { + $dir = preg_replace( + '|/files/civicrm/.*$|', + '/files/', + $config->imageUploadDir + ); + } + $matches = array(); if (preg_match( '|/sites/([\w\.\-\_]+)/|', @@ -448,7 +489,6 @@ class CRM_Core_BAO_ConfigSetting { } } - return array($url, $dir, $siteName, $siteRoot); } @@ -462,8 +502,15 @@ class CRM_Core_BAO_ConfigSetting { */ static function getBestGuessSettings() { $config = CRM_Core_Config::singleton(); - $dir = preg_replace( - '|civicrm/templates_c/.*$|', + + //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths + if(DIRECTORY_SEPARATOR == '\\') + $needle = 'civicrm[/\\\\]templates_c[/\\\\].*$'; + else + $needle = 'civicrm/templates_c/.*$'; + + $dir = preg_replace( + "|$needle|", '', $config->templateCompileDir ); -- 2.25.1