CRM-19097 Cache cidRefs during merge
authoreileen <emcnaughton@wikimedia.org>
Sun, 17 Jul 2016 22:58:33 +0000 (10:58 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 17 Jul 2016 22:58:33 +0000 (10:58 +1200)
CRM/Dedupe/Merger.php

index fa16d0c559b5a0a089852d0e8de6d60c2cb5340c..57abaa5b0ace74e204e63500d981ee356611db06 100644 (file)
@@ -205,27 +205,31 @@ class CRM_Dedupe_Merger {
    * Refer to CRM-17454 for information on the danger of querying the information
    * schema to derive this.
    *
-   * @todo create an 'entity hook' to allow entities to be registered to CiviCRM
-   * including all info that is normally in the DAO.
+   * This function calls the merge hook but the entityTypes hook is the recommended
+   * way to add tables to this result.
    */
   public static function cidRefs() {
-    $cidRefs = array();
+    if (isset(\Civi::$statics[__CLASS__]) && isset(\Civi::$statics[__CLASS__]['contact_references'])) {
+      return \Civi::$statics[__CLASS__]['contact_references'];
+    }
+    $contactReferences = array();
     $coreReferences = CRM_Core_DAO::getReferencesToTable('civicrm_contact');
     foreach ($coreReferences as $coreReference) {
       if (!is_a($coreReference, 'CRM_Core_Reference_Dynamic')) {
-        $cidRefs[$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey();
+        $contactReferences[$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey();
       }
     }
-    self::addCustomTablesExtendingContactsToCidRefs($cidRefs);
+    self::addCustomTablesExtendingContactsToCidRefs($contactReferences);
 
     // FixME for time being adding below line statically as no Foreign key constraint defined for table 'civicrm_entity_tag'
-    $cidRefs['civicrm_entity_tag'][] = 'entity_id';
+    $contactReferences['civicrm_entity_tag'][] = 'entity_id';
 
     // Allow hook_civicrm_merge() to adjust $cidRefs.
-    // @todo consider adding a way to register entities and have them
-    // automatically added to this list.
-    CRM_Utils_Hook::merge('cidRefs', $cidRefs);
-    return $cidRefs;
+    // Note that if entities are registered using the entityTypes hook there
+    // is no need to use this hook.
+    CRM_Utils_Hook::merge('cidRefs', $contactReferences);
+    \Civi::$statics[__CLASS__]['contact_references'] = $contactReferences;
+    return \Civi::$statics[__CLASS__]['contact_references'];
   }
 
   /**