Merge function back into parent function
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 14 Jan 2022 18:41:47 +0000 (07:41 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 15 Jan 2022 19:28:47 +0000 (08:28 +1300)
It isn't a logical separation of responsibility & doesn't reduce code

CRM/Contact/BAO/Contact/Utils.php

index cb0ffe1f009234dd34b16a9cbce93e811b7c0c34..0fb588840093e793b14052d4dcf0a013f59b7136 100644 (file)
@@ -294,14 +294,33 @@ WHERE  id IN ( $idString )
     // set current employer
     self::setCurrentEmployer([$contactID => $employerID]);
 
-    $relationshipParams = [
-      'relationship_ids' => $relationshipIds,
-      'is_active' => 1,
-      'contact_check' => [$employerID => TRUE],
-      'relationship_type_id' => $relationshipTypeID . '_a_b',
-    ];
-    // Handle related memberships. CRM-3792
-    self::currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate, $previousEmployerID);
+    $ids = [];
+    $action = CRM_Core_Action::ADD;
+
+    //we do not know that triggered relationship record is active.
+    if ($duplicate) {
+      $relationship = new CRM_Contact_DAO_Relationship();
+      $relationship->contact_id_a = $contactID;
+      $relationship->contact_id_b = $employerID;
+      $relationship->relationship_type_id = $relationshipTypeID;
+      if ($relationship->find(TRUE)) {
+        $action = CRM_Core_Action::UPDATE;
+        $ids['contact'] = $contactID;
+        $ids['contactTarget'] = $employerID;
+        $ids['relationship'] = $relationship->id;
+        CRM_Contact_BAO_Relationship::setIsActive($relationship->id, TRUE);
+      }
+    }
+
+    //need to handle related memberships. CRM-3792
+    if ($previousEmployerID != $employerID) {
+      CRM_Contact_BAO_Relationship::relatedMemberships($contactID, [
+        'relationship_ids' => $relationshipIds,
+        'is_active' => 1,
+        'contact_check' => [$employerID => TRUE],
+        'relationship_type_id' => $relationshipTypeID . '_a_b',
+      ], $ids, $action);
+    }
   }
 
   /**
@@ -380,28 +399,7 @@ WHERE  id IN ( $idString )
    * @throws \CRM_Core_Exception
    */
   private static function currentEmployerRelatedMembership($contactID, $employerID, $relationshipParams, $duplicate = FALSE, $previousEmployerID = NULL) {
-    $ids = [];
-    $action = CRM_Core_Action::ADD;
-
-    //we do not know that triggered relationship record is active.
-    if ($duplicate) {
-      $relationship = new CRM_Contact_DAO_Relationship();
-      $relationship->contact_id_a = $contactID;
-      $relationship->contact_id_b = $employerID;
-      $relationship->relationship_type_id = $relationshipParams['relationship_type_id'];
-      if ($relationship->find(TRUE)) {
-        $action = CRM_Core_Action::UPDATE;
-        $ids['contact'] = $contactID;
-        $ids['contactTarget'] = $employerID;
-        $ids['relationship'] = $relationship->id;
-        CRM_Contact_BAO_Relationship::setIsActive($relationship->id, TRUE);
-      }
-    }
 
-    //need to handle related memberships. CRM-3792
-    if ($previousEmployerID != $employerID) {
-      CRM_Contact_BAO_Relationship::relatedMemberships($contactID, $relationshipParams, $ids, $action);
-    }
   }
 
   /**