From fa8e67b8ddff1257e4aebca716d2bca810ba777a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 20 Jan 2016 20:15:50 -0800 Subject: [PATCH] CRM-17342 - Case Managed Entities - Don't recreate disabled relationship types Use-case: * Create a CaseType which includes role "Sibling of" * Disable role "Sibling of" * Flush system (eg enable/disable modules) --- CRM/Case/ManagedEntities.php | 7 +++++-- CRM/Core/PseudoConstant.php | 18 +++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CRM/Case/ManagedEntities.php b/CRM/Case/ManagedEntities.php index daeebe989b..382f9a05a7 100644 --- a/CRM/Case/ManagedEntities.php +++ b/CRM/Case/ManagedEntities.php @@ -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) { diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 1debce2676..16a6ef8933 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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]; } /** -- 2.25.1