CRM_Core_BAO_ConfigSetting -- Add disableComponent($componentName)
authorTim Otten <totten@civicrm.org>
Wed, 27 Aug 2014 03:56:59 +0000 (20:56 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 27 Aug 2014 03:56:59 +0000 (20:56 -0700)
CRM/Core/BAO/ConfigSetting.php

index d86a57a74f3b5a0c6cd65fd6d94506e87b7b5edb..3d728a0d875c6809dd8f05c00322f4a805bcf6b5 100644 (file)
@@ -626,10 +626,9 @@ WHERE  option_group_id = (
       // component is already enabled
       return TRUE;
     }
-    $components = CRM_Core_Component::getComponents();
 
     // return if component does not exist
-    if (!array_key_exists($componentName, $components)) {
+    if (!array_key_exists($componentName, CRM_Core_Component::getComponents())) {
       return FALSE;
     }
 
@@ -638,6 +637,32 @@ WHERE  option_group_id = (
       CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
     $enabledComponents[] = $componentName;
 
+    self::setEnabledComponents($enabledComponents);
+
+    return TRUE;
+  }
+
+  static function disableComponent($componentName) {
+    $config = CRM_Core_Config::singleton();
+    if (!in_array($componentName, $config->enableComponents) || !array_key_exists($componentName, CRM_Core_Component::getComponents())) {
+      // post-condition satisified
+      return TRUE;
+    }
+
+    // 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 = array_diff($enabledComponents, array($componentName));
+
+    self::setEnabledComponents($enabledComponents);
+
+    return TRUE;
+  }
+
+  public static function setEnabledComponents($enabledComponents) {
+    $config = CRM_Core_Config::singleton();
+    $components = CRM_Core_Component::getComponents();
+
     $enabledComponentIDs = array();
     foreach ($enabledComponents as $name) {
       $enabledComponentIDs[] = $components[$name]->componentID;
@@ -652,9 +677,7 @@ WHERE  option_group_id = (
 
     // update DB
     CRM_Core_BAO_Setting::setItem($enabledComponents,
-      CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,'enable_components');
-
-    return TRUE;
+      CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
   }
 
   /**