From 58628545c1c1aa11a3d8f956c230ff9aa54c0ae6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 7 Jan 2022 09:53:38 +1300 Subject: [PATCH] Remove always-true IF --- CRM/Contact/BAO/Contact/Utils.php | 82 +++++++++++++++---------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 7b5d72ef71..3383edbd8b 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -331,58 +331,54 @@ WHERE id IN ( $idString ) $valid = $invalid = $duplicate = $saved = 0; $relationships = $relationshipIds = []; $ids = ['contact' => $contactID]; - $relationshipId = NULL; //CRM-9015 - the hooks are called here & in add (since add doesn't call create) // but in future should be tidied per ticket $hook = 'create'; // @todo pre hook is called from add - remove it from here - CRM_Utils_Hook::pre($hook, 'Relationship', $relationshipId, $params); + CRM_Utils_Hook::pre($hook, 'Relationship', NULL, $params); - if (!$relationshipId) { - // creating a new relationship - $dataExists = CRM_Contact_BAO_Relationship::dataExists($params); - if (!$dataExists) { - return [FALSE, TRUE, FALSE, FALSE, NULL]; + // creating a new relationship + $dataExists = CRM_Contact_BAO_Relationship::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. + // 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 + // step 3: if valid relationship then add the relation and keep the count + + // step 1 + $contactFields = CRM_Contact_BAO_Relationship::setContactABFromIDs($params, $ids, $key); + $errors = CRM_Contact_BAO_Relationship::checkValidRelationship($contactFields, $ids, $key); + if ($errors) { + $invalid++; + continue; } - $relationshipIds = []; - foreach ($params['contact_check'] as $key => $value) { - // 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 - // step 3: if valid relationship then add the relation and keep the count - - // step 1 - $contactFields = CRM_Contact_BAO_Relationship::setContactABFromIDs($params, $ids, $key); - $errors = CRM_Contact_BAO_Relationship::checkValidRelationship($contactFields, $ids, $key); - if ($errors) { - $invalid++; - continue; - } - - //CRM-16978:check duplicate relationship as per case id. - if ($caseId = CRM_Utils_Array::value('case_id', $params)) { - $contactFields['case_id'] = $caseId; - } - if ( - CRM_Contact_BAO_Relationship::checkDuplicateRelationship( - $contactFields, - CRM_Utils_Array::value('contact', $ids), - // step 2 - $key - ) - ) { - $duplicate++; - continue; - } - $singleInstanceParams = array_merge($params, $contactFields); - $relationship = CRM_Contact_BAO_Relationship::add($singleInstanceParams); - $relationshipIds[] = $relationship->id; - $relationships[$relationship->id] = $relationship; - $valid++; + //CRM-16978:check duplicate relationship as per case id. + if ($caseId = CRM_Utils_Array::value('case_id', $params)) { + $contactFields['case_id'] = $caseId; } - // editing the relationship + if ( + CRM_Contact_BAO_Relationship::checkDuplicateRelationship( + $contactFields, + CRM_Utils_Array::value('contact', $ids), + // step 2 + $key + ) + ) { + $duplicate++; + continue; + } + + $singleInstanceParams = array_merge($params, $contactFields); + $relationship = CRM_Contact_BAO_Relationship::add($singleInstanceParams); + $relationshipIds[] = $relationship->id; + $relationships[$relationship->id] = $relationship; + $valid++; } // do not add to recent items for import, CRM-4399 -- 2.25.1