RelationshipType - Flush static caches after creating RelationshipType
authorTim Otten <totten@civicrm.org>
Mon, 14 Jul 2014 05:55:29 +0000 (22:55 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 14 Jul 2014 05:55:29 +0000 (22:55 -0700)
CRM/Case/XMLProcessor.php
CRM/Contact/BAO/RelationshipType.php

index 49a63387352fa40fac07889f0be3907199acf9fa..a174a6a8ea472bf5a0d53b13ce2d191bd45cf49f 100644 (file)
  */
 class CRM_Case_XMLProcessor {
 
+  /**
+   * FIXME: This does *NOT* belong in a static property, but we're too late in
+   * the 4.5-cycle to do the necessary cleanup.
+   *
+   * @var array|null array(int $id => string $relTypeCname)
+   */
+  public static $activityTypes = NULL;
+
+  /**
+   * FIXME: This does *NOT* belong in a static property, but we're too late in
+   * the 4.5-cycle to do the necessary cleanup.
+   *
+   * @var array|null array(int $id => string $relTypeCname)
+   */
+  public static $relationshipTypes = NULL;
+
   /**
    * Relationship-types have four name fields (name_a_b, name_b_a, label_a_b,
    * label_b_a), but CiviCase XML refers to reltypes by a single name.
@@ -86,29 +102,34 @@ class CRM_Case_XMLProcessor {
    * @return array
    */
   function &allActivityTypes($indexName = TRUE, $all = FALSE) {
-    static $activityTypes = NULL;
-    if (!$activityTypes) {
-      $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
+    if (self::$activityTypes === NULL) {
+      self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
     }
-    return $activityTypes;
+    return self::$activityTypes;
   }
 
   /**
    * @return array
    */
   function &allRelationshipTypes() {
-    static $relationshipTypes = array();
-
-    if (!$relationshipTypes) {
-      $relationshipInfo = CRM_Core_PseudoConstant::relationshipType();
+    if (self::$relationshipTypes === NULL) {
+      $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE);
 
-      $relationshipTypes = array();
+      self::$relationshipTypes = array();
       foreach ($relationshipInfo as $id => $info) {
-        $relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
+        self::$relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
       }
     }
 
-    return $relationshipTypes;
+    return self::$relationshipTypes;
+  }
+
+  /**
+   * FIXME: This should not exist
+   */
+  public static function flushStaticCaches() {
+    self::$activityTypes = NULL;
+    self::$relationshipTypes = NULL;
   }
 }
 
index 58ec7cefd5c5355fc178336900973b20118fa50e..b41a21afda6d5caffc85f7c958c7f96eb79aefa2 100644 (file)
@@ -126,7 +126,12 @@ class CRM_Contact_BAO_RelationshipType extends CRM_Contact_DAO_RelationshipType
 
     $relationshipType->id = CRM_Utils_Array::value('relationshipType', $ids);
 
-    return $relationshipType->save();
+    $result = $relationshipType->save();
+
+    CRM_Core_PseudoConstant::relationshipType('label', TRUE);
+    CRM_Core_PseudoConstant::relationshipType('name', TRUE);
+    CRM_Case_XMLProcessor::flushStaticCaches();
+    return $result;
   }
 
   /**