From cc392771325846e67d40da0c9dd7c8a9566d2486 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 5 May 2022 10:34:21 +1200 Subject: [PATCH] Minor function simplification in private function The function does 2 different things depending on whether if finds a duplicate & having it in a sub-function doesn't make the parent class clearer.... --- CRM/Contact/BAO/Contact/Utils.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index fbeeea0c14..02fc76b69b 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -272,9 +272,21 @@ WHERE id IN ( $idString ) CRM_Core_Error::deprecatedWarning('attempting to create an employer with invalid contact types is deprecated'); return; } + $relationshipIds = []; // create employee of relationship - [$duplicate, $relationshipIds] - = self::legacyCreateMultiple($relationshipTypeID, $employerID, $contactID); + $duplicate = CRM_Contact_BAO_Relationship::checkDuplicateRelationship( + [ + 'contact_id_a' => $contactID, + 'contact_id_b' => $employerID, + 'relationship_type_id' => $relationshipTypeID, + ], + $contactID, + // step 2 + $employerID + ); + if (!$duplicate) { + $relationshipIds = self::legacyCreateMultiple($relationshipTypeID, $employerID, $contactID); + } // In case we change employer, clean previous employer related records. if (!$previousEmployerID && !$newContact) { @@ -332,7 +344,6 @@ WHERE id IN ( $idString ) * @param int $contactID * * @return array - * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ private static function legacyCreateMultiple(int $relationshipTypeID, int $organizationID, int $contactID): array { @@ -355,24 +366,13 @@ WHERE id IN ( $idString ) 'relationship_type_id' => $relationshipTypeID, ]; - if ( - CRM_Contact_BAO_Relationship::checkDuplicateRelationship( - $contactFields, - $contactID, - // step 2 - $organizationID - ) - ) { - return [1, []]; - } - $singleInstanceParams = array_merge($params, $contactFields); $relationship = CRM_Contact_BAO_Relationship::add($singleInstanceParams); $relationshipIds[] = $relationship->id; CRM_Contact_BAO_Relationship::addRecent($params, $relationship); - return [0, $relationshipIds]; + return $relationshipIds; } /** -- 2.25.1