From: Deepak Srivastava Date: Fri, 5 Jul 2013 14:06:54 +0000 (+0530) Subject: CRM-12846 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3124edb393133aa35472ce7326d06b88fda31800;p=civicrm-core.git CRM-12846 ---------------------------------------- * CRM-12846: API support for toggling components by storing 'enableComponents' config in settings table http://issues.civicrm.org/jira/browse/CRM-12846 --- diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index 80ea92057d..6d65cad901 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -219,6 +219,16 @@ LIMIT 1 unset($params['autocompleteContactReference']); } + // save components to be enabled + if (CRM_Utils_Array::value('enableComponents', $params)) { + CRM_Core_BAO_Setting::setItem($params['enableComponents'], + CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,'enable_components'); + + // unset params by emptying the values, so while retrieving we can detect and load from settings table + // instead of config-backend for backward compatibility. We could use unset() in later releases. + $params['enableComponents'] = $params['enableComponentIDs'] = array(); + } + // save checksum timeout if (CRM_Utils_Array::value('checksumTimeout', $params)) { CRM_Core_BAO_Setting::setItem($params['checksumTimeout'], diff --git a/CRM/Admin/Form/Setting/Component.php b/CRM/Admin/Form/Setting/Component.php index 8b87877e9d..b855218d17 100644 --- a/CRM/Admin/Form/Setting/Component.php +++ b/CRM/Admin/Form/Setting/Component.php @@ -108,11 +108,6 @@ class CRM_Admin_Form_Setting_Component extends CRM_Admin_Form_Setting { public function postProcess() { $params = $this->controller->exportValues($this->_name); - $params['enableComponentIDs'] = array(); - foreach ($params['enableComponents'] as $name) { - $params['enableComponentIDs'][] = $this->_components[$name]->componentID; - } - // if CiviCase is being enabled, // load the case related sample data if (in_array('CiviCase', $params['enableComponents']) && diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index 193873ab4a..40a807361a 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -352,6 +352,20 @@ class CRM_Core_BAO_ConfigSetting { if (!empty($defaults)) { // retrieve directory and url preferences also CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults); + + // Pickup enabled-components from settings table. + // For backward compatibility we will have to make sure we not finding the values from config-backend. + if (!CRM_Utils_Array::value('enableComponents', $defaults)) { + $defaults['enableComponents'] = + CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); + + $components = CRM_Core_Component::getComponents(); + $enabledComponentIDs = array(); + foreach ($defaults['enableComponents'] as $name) { + $enabledComponentIDs[] = $components[$name]->componentID; + } + $defaults['enableComponentIDs'] = $enabledComponentIDs; + } } } @@ -613,48 +627,26 @@ WHERE option_group_id = ( return FALSE; } - // get config_backend value - $sql = " -SELECT config_backend -FROM civicrm_domain -WHERE id = %1 -"; - $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer')); - $configBackend = CRM_Core_DAO::singleValueQuery($sql, $params); + // get enabled-components from DB and add to the list + $enabledComponents = + CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); + $enabledComponents[] = $componentName; - if (!$configBackend) { - static $alreadyVisited = FALSE; - if ($alreadyVisited) { - CRM_Core_Error::fatal(ts('Returning early due to unexpected error - civicrm_domain.config_backend column value is NULL. Try visiting CiviCRM Home page.')); - } - - $alreadyVisited = TRUE; - - // try to recreate the config backend - $config = CRM_Core_Config::singleton(TRUE, TRUE); - return self::enableComponent($componentName); + $enabledComponentIDs = array(); + foreach ($enabledComponents as $name) { + $enabledComponentIDs[] = $components[$name]->componentID; } - $configBackend = unserialize($configBackend); - - $configBackend['enableComponents'][] = $componentName; - $configBackend['enableComponentIDs'][] = $components[$componentName]->componentID; // fix the config object - $config->enableComponents = $configBackend['enableComponents']; - $config->enableComponentIDs = $configBackend['enableComponentIDs']; + $config->enableComponents = $enabledComponents; + $config->enableComponentIDs = $enabledComponentIDs; // also force reset of component array CRM_Core_Component::getEnabledComponents(TRUE); - // check if component is already there, is so return - $configBackend = serialize($configBackend); - $sql = " -UPDATE civicrm_domain -SET config_backend = %2 -WHERE id = %1 -"; - $params[2] = array($configBackend, 'String'); - CRM_Core_DAO::executeQuery($sql, $params); + // update DB + CRM_Core_BAO_Setting::setItem($enabledComponents, + CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,'enable_components'); return TRUE; }