From 7f90383ec296e6c91455faedee83a669a27ec180 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 27 Mar 2017 16:52:38 +1300 Subject: [PATCH] Towards CRM-20155 remove duplicate code, towards taking extension from core --- CRM/Campaign/Form/Petition/Signature.php | 12 +----------- CRM/Contact/BAO/Contact/Utils.php | 6 +----- CRM/Contact/Form/Contact.php | 3 +-- CRM/Contribute/BAO/ContributionSoft.php | 12 ++++++++---- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/CRM/Campaign/Form/Petition/Signature.php b/CRM/Campaign/Form/Petition/Signature.php index 27efde46e6..f144dc4076 100644 --- a/CRM/Campaign/Form/Petition/Signature.php +++ b/CRM/Campaign/Form/Petition/Signature.php @@ -371,17 +371,7 @@ class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form { $ids[0] = $this->_contactId; } else { - // dupeCheck - check if contact record already exists - // code modified from api/v2/Contact.php-function civicrm_contact_check_params() - $params['contact_type'] = $this->_ctype; - //TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working - // ignore soft deleted contacts - //$params['is_deleted'] = 0; - $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']); - $dedupeParams['check_permission'] = ''; - - //dupesByParams($params, $ctype, $level = 'Unsupervised', $except = array()) - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']); + $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, $this->_ctype, 'Unsupervised', array(), FALSE); } $petition_params['id'] = $this->_surveyId; diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 7f8b2f2f7d..9cbb44d53b 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -284,11 +284,7 @@ UNION public static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL, $newContact = FALSE) { //if organization name is passed. CRM-15368,CRM-15547 if ($organization && !is_numeric($organization)) { - $organizationParams['organization_name'] = $organization; - $dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization'); - - $dedupeParams['check_permission'] = FALSE; - $dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Unsupervised'); + $dupeIDs = CRM_Contact_BAO_Contact::getDuplicateContacts(array('organization_name' => $organization), 'Organization', 'Unsupervised', array(), FALSE); if (is_array($dupeIDs) && !empty($dupeIDs)) { // we should create relationship only w/ first org CRM-4193 diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 201e1a0cc0..0a1c077b62 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -1130,8 +1130,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { // if this is a forced save, ignore find duplicate rule if (empty($fields['_qf_Contact_upload_duplicate'])) { - $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, $contactType); - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $contactType, 'Supervised', array($contactID)); + $ids = CRM_Contact_BAO_Contact::getDuplicateContacts($fields, $contactType, 'Supervised', array($contactID)); if ($ids) { $contactLinks = CRM_Contact_BAO_Contact_Utils::formatContactIDSToLinks($ids, TRUE, TRUE, $contactID); diff --git a/CRM/Contribute/BAO/ContributionSoft.php b/CRM/Contribute/BAO/ContributionSoft.php index a60284eae2..3ba3ee7d2a 100644 --- a/CRM/Contribute/BAO/ContributionSoft.php +++ b/CRM/Contribute/BAO/ContributionSoft.php @@ -150,18 +150,22 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio if (!empty($form->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) { $honorId = NULL; + // @todo fix use of deprecated function. $contributionSoftParams['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'pcp', 'name'); //check if there is any duplicate contact - $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']); - $dedupeParams = CRM_Dedupe_Finder::formatParams($params['honor'], $profileContactType); - $dedupeParams['check_permission'] = FALSE; // honoree should never be the donor $exceptKeys = array( 'contactID' => 0, 'onbehalf_contact_id' => 0, ); $except = array_values(array_intersect_key($params, $exceptKeys)); - $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $profileContactType, 'Unsupervised', $except); + $ids = CRM_Contact_BAO_Contact::getDuplicateContacts( + $params['honor'], + CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']), + 'Unsupervised', + $except, + FALSE + ); if (count($ids)) { $honorId = CRM_Utils_Array::value(0, $ids); } -- 2.25.1