Commit 3124edb3 authored by Deepak Srivastava's avatar Deepak Srivastava

CRM-12846

----------------------------------------
* CRM-12846: API support for toggling components by storing 'enableComponents' config in settings table
  http://issues.civicrm.org/jira/browse/CRM-12846
parent 38fe30e2
......@@ -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'],
......
......@@ -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']) &&
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment