CRM-12846
authorDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Fri, 5 Jul 2013 14:06:54 +0000 (19:36 +0530)
committerDeepak Srivastava <deepak.srivastava@webaccess.co.in>
Fri, 5 Jul 2013 14:06:54 +0000 (19:36 +0530)
----------------------------------------
* CRM-12846: API support for toggling components by storing 'enableComponents' config in settings table
  http://issues.civicrm.org/jira/browse/CRM-12846

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

index 80ea92057dd19f0918cebd7df6a0fe19cf492c1a..6d65cad9012231b70859effb0442480fa50d0d3e 100644 (file)
@@ -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'],
index 8b87877e9da8034ad579f7872df0d93f336acc1f..b855218d17a4dc2511d4cf174eb996828b426e48 100644 (file)
@@ -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']) &&
index 193873ab4a6505ac701a417bdbe783fc024b103f..40a807361aee4c6ba4efdf3aa7b6510372740aab 100644 (file)
@@ -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;
   }