CRM-20328 remove call to duplicated code sequence.
authoreileen <emcnaughton@wikimedia.org>
Tue, 28 Mar 2017 21:40:15 +0000 (10:40 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 12 Apr 2017 10:14:26 +0000 (22:14 +1200)
On looking  is actually getting an ID so I renamed it

CRM/Core/BAO/UFGroup.php
CRM/Friend/BAO/Friend.php

index dec593b406cd242be6608dd8ca4a54486f97d162..a763b283dc42473ce359c927f874845765b94151 100644 (file)
@@ -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.
    *
index ce96cc98cecbdbd6b4bc5d876d32c54ae632454b..acd6ca2a48c935a28d68fd9a7fdfa15d9ae41ccb 100644 (file)
@@ -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);
       }
     }