From: Eileen McNaughton Date: Mon, 10 Jan 2022 00:01:30 +0000 (+1300) Subject: Clean up input and outputs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;ds=sidebyside;h=12e948808318d36373e3110dc32bd33ff8dbf75f;p=civicrm-core.git Clean up input and outputs By grepping universe we can see that params['contact_check'] only ever has one value when called from the supported core place and the unsupported jma grant application extension place. By clarifying that here we can do further cleanup without having to re-search universe... --- diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 618d792454..eb20427108 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -162,9 +162,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @return array * @throws \CRM_Core_Exception */ - public static function legacyCreateMultiple(&$params, $ids = []) { - $valid = $invalid = $duplicate = $saved = 0; - $relationships = $relationshipIds = []; + public static function legacyCreateMultiple($params, $ids = []) { // 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) @@ -174,11 +172,14 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { $ids = ['contact' => $ids['contact']]; // Likewise neither place ever passed in relationshipID $relationshipId = NULL; + // There is only ever one value passed in from the 2 places above that call + // this - by clarifying here like this we can cleanup within this + // function without having to do more universe searches. + $relatedContactIDs = [key($params['contact_check'])]; if (!$relationshipId) { // creating a new relationship - $relationshipIds = []; - foreach (array_keys($params['contact_check']) as $relatedContactID) { + foreach ($relatedContactIDs as $relatedContactID) { // check if the relationship is valid between contacts. // step 1: check if the relationship is valid if not valid skip and keep the count // step 2: check the if two contacts already have a relationship if yes skip and keep the count @@ -188,8 +189,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { $contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID); $errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID); if ($errors) { - $invalid++; - continue; + return [0, 0]; } //CRM-16978:check duplicate relationship as per case id. @@ -206,25 +206,21 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { $relatedContactID ) ) { - $duplicate++; - continue; + return [0, 1]; } $singleInstanceParams = array_merge($params, $contactFields); $relationship = self::add($singleInstanceParams); - $relationshipIds[] = $relationship->id; - $relationships[$relationship->id] = $relationship; - $valid++; } // editing the relationship } // do not add to recent items for import, CRM-4399 - if (!(!empty($params['skipRecentView']) || $invalid || $duplicate)) { + if (!(!empty($params['skipRecentView']))) { self::addRecent($params, $relationship); } - return [$valid, $duplicate]; + return [1, 0]; } /**