// 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;
}
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;
// 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');
}
/**