Clarify contents of ids for further fixes
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 7 Jan 2022 01:37:47 +0000 (14:37 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 7 Jan 2022 02:28:57 +0000 (15:28 +1300)
CRM/Contact/BAO/Relationship.php

index dd94e3daa230c2f78f9d543bfbea77a996db0631..76b25e760abc767a12efdfb3f12bad0a9dcdf463 100644 (file)
@@ -165,26 +165,23 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
   public static function legacyCreateMultiple(&$params, $ids = []) {
     $valid = $invalid = $duplicate = $saved = 0;
     $relationships = $relationshipIds = [];
-    $relationshipId = CRM_Utils_Array::value('relationship', $ids, CRM_Utils_Array::value('id', $params));
-
-    //CRM-9015 - the hooks are called here & in add (since add doesn't call create)
+    // clarify that the only key ever pass in the ids array is 'contact'
+    // There is legacy handling for other keys but a universe search on
+    // calls to this function (not supported to be called from outside core)
+    // only returns 2 calls - one in CRM_Contact_Import_Parser_Contact
+    // and the other in jma grant applications (CRM_Grant_Form_Grant_Confirm)
+    // both only pass in contact as a key here.
+    $ids = ['contact' => $ids['contact']];
+    // Likewise neither place ever passed in relationshipID
+    $relationshipId = NULL;
+    $hook = 'create';
+    // CRM-9015 - the hooks are called here & in add (since add doesn't call create)
     // but in future should be tidied per ticket
-    if (empty($relationshipId)) {
-      $hook = 'create';
-    }
-    else {
-      $hook = 'edit';
-    }
-
     // @todo pre hook is called from add - remove it from here
     CRM_Utils_Hook::pre($hook, 'Relationship', $relationshipId, $params);
 
     if (!$relationshipId) {
       // creating a new relationship
-      $dataExists = self::dataExists($params);
-      if (!$dataExists) {
-        return [FALSE, TRUE, FALSE, FALSE, NULL];
-      }
       $relationshipIds = [];
       foreach ($params['contact_check'] as $key => $value) {
         // check if the relationship is valid between contacts.