Skip to content

Commit

Permalink
Merge pull request #19270 from eileenmcnaughton/import
Browse files Browse the repository at this point in the history
Fold deprecated function into the only function that calls it
  • Loading branch information
seamuslee001 authored Dec 24, 2020
2 parents 46876bd + bd7c621 commit e93f0b4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 79 deletions.
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

0 comments on commit e93f0b4

Please sign in to comment.