From 22aca6b7bdc8b0dad2605bf863e72a453ada4f92 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 11 Jan 2022 08:33:14 +1300 Subject: [PATCH] Remove & deprecate silly function This function just calls another function & it's slightly MORE complicted to call that then the function it calls - deprecate it.... --- CRM/Contact/BAO/Contact/Utils.php | 4 ++-- CRM/Contact/BAO/Relationship.php | 12 ++++++++---- .../Contact/BAO/ContactType/RelationshipTest.php | 13 +++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index d260768026..0248dfe2f7 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -339,8 +339,8 @@ WHERE id IN ( $idString ) // step 1 $contactFields = CRM_Contact_BAO_Relationship::setContactABFromIDs($params, $ids, $organizationID); - $errors = CRM_Contact_BAO_Relationship::checkValidRelationship($contactFields, $ids, $organizationID); - if ($errors) { + if (!CRM_Contact_BAO_Relationship::checkRelationshipType($contactFields['contact_id_a'], $contactFields['contact_id_b'], + $contactFields['relationship_type_id'])) { return [0, []]; } diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index cdc2903f1a..eccd4fb188 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -55,7 +55,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { throw new CRM_Core_Exception('Duplicate Relationship'); } $params = $extendedParams; - if (self::checkValidRelationship($params, $params, 0)) { + if (!CRM_Contact_BAO_Relationship::checkRelationshipType($params['contact_id_a'], $params['contact_id_b'], + $params['relationship_type_id'])) { throw new CRM_Core_Exception('Invalid Relationship'); } $relationship = self::add($params); @@ -182,8 +183,8 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { // step 1 $contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID); - $errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID); - if ($errors) { + if (!CRM_Contact_BAO_Relationship::checkRelationshipType($contactFields['contact_id_a'], $contactFields['contact_id_b'], + $contactFields['relationship_type_id'])) { return [0, 0]; } @@ -208,7 +209,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { $relationship = self::add($singleInstanceParams); // do not add to recent items for import, CRM-4399 - if (!(!empty($params['skipRecentView']))) { + if (empty($params['skipRecentView'])) { self::addRecent($params, $relationship); } @@ -840,10 +841,13 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * @param int $contactId * This is contact id for adding relationship. * + * @deprecated + * * @return string */ public static function checkValidRelationship($params, $ids, $contactId) { $errors = ''; + CRM_Core_Error::deprecatedFunctionWarning('no alternative'); // function to check if the relationship selected is correct // i.e. employer relationship can exit between Individual and Organization (not between Individual and Individual) if (!CRM_Contact_BAO_Relationship::checkRelationshipType($params['contact_id_a'], $params['contact_id_b'], diff --git a/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php b/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php index 7280901e47..e4ff5266d9 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactType/RelationshipTest.php @@ -147,14 +147,15 @@ DELETE FROM civicrm_contact_type } /** - * Methods create relationshipe within same contact type with valid data. - * success expected + * Methods create relationships within same contact type with valid data. + * + * Success expected */ - public function testRelationshipCreateWithinSameType() { + public function testRelationshipCreateWithinSameType(): void { //check for Individual to Parent $relTypeParams = [ - 'name_a_b' => 'indivToparent', - 'name_b_a' => 'parentToindiv', + 'name_a_b' => 'individualToParent', + 'name_b_a' => 'parentToIndividual', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'contact_sub_type_b' => $this->parent, @@ -166,7 +167,7 @@ DELETE FROM civicrm_contact_type 'contact_check' => [$this->indivi_parent => $this->indivi_parent], ]; $ids = ['contact' => $this->individual]; - list($valid) = CRM_Contact_BAO_Relationship::legacyCreateMultiple($params, $ids); + [$valid] = CRM_Contact_BAO_Relationship::legacyCreateMultiple($params, $ids); $this->assertEquals($valid, 1); } -- 2.25.1