CRM-16373 - Config - Remove `enableComponentIDs`
authorTim Otten <totten@civicrm.org>
Sat, 22 Aug 2015 09:45:39 +0000 (02:45 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 17 Sep 2015 22:45:00 +0000 (15:45 -0700)
Note: `enableComponents` is heavily used, but `enableComponentIDs` is only
used once.  Generally, it's much easier to write tests based on names
(`enableComponents`) than IDs (`enableComponentIDs`).

CRM/Core/BAO/ConfigSetting.php
CRM/Core/Config/Variables.php
CRM/Core/Permission.php

index 4b3a7e4e4df1c0f717fbca90b635d51ceabe64dc..646ac5ffd542c4fe9bac98a4955a5e088de92a2f 100644 (file)
@@ -322,15 +322,6 @@ class CRM_Core_BAO_ConfigSetting {
       $enableComponents = Civi::settings()->get('enable_components');
       if (!empty($enableComponents)) {
         $defaults['enableComponents'] = $enableComponents;
-
-        // Lookup component IDs. Note: Do *not* instantiate components.
-        // Classloading may not be fully setup yet.
-        $components = CRM_Core_Component::getComponentIDs();
-        $enabledComponentIDs = array();
-        foreach ($defaults['enableComponents'] as $name) {
-          $enabledComponentIDs[] = $components[$name];
-        }
-        $defaults['enableComponentIDs'] = $enabledComponentIDs;
       }
     }
   }
@@ -689,16 +680,9 @@ WHERE  option_group_id = (
    */
   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;
-    }
 
     // fix the config object
     $config->enableComponents = $enabledComponents;
-    $config->enableComponentIDs = $enabledComponentIDs;
 
     // also force reset of component array
     CRM_Core_Component::getEnabledComponents(TRUE);
index 26df64b164f3df8ec36cfc61aa040505fcad23b8..07d34def92b079685ee5f779c4f3359575f04ecb 100644 (file)
@@ -324,7 +324,6 @@ class CRM_Core_Config_Variables extends CRM_Core_Config_Defaults {
     'CiviMail',
     'CiviReport',
   );
-  public $enableComponentIDs = array(1, 6, 2, 3, 4, 8);
 
   /**
    * Should payments be accepted only via SSL?
index b9bacb0ce9ded858c997c304806d53356ea156bd..5caf02ab0c3d01047bd1bc180db847227788c148 100644 (file)
@@ -508,13 +508,14 @@ class CRM_Core_Permission {
     }
 
     // if component_id is present, ensure it is enabled
-    if (isset($item['component_id']) &&
-      $item['component_id']
-    ) {
+    if (isset($item['component_id']) && $item['component_id']) {
+      if (!isset(Civi::$statics[__CLASS__]['componentNameId'])) {
+        Civi::$statics[__CLASS__]['componentNameId'] = array_flip(CRM_Core_Component::getComponentIDs());
+      }
+      $componentName = Civi::$statics[__CLASS__]['componentNameId'][$item['component_id']];
+
       $config = CRM_Core_Config::singleton();
-      if (is_array($config->enableComponentIDs) &&
-        in_array($item['component_id'], $config->enableComponentIDs)
-      ) {
+      if (is_array($config->enableComponents) && in_array($componentName, $config->enableComponents)) {
         // continue with process
       }
       else {