From: Tim Otten Date: Thu, 17 Sep 2015 05:59:05 +0000 (-0700) Subject: SettingsManager::getSystemDefaults() - Return defaults even for critical boot settings X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ac47f7cadd5d156bd6d261001ec1f27fd848f5c6;p=civicrm-core.git SettingsManager::getSystemDefaults() - Return defaults even for critical boot settings This fixes some issues in tests involving enableComponents. Upshot: The UI for setting URLs/directories now displays the default values properly. --- diff --git a/CRM/Core/Config/MagicMerge.php b/CRM/Core/Config/MagicMerge.php index 9b01f25825..4268abd1c9 100644 --- a/CRM/Core/Config/MagicMerge.php +++ b/CRM/Core/Config/MagicMerge.php @@ -165,18 +165,18 @@ class CRM_Core_Config_MagicMerge { 'templateCompileDir' => array('runtime'), 'templateDir' => array('runtime'), - 'customFileUploadDir' => array('setting-path', NULL, '[civicrm.files]/custom/', array('mkdir', 'restrict')), + 'customFileUploadDir' => array('setting-path', NULL, array('mkdir', 'restrict')), 'customPHPPathDir' => array('setting-path'), 'customTemplateDir' => array('setting-path'), 'extensionsDir' => array('setting-path'), - 'imageUploadDir' => array('setting-path', NULL, '[civicrm.files]/persist/contribute/', array('mkdir')), - 'uploadDir' => array('setting-path', NULL, '[civicrm.files]/upload/', array('mkdir', 'restrict')), + 'imageUploadDir' => array('setting-path', NULL, array('mkdir')), + 'uploadDir' => array('setting-path', NULL, array('mkdir', 'restrict')), 'customCSSURL' => array('setting-url-abs'), 'extensionsURL' => array('setting-url-abs'), - 'imageUploadURL' => array('setting-url-abs', NULL, '[civicrm.files]/persist/contribute/'), - 'resourceBase' => array('setting-url-rel', 'userFrameworkResourceURL', '[civicrm]/.'), - 'userFrameworkResourceURL' => array('setting-url-abs', NULL, '[civicrm]/.'), + 'imageUploadURL' => array('setting-url-abs'), + 'resourceBase' => array('setting-url-rel', 'userFrameworkResourceURL'), + 'userFrameworkResourceURL' => array('setting-url-abs'), 'geocodeMethod' => array('callback', 'CRM_Utils_Geocode', 'getProviderClass'), 'defaultCurrencySymbol' => array('callback', 'CRM_Core_BAO_Country', 'getDefaultCurrencySymbol'), @@ -199,18 +199,15 @@ class CRM_Core_Config_MagicMerge { return $this->getSettings()->get($name); case 'setting-path': - // Array(0 => $type, 1 => $setting, 2 => $default, 3 => $actions). + // Array(0 => $type, 1 => $setting, 2 => $actions). $value = $this->getSettings()->get($name); - if (empty($value) && isset($this->map[$k][2])) { - $value = $this->map[$k][2]; - } $value = Civi::paths()->getPath($value); if ($value) { $value = CRM_Utils_File::addTrailingSlash($value); - if (isset($this->map[$k][3]) && in_array('mkdir', $this->map[$k][3])) { + if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) { CRM_Utils_File::createDir($value); } - if (isset($this->map[$k][3]) && in_array('restrict', $this->map[$k][3])) { + if (isset($this->map[$k][2]) && in_array('restrict', $this->map[$k][2])) { CRM_Utils_File::restrictAccess($value); } } @@ -218,20 +215,12 @@ class CRM_Core_Config_MagicMerge { return $value; case 'setting-url-abs': - // Array(0 => $type, 1 => $setting, 2 => $default). $value = $this->getSettings()->get($name); - if (empty($value) && isset($this->map[$k][2])) { - $value = $this->map[$k][2]; - } $this->cache[$k] = Civi::paths()->getUrl($value, 'absolute'); return $this->cache[$k]; case 'setting-url-rel': - // Array(0 => $type, 1 => $setting, 2 => $default). $value = $this->getSettings()->get($name); - if (empty($value) && isset($this->map[$k][2])) { - $value = $this->map[$k][2]; - } $this->cache[$k] = Civi::paths()->getUrl($value, 'relative'); return $this->cache[$k]; diff --git a/Civi/Core/Paths.php b/Civi/Core/Paths.php index a9d4d6e165..230ea24254 100644 --- a/Civi/Core/Paths.php +++ b/Civi/Core/Paths.php @@ -28,9 +28,9 @@ class Paths { public function __construct() { $this - ->register('civicrm', function () { - return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage(); - }) + //->register('civicrm', function () { + // return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage(); + //}) ->register('civicrm.root', function () { return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage(); }) @@ -121,9 +121,9 @@ class Paths { */ public function getUrl($value, $preferFormat = 'relative', $ssl = NULL) { $defaultContainer = self::DEFAULT_URL; - if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\]/(.*);', $value, $matches)) { + if ($value && $value{0} == '[' && preg_match(';^\[([a-zA-Z0-9\._]+)\](/(.*))$;', $value, $matches)) { $defaultContainer = $matches[1]; - $value = $matches[2]; + $value = empty($matches[3]) ? '.' : $matches[3]; } if (empty($value)) { diff --git a/Civi/Core/SettingsBag.php b/Civi/Core/SettingsBag.php index 3448b32b8f..73b820fb56 100644 --- a/Civi/Core/SettingsBag.php +++ b/Civi/Core/SettingsBag.php @@ -80,8 +80,6 @@ class SettingsBag { */ protected $values; - protected $filteredValues; - /** * @param int $domainId * The domain for which we want settings. @@ -92,7 +90,6 @@ class SettingsBag { $this->domainId = $domainId; $this->contactId = $contactId; $this->values = array(); - $this->filteredValues = array(); $this->combined = NULL; } @@ -105,7 +102,6 @@ class SettingsBag { */ public function loadDefaults($defaults) { $this->defaults = $defaults; - $this->filteredValues = array(); $this->combined = NULL; return $this; } @@ -119,7 +115,6 @@ class SettingsBag { */ public function loadMandatory($mandatory) { $this->mandatory = $mandatory; - $this->filteredValues = array(); $this->combined = NULL; return $this; } @@ -276,7 +271,6 @@ class SettingsBag { public function set($key, $value) { $this->setDb($key, $value); $this->values[$key] = $value; - unset($this->filteredValues[$key]); $this->combined = NULL; return $this; } diff --git a/Civi/Core/SettingsManager.php b/Civi/Core/SettingsManager.php index 7194da1a7b..fe47d5e41d 100644 --- a/Civi/Core/SettingsManager.php +++ b/Civi/Core/SettingsManager.php @@ -202,7 +202,7 @@ class SettingsManager { */ protected function getDefaults($entity) { if (!$this->useDefaults) { - return array(); + return self::getSystemDefaults($entity); } $cacheKey = 'defaults:' . $entity; @@ -215,6 +215,7 @@ class SettingsManager { foreach ($specs as $key => $spec) { $defaults[$key] = \CRM_Utils_Array::value('default', $spec); } + \CRM_Utils_Array::extend($defaults, self::getSystemDefaults($entity)); $this->cache->set($cacheKey, $defaults); } return $defaults; @@ -307,7 +308,7 @@ class SettingsManager { $bag->loadMandatory($this->getMandatory('domain')); } - foreach ($this->bagsByDomain as $bag) { + foreach ($this->bagsByContact as $bag) { /** @var SettingsBag $bag */ $bag->loadValues(); $bag->loadDefaults($this->getDefaults('contact')); @@ -317,4 +318,32 @@ class SettingsManager { return $this; } + /** + * Get a list of critical system defaults. + * + * The setting system can be modified by extensions, which means that it's not fully available + * during bootstrap -- in particular, defaults cannot be loaded. For a very small number of settings, + * we must define defaults before the system bootstraps. + * + * @return array + */ + private static function getSystemDefaults($entity) { + $defaults = array(); + switch ($entity) { + case 'domain': + $defaults = array( + 'enable_components' => array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'), + 'customFileUploadDir' => '[civicrm.files]/custom/', + 'imageUploadDir' => '[civicrm.files]/persist/contribute/', + 'uploadDir' => '[civicrm.files]/upload/', + 'imageUploadURL' => '[civicrm.files]/persist/contribute/', + 'resourceBase' => '[civicrm.root]/', + 'userFrameworkResourceURL' => '[civicrm.root]/', + ); + break; + + } + return $defaults; + } + } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 68d8e18f02..571e8a378d 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -662,6 +662,7 @@ return array( 'help_text' => NULL, ), 'enable_components' => array( + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'CiviCRM Preferences', 'group' => 'core', 'name' => 'enable_components', @@ -673,7 +674,7 @@ return array( 'style' => 'width:150px', 'class' => 'advmultiselect', ), - 'default' => array('CiviEvent', 'CiviContribute', 'CiviMember', 'CiviMail', 'CiviReport', 'CiviPledge'), + 'default' => NULL, 'add' => '4.4', 'title' => 'Enable Components', 'is_domain' => '1', diff --git a/settings/Directory.setting.php b/settings/Directory.setting.php index 7296bce7c9..069d37e024 100644 --- a/settings/Directory.setting.php +++ b/settings/Directory.setting.php @@ -38,7 +38,7 @@ return array( 'uploadDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'uploadDir', @@ -54,7 +54,7 @@ return array( 'help_text' => 'File system path where temporary CiviCRM files - such as import data files - are uploaded.', ), 'imageUploadDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'imageUploadDir', @@ -70,7 +70,7 @@ return array( 'help_text' => NULL, ), 'customFileUploadDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'customFileUploadDir', @@ -86,7 +86,7 @@ return array( 'help_text' => NULL, ), 'customTemplateDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'customTemplateDir', @@ -102,7 +102,7 @@ return array( 'help_text' => NULL, ), 'customPHPPathDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'customPHPPathDir', @@ -118,7 +118,7 @@ return array( 'help_text' => NULL, ), 'extensionsDir' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group_name' => 'Directory Preferences', 'group' => 'directory', 'name' => 'extensionsDir', diff --git a/settings/Url.setting.php b/settings/Url.setting.php index 21db6495ca..886e218beb 100644 --- a/settings/Url.setting.php +++ b/settings/Url.setting.php @@ -37,7 +37,7 @@ */ return array( 'userFrameworkResourceURL' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group' => 'url', 'group_name' => 'URL Preferences', 'name' => 'userFrameworkResourceURL', @@ -54,7 +54,7 @@ return array( 'validate_callback' => 'CRM_Utils_Rule::urlish', ), 'imageUploadURL' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group' => 'url', 'group_name' => 'URL Preferences', 'title' => 'Image Upload URL', @@ -71,7 +71,7 @@ return array( 'validate_callback' => 'CRM_Utils_Rule::urlish', ), 'customCSSURL' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group' => 'url', 'group_name' => 'URL Preferences', 'name' => 'customCSSURL', @@ -88,7 +88,7 @@ return array( 'validate_callback' => 'CRM_Utils_Rule::urlish', ), 'extensionsURL' => array( - 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults and other metadata may not be available during bootstrap.', + 'bootstrap_comment' => 'This is a boot setting which may be loaded during bootstrap. Defaults are loaded via SettingsBag::getSystemDefaults().', 'group' => 'url', 'group_name' => 'URL Preferences', 'title' => 'Extension Resource URL',