CRM-15365 - Windows Directory Fixes
authorDan Cruson <cruson.web@gmail.com>
Wed, 24 Sep 2014 16:32:34 +0000 (12:32 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 26 Sep 2014 17:40:40 +0000 (13:40 -0400)
CRM-15365 - Fix problems with adjusting directories through the UI

CRM/Admin/Form/Setting/UpdateConfigBackend.php
CRM/Core/BAO/ConfigSetting.php

index f543c1796282b7b5b5f566c975744a23f970654d..7fadf6264b095fadc229556283872ad5433ba497 100644 (file)
@@ -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']),
index 3d728a0d875c6809dd8f05c00322f4a805bcf6b5..34a8509e62959fd29481612241834a1507903dff 100644 (file)
@@ -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
     );