From bd7c62197db358d23bb421c3cf6f70cf4f555f54 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 24 Dec 2020 10:12:08 +1300 Subject: [PATCH] Fold deprecated function into the only function that calls it --- CRM/Import/Parser.php | 67 +++++++++++++++++++++++++++++- CRM/Utils/DeprecatedUtils.php | 77 ----------------------------------- 2 files changed, 65 insertions(+), 79 deletions(-) diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 05a22b58bba7..60ba7e8d5658 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -527,8 +527,71 @@ protected function checkContactDuplicate(&$formatValues) { $formatValues['contact_type'] = $formatValues['contact_type'] ?? $this->_contactType; $formatValues['version'] = 3; require_once 'CRM/Utils/DeprecatedUtils.php'; - $error = _civicrm_api3_deprecated_check_contact_dedupe($formatValues); - return $error; + $params = $formatValues; + static $cIndieFields = NULL; + static $defaultLocationId = NULL; + + $contactType = $params['contact_type']; + if ($cIndieFields == NULL) { + $cTempIndieFields = CRM_Contact_BAO_Contact::importableFields($contactType); + $cIndieFields = $cTempIndieFields; + + $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); + + // set the value to default location id else set to 1 + if (!$defaultLocationId = (int) $defaultLocation->id) { + $defaultLocationId = 1; + } + } + + $locationFields = CRM_Contact_BAO_Query::$_locationSpecificFields; + + $contactFormatted = []; + foreach ($params as $key => $field) { + if ($field == NULL || $field === '') { + continue; + } + // CRM-17040, Considering only primary contact when importing contributions. So contribution inserts into primary contact + // instead of soft credit contact. + if (is_array($field) && $key != "soft_credit") { + foreach ($field as $value) { + $break = FALSE; + if (is_array($value)) { + foreach ($value as $name => $testForEmpty) { + if ($name !== 'phone_type' && + ($testForEmpty === '' || $testForEmpty == NULL) + ) { + $break = TRUE; + break; + } + } + } + else { + $break = TRUE; + } + if (!$break) { + _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted); + } + } + continue; + } + + $value = [$key => $field]; + + // check if location related field, then we need to add primary location type + if (in_array($key, $locationFields)) { + $value['location_type_id'] = $defaultLocationId; + } + elseif (array_key_exists($key, $cIndieFields)) { + $value['contact_type'] = $contactType; + } + + _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted); + } + + $contactFormatted['contact_type'] = $contactType; + + return _civicrm_api3_deprecated_duplicate_formatted_contact($contactFormatted); } /** diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 386ba2054f8a..d0a4e1512b8e 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -24,83 +24,6 @@ require_once 'api/v3/utils.php'; -/** - * Check duplicate contacts based on de-dupe parameters. - * - * @param array $params - * - * @return array - */ -function _civicrm_api3_deprecated_check_contact_dedupe($params) { - static $cIndieFields = NULL; - static $defaultLocationId = NULL; - - $contactType = $params['contact_type']; - if ($cIndieFields == NULL) { - require_once 'CRM/Contact/BAO/Contact.php'; - $cTempIndieFields = CRM_Contact_BAO_Contact::importableFields($contactType); - $cIndieFields = $cTempIndieFields; - - require_once "CRM/Core/BAO/LocationType.php"; - $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); - - // set the value to default location id else set to 1 - if (!$defaultLocationId = (int) $defaultLocation->id) { - $defaultLocationId = 1; - } - } - - require_once 'CRM/Contact/BAO/Query.php'; - $locationFields = CRM_Contact_BAO_Query::$_locationSpecificFields; - - $contactFormatted = []; - foreach ($params as $key => $field) { - if ($field == NULL || $field === '') { - continue; - } - // CRM-17040, Considering only primary contact when importing contributions. So contribution inserts into primary contact - // instead of soft credit contact. - if (is_array($field) && $key != "soft_credit") { - foreach ($field as $value) { - $break = FALSE; - if (is_array($value)) { - foreach ($value as $name => $testForEmpty) { - if ($name !== 'phone_type' && - ($testForEmpty === '' || $testForEmpty == NULL) - ) { - $break = TRUE; - break; - } - } - } - else { - $break = TRUE; - } - if (!$break) { - _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted); - } - } - continue; - } - - $value = [$key => $field]; - - // check if location related field, then we need to add primary location type - if (in_array($key, $locationFields)) { - $value['location_type_id'] = $defaultLocationId; - } - elseif (array_key_exists($key, $cIndieFields)) { - $value['contact_type'] = $contactType; - } - - _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted); - } - - $contactFormatted['contact_type'] = $contactType; - - return _civicrm_api3_deprecated_duplicate_formatted_contact($contactFormatted); -} - /** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If