From 6c9ed1e4fb085b84a03d04d05bd5561985e8a44c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 12 Jan 2022 18:06:56 +1300 Subject: [PATCH] Remove always-true-if We just ensured organization is numeric so .. it is --- CRM/Contact/BAO/Contact/Utils.php | 57 +++++++++++++++---------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 77b9437864..27e5446b28 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -270,40 +270,37 @@ WHERE id IN ( $idString ) ])->execute()->first()['id']; } - if (is_numeric($organization)) { + // get the relationship type id of "Employee of" + $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b'); + if (!$relTypeId) { + throw new CRM_Core_Exception(ts("You seem to have deleted the relationship type 'Employee of'")); + } - // get the relationship type id of "Employee of" - $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b'); - if (!$relTypeId) { - throw new CRM_Core_Exception(ts("You seem to have deleted the relationship type 'Employee of'")); - } + // create employee of relationship + [$duplicate, $relationshipIds] + = self::legacyCreateMultiple($relTypeId, $organization, $contactID); - // create employee of relationship - [$duplicate, $relationshipIds] - = self::legacyCreateMultiple($relTypeId, $organization, $contactID); + // In case we change employer, clean previous employer related records. + if (!$previousEmployerID && !$newContact) { + $previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'); + } + if ($previousEmployerID && + $previousEmployerID != $organization + ) { + self::clearCurrentEmployer($contactID, $previousEmployerID); + } - // In case we change employer, clean previous employer related records. - if (!$previousEmployerID && !$newContact) { - $previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'); - } - if ($previousEmployerID && - $previousEmployerID != $organization - ) { - self::clearCurrentEmployer($contactID, $previousEmployerID); - } + // set current employer + self::setCurrentEmployer([$contactID => $organization]); - // set current employer - self::setCurrentEmployer([$contactID => $organization]); - - $relationshipParams = [ - 'relationship_ids' => $relationshipIds, - 'is_active' => 1, - 'contact_check' => [$organization => TRUE], - 'relationship_type_id' => $relTypeId . '_a_b', - ]; - // Handle related memberships. CRM-3792 - self::currentEmployerRelatedMembership($contactID, $organization, $relationshipParams, $duplicate, $previousEmployerID); - } + $relationshipParams = [ + 'relationship_ids' => $relationshipIds, + 'is_active' => 1, + 'contact_check' => [$organization => TRUE], + 'relationship_type_id' => $relTypeId . '_a_b', + ]; + // Handle related memberships. CRM-3792 + self::currentEmployerRelatedMembership($contactID, $organization, $relationshipParams, $duplicate, $previousEmployerID); } /** -- 2.25.1