CRM-17342 - Case Managed Entities - Don't recreate disabled relationship types
authorTim Otten <totten@civicrm.org>
Thu, 21 Jan 2016 04:15:50 +0000 (20:15 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 21 Jan 2016 04:15:50 +0000 (20:15 -0800)
Use-case:
 * Create a CaseType which includes role "Sibling of"
 * Disable role "Sibling of"
 * Flush system (eg enable/disable modules)

CRM/Case/ManagedEntities.php
CRM/Core/PseudoConstant.php

index daeebe989b037043d0cc1e29e64f99dda9c22c64..382f9a05a7b3f0ac1e251591898eee4324c8e777 100644 (file)
@@ -110,8 +110,11 @@ class CRM_Case_ManagedEntities {
   public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me) {
     $result = array();
 
-    $p = new CRM_Case_XMLProcessor();
-    $validRelTypes = $p->allRelationshipTypes();
+    if (!isset(Civi::$statics[__CLASS__]['reltypes'])) {
+      $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE, NULL);
+      Civi::$statics[__CLASS__]['reltypes'] = CRM_Utils_Array::collect(CRM_Case_XMLProcessor::REL_TYPE_CNAME, $relationshipInfo);
+    }
+    $validRelTypes = Civi::$statics[__CLASS__]['reltypes'];
 
     $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
     foreach ($relTypes as $relType) {
index 1debce267600ecdda11d746e7f8f180ef0298351..16a6ef8933d91e728827171c7d3f9dfbcc3f8127 100644 (file)
@@ -1036,14 +1036,16 @@ WHERE  id = %1";
    *   Db column name/label.
    * @param bool $reset
    *   Reset relationship types if true.
-   *
+   * @param bool|NULL $isActive
+   *   Filter by is_active. NULL to disable.
    *
    * @return array
    *   array reference of all relationship types.
    */
-  public static function &relationshipType($valueColumnName = 'label', $reset = FALSE) {
-    if (!CRM_Utils_Array::value($valueColumnName, self::$relationshipType) || $reset) {
-      self::$relationshipType[$valueColumnName] = array();
+  public static function &relationshipType($valueColumnName = 'label', $reset = FALSE, $isActive = 1) {
+    $cacheKey = $valueColumnName . '::' . $isActive;
+    if (!CRM_Utils_Array::value($cacheKey, self::$relationshipType) || $reset) {
+      self::$relationshipType[$cacheKey] = array();
 
       //now we have name/label columns CRM-3336
       $column_a_b = "{$valueColumnName}_a_b";
@@ -1052,11 +1054,13 @@ WHERE  id = %1";
       $relationshipTypeDAO = new CRM_Contact_DAO_RelationshipType();
       $relationshipTypeDAO->selectAdd();
       $relationshipTypeDAO->selectAdd("id, {$column_a_b}, {$column_b_a}, contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b");
-      $relationshipTypeDAO->is_active = 1;
+      if ($isActive !== NULL) {
+        $relationshipTypeDAO->is_active = $isActive;
+      }
       $relationshipTypeDAO->find();
       while ($relationshipTypeDAO->fetch()) {
 
-        self::$relationshipType[$valueColumnName][$relationshipTypeDAO->id] = array(
+        self::$relationshipType[$cacheKey][$relationshipTypeDAO->id] = array(
           'id' => $relationshipTypeDAO->id,
           $column_a_b => $relationshipTypeDAO->$column_a_b,
           $column_b_a => $relationshipTypeDAO->$column_b_a,
@@ -1068,7 +1072,7 @@ WHERE  id = %1";
       }
     }
 
-    return self::$relationshipType[$valueColumnName];
+    return self::$relationshipType[$cacheKey];
   }
 
   /**