Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold deprecated function into the only function that calls it #19270

Merged
merged 1 commit into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
77 changes: 0 additions & 77 deletions CRM/Utils/DeprecatedUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down