From 59812fd0c97492859059b0b208a5adbf007e1252 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 29 Mar 2017 10:40:15 +1300 Subject: [PATCH] CRM-20328 remove call to duplicated code sequence. On looking is actually getting an ID so I renamed it --- CRM/Core/BAO/UFGroup.php | 22 ---------------------- CRM/Friend/BAO/Friend.php | 18 ++++++++---------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index dec593b406..a763b283dc 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -951,28 +951,6 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { return ''; } - /** - * Searches for a contact in the db with similar attributes. - * - * @param array $params - * The list of values to be used in the where clause. - * @param int $id - * The current contact id (hence excluded from matching). - * @param string $contactType - * - * @return int|null - * contact_id if found, null otherwise - */ - public static function findContact(&$params, $id = NULL, $contactType = 'Individual') { - $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, $contactType, 'Supervised', array($id), CRM_Utils_Array::value('check_permission', $params, TRUE)); - if (!empty($ids)) { - return implode(',', $ids); - } - else { - return NULL; - } - } - /** * Given a contact id and a field set, return the values from the db. * diff --git a/CRM/Friend/BAO/Friend.php b/CRM/Friend/BAO/Friend.php index ce96cc98ce..acd6ca2a48 100644 --- a/CRM/Friend/BAO/Friend.php +++ b/CRM/Friend/BAO/Friend.php @@ -54,11 +54,10 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend { * @param array $params * (reference ) an assoc array of name/value pairs. * - * @return CRM_Friend_BAO_Friend + * @return int */ public static function add(&$params) { - $friend = CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray); - return $friend; + return CRM_Contact_BAO_Contact::createProfileContact($params, CRM_Core_DAO::$_nullArray); } /** @@ -143,27 +142,26 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend { //create contact only if it does not exits in db $value['email'] = $value['email-Primary']; - $value['check_permission'] = FALSE; - $contact = CRM_Core_BAO_UFGroup::findContact($value, NULL, 'Individual'); + $contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($value, 'Individual', 'Supervised', array(), FALSE); - if (!$contact) { - $contact = self::add($value); + if (!$contactID) { + $contactID = self::add($value); } // attempt to save activity targets $targetParams = array( 'activity_id' => $activity->id, - 'contact_id' => $contact, + 'contact_id' => $contactID, 'record_type_id' => $targetID, ); // See if it already exists $activityContact = new CRM_Activity_DAO_ActivityContact(); $activityContact->activity_id = $activity->id; - $activityContact->contact_id = $contact; + $activityContact->contact_id = $contactID; $activityContact->find(TRUE); if (empty($activityContact->id)) { - $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams); + CRM_Activity_BAO_ActivityContact::create($targetParams); } } -- 2.25.1