From 9977c6f51868c518f6440d4af45545d4ae55f9d7 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 29 May 2013 21:02:25 +1200 Subject: [PATCH] CRM-12674 wordpress fix broke update settings for drupal --- CRM/Core/BAO/ConfigSetting.php | 44 ++++---------------- CRM/Utils/System/Base.php | 12 ++++++ CRM/Utils/System/Drupal.php | 6 +-- CRM/Utils/System/Drupal6.php | 6 +-- CRM/Utils/System/DrupalBase.php | 74 +++++++++++++++++++++++++++++++++ CRM/Utils/System/Joomla.php | 22 ++++++++++ 6 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 CRM/Utils/System/DrupalBase.php diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 7882796e2c..c53d24c4a9 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -438,48 +438,22 @@ class CRM_Core_BAO_ConfigSetting { return array($url, $dir, $siteName, $siteRoot); } +/** + * Return likely default settings + * @return array site settings + * -$url, + * - $dir Base Directory + * - $siteName + * - $siteRoot + */ static function getBestGuessSettings() { $config = CRM_Core_Config::singleton(); - - $url = $config->userFrameworkBaseURL; - $siteName = $siteRoot = NULL; - if ($config->userFramework == 'Joomla') { - $url = preg_replace( - '|/administrator|', - '', - $config->userFrameworkBaseURL - ); - $siteRoot = preg_replace( - '|/media/civicrm/.*$|', - '', - $config->imageUploadDir - ); - } - $dir = preg_replace( '|civicrm/templates_c/.*$|', '', $config->templateCompileDir ); - - if ($config->userFramework->is_drupal) { - $matches = array(); - if (preg_match( - '|/sites/([\w\.\-\_]+)/|', - $config->templateCompileDir, - $matches - )) { - $siteName = $matches[1]; - if ($siteName) { - $siteName = "/sites/$siteName/"; - $siteNamePos = strpos($dir, $siteName); - if ($siteNamePos !== FALSE) { - $siteRoot = substr($dir, 0, $siteNamePos); - } - } - } - } - + list($url, $siteName, $siteRoot) = $config->userSystem->getDefaultSiteSettings($dir); return array($url, $dir, $siteName, $siteRoot); } diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index cc084af667..4d951a12e1 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -127,5 +127,17 @@ abstract class CRM_Utils_System_Base { function flush() { // nullop by default } + /** + * Return default Site Settings + * @return array array + * - $url, (Joomla - non admin url) + * - $siteName, + * - $siteRoot + */ + function getDefaultSiteSettings($dir){ + $config = CRM_Core_Config::singleton(); + $url = $config->userFrameworkBaseURL; + return array($url, NULL, NULL); + } } diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index c1652527aa..849024ae54 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -36,11 +36,7 @@ /** * Drupal specific stuff goes here */ -class CRM_Utils_System_Drupal extends CRM_Utils_System_Base { - function __construct() { - $this->is_drupal = TRUE; - $this->supports_form_extensions = TRUE; - } +class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase { /** * Function to create a user in Drupal. diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index e7a3dfe5e7..1f38223a5c 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -36,11 +36,7 @@ /** * Drupal specific stuff goes here */ -class CRM_Utils_System_Drupal6 extends CRM_Utils_System_Base { - function __construct() { - $this->is_drupal = TRUE; - $this->supports_form_extensions = TRUE; - } +class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { /** * if we are using a theming system, invoke theme, else just print the diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php new file mode 100644 index 0000000000..5550afc9fb --- /dev/null +++ b/CRM/Utils/System/DrupalBase.php @@ -0,0 +1,74 @@ +is_drupal = TRUE; + $this->supports_form_extensions = TRUE; + } + + /** + * @param string dir base civicrm directory + * Return default Site Settings + * @return array array + * - $url, (Joomla - non admin url) + * - $siteName, + * - $siteRoot + */ + function getDefaultSiteSettings($dir){ + $config = CRM_Core_Config::singleton(); + $siteName = $siteRoot = NULL; + $matches = array(); + if (preg_match( + '|/sites/([\w\.\-\_]+)/|', + $config->templateCompileDir, + $matches + )) { + $siteName = $matches[1]; + if ($siteName) { + $siteName = "/sites/$siteName/"; + $siteNamePos = strpos($dir, $siteName); + if ($siteNamePos !== FALSE) { + $siteRoot = substr($dir, 0, $siteNamePos); + } + } + } + $url = $config->userFrameworkBaseURL; + return array($url, $siteName, $siteRoot); + } +} \ No newline at end of file diff --git a/CRM/Utils/System/Joomla.php b/CRM/Utils/System/Joomla.php index 163adf2941..43952ba4ee 100644 --- a/CRM/Utils/System/Joomla.php +++ b/CRM/Utils/System/Joomla.php @@ -688,5 +688,27 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base { public function getLoginDestination(&$form) { return; } + + /** + * Return default Site Settings + * @return array array + * - $url, (Joomla - non admin url) + * - $siteName, + * - $siteRoot + */ + function getDefaultSiteSettings($dir){ + $config = CRM_Core_Config::singleton(); + $url = preg_replace( + '|/administrator|', + '', + $config->userFrameworkBaseURL + ); + $siteRoot = preg_replace( + '|/media/civicrm/.*$|', + '', + $config->imageUploadDir + ); + return array($url, NULL, $siteRoot); + } } -- 2.25.1