From: Tim Otten Date: Wed, 27 Aug 2014 03:56:59 +0000 (-0700) Subject: CRM_Core_BAO_ConfigSetting -- Add disableComponent($componentName) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b086633a21d1287c4be54216dbd1195c1f43f3cc;p=civicrm-core.git CRM_Core_BAO_ConfigSetting -- Add disableComponent($componentName) --- 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'); } /**