CRM/Report add missing comment blocks
[civicrm-core.git] / CRM / Core / ManagedEntities.php
index a1b08c8fa45895f7e64724426ddfda76bbfbd0b5..75e0c26ec659fb1882580ae6d24c2077846f4d81 100644 (file)
@@ -23,6 +23,9 @@ class CRM_Core_ManagedEntities {
     static $singleton;
     if ($fresh || !$singleton) {
       $declarations = array();
+      foreach (CRM_Core_Component::getEnabledComponents() as $component) {
+        $declarations = array_merge($declarations, $component->getManagedEntities());
+      }
       CRM_Utils_Hook::managed($declarations);
       $singleton = new CRM_Core_ManagedEntities(CRM_Core_Module::getAll(), $declarations);
     }
@@ -47,15 +50,15 @@ class CRM_Core_ManagedEntities {
     $dao->name = $name;
     if ($dao->find(TRUE)) {
       $params = array(
-        'version' => 3,
         'id' => $dao->entity_id,
       );
-      $result = civicrm_api($dao->entity_type, 'getsingle', $params);
-      if ($result['is_error']) {
+      try {
+        $result = civicrm_api3($dao->entity_type, 'getsingle', $params);
+      }
+      catch (Exception $e) {
         $this->onApiError($params, $result);
-      } else {
-        return $result;
       }
+      return $result;
     } else {
       return NULL;
     }
@@ -91,7 +94,7 @@ class CRM_Core_ManagedEntities {
   /**
    * Create, update, and delete entities declared by an active module
    *
-   * @param $module string
+   * @param \CRM_Core_Module|string $module string
    * @param $todos array $name => array()
    */
   public function reconcileEnabledModule(CRM_Core_Module $module, $todos) {
@@ -99,7 +102,7 @@ class CRM_Core_ManagedEntities {
     $dao->module = $module->name;
     $dao->find();
     while ($dao->fetch()) {
-      if ($todos[$dao->name]) {
+      if (isset($todos[$dao->name]) && $todos[$dao->name]) {
         // update existing entity; remove from $todos
         $defaults = array('id' => $dao->entity_id, 'is_active' => 1); // FIXME: test whether is_active is valid
         $params = array_merge($defaults, $todos[$dao->name]['params']);
@@ -201,6 +204,8 @@ class CRM_Core_ManagedEntities {
   }
 
   /**
+   * @param $modules
+   *
    * @return array indexed by is_active,name
    */
   protected static function createModuleIndex($modules) {
@@ -212,6 +217,9 @@ class CRM_Core_ManagedEntities {
   }
 
   /**
+   * @param $moduleIndex
+   * @param $declarations
+   *
    * @return array indexed by module,name
    */
   protected static function createDeclarationIndex($moduleIndex, $declarations) {
@@ -232,6 +240,8 @@ class CRM_Core_ManagedEntities {
   }
 
   /**
+   * @param $declarations
+   *
    * @return mixed string on error, or FALSE
    */
   protected static function validate($declarations) {