[Ref] Get rid of private deprecated legacy function
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 5 May 2022 11:12:58 +0000 (23:12 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 5 May 2022 11:12:58 +0000 (23:12 +1200)
It now doesn't have enough code to justify it's own function

CRM/Contact/BAO/Contact/Utils.php

index e5e149a30a5937fb9f846c0a3ede43ee3fb03ea5..fb8d5bacac001d3490cd8514e65ef4b8b3e0f518 100644 (file)
@@ -273,7 +273,6 @@ WHERE  id IN ( $idString )
       return;
     }
     $relationshipIds = [];
-    // create employee of relationship
     $duplicate = CRM_Contact_BAO_Relationship::checkDuplicateRelationship(
       [
         'contact_id_a' => $contactID,
@@ -281,11 +280,19 @@ WHERE  id IN ( $idString )
         'relationship_type_id' => $relationshipTypeID,
       ],
       $contactID,
-      // step 2
       $employerID
     );
     if (!$duplicate) {
-      $relationshipIds = [self::legacyCreateMultiple($relationshipTypeID, $employerID, $contactID)];
+      $params = [
+        'is_active' => TRUE,
+        'contact_check' => [$employerID => TRUE],
+        'contact_id_a' => $contactID,
+        'contact_id_b' => $employerID,
+        'relationship_type_id' => $relationshipTypeID,
+      ];
+      $relationship = CRM_Contact_BAO_Relationship::add($params);
+      CRM_Contact_BAO_Relationship::addRecent($params, $relationship);
+      $relationshipIds = [$relationship->id];
     }
 
     // In case we change employer, clean previous employer related records.
@@ -330,36 +337,6 @@ WHERE  id IN ( $idString )
     }
   }
 
-  /**
-   * Previously shared function in need of cleanup.
-   *
-   * Takes an associative array and creates a relationship object.
-   *
-   * @deprecated For single creates use the api instead (it's tested).
-   * For multiple a new variant of this function needs to be written and migrated to as this is a bit
-   * nasty
-   *
-   * @param int $relationshipTypeID
-   * @param int $organizationID
-   * @param int $contactID
-   *
-   * @return array
-   * @throws \CiviCRM_API3_Exception
-   */
-  private static function legacyCreateMultiple(int $relationshipTypeID, int $organizationID, int $contactID): int {
-    $params = [
-      'is_active' => TRUE,
-      'contact_check' => [$organizationID => TRUE],
-      'contact_id_a' => $contactID,
-      'contact_id_b' => $organizationID,
-      'relationship_type_id' => $relationshipTypeID,
-    ];
-    $relationship = CRM_Contact_BAO_Relationship::add($params);
-    CRM_Contact_BAO_Relationship::addRecent($params, $relationship);
-
-    return $relationship->id;
-  }
-
   /**
    * Create related memberships for current employer.
    *