From b086633a21d1287c4be54216dbd1195c1f43f3cc Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 26 Aug 2014 20:56:59 -0700 Subject: [PATCH] CRM_Core_BAO_ConfigSetting -- Add disableComponent($componentName) --- CRM/Core/BAO/ConfigSetting.php | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index d86a57a74f..3d728a0d87 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -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'); } /** -- 2.25.1