Skip to content

Commit

Permalink
Merge pull request #23444 from eileenmcnaughton/import_get
Browse files Browse the repository at this point in the history
[REF] [Import] Minor code cleanup
  • Loading branch information
colemanw authored May 13, 2022
2 parents 7ff5a93 + f5d4a76 commit 395af92
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2410,42 +2410,17 @@ private function getParams(array $values): array {
$relatedContactType = $this->getRelatedContactType($mappedField['relationship_type_id'], $mappedField['relationship_direction']);
$relatedContactLocationTypeID = $relatedContactKey ? $mappedField['location_type_id'] : NULL;
$relatedContactWebsiteTypeID = $relatedContactKey ? $mappedField['website_type_id'] : NULL;
$relatedContactIMProviderID = $relatedContactKey ? $mappedField['im_provider_id'] : NULL;
$relatedContactIMProviderID = $relatedContactKey ? $mappedField['provider_id'] : NULL;
$relatedContactPhoneTypeID = $relatedContactKey ? $mappedField['phone_type_id'] : NULL;

$locationTypeID = $relatedContactKey ? NULL : $mappedField['location_type_id'];
$phoneTypeID = $relatedContactKey ? NULL : $mappedField['phone_type_id'];
$imProviderID = $relatedContactKey ? NULL : $mappedField['im_provider_id'];
$websiteTypeID = $relatedContactKey ? NULL : $mappedField['website_type_id'];

$locationFields = ['location_type_id', 'phone_type_id', 'provider_id', 'website_type_id'];
$value = array_filter(array_intersect_key($mappedField, array_fill_keys($locationFields, 1)));
if (!$relatedContactKey) {
if (isset($locationTypeID)) {
if (!empty($value)) {
if (!isset($params[$fieldName])) {
$params[$fieldName] = [];
}

$value = [
$fieldName => $importedValue,
'location_type_id' => $locationTypeID,
];

if (isset($phoneTypeID)) {
$value['phone_type_id'] = $phoneTypeID;
}

// get IM service Provider type id
if (isset($imProviderID)) {
$value['provider_id'] = $imProviderID;
}

$params[$fieldName][] = $value;
}
elseif (isset($websiteTypeID)) {
$value = [
$fieldName => $importedValue,
'website_type_id' => $websiteTypeID,
];

$value[$fieldName] = $importedValue;
$params[$fieldName][] = $value;
}

Expand Down Expand Up @@ -3185,6 +3160,7 @@ public function validateValues(array $values): void {
*
* This is the same format as saved in civicrm_mapping_field except
* that location_type_id = 'Primary' rather than empty where relevant.
* Also 'im_provider_id' is mapped to the 'real' field name 'provider_id'
*
* @return array
* @throws \API_Exception
Expand All @@ -3196,8 +3172,12 @@ protected function getFieldMappings(): array {
if (!$mappedField['location_type_id'] && !empty($this->importableFieldsMetadata[$mappedField['name']]['hasLocationType'])) {
$mappedField['location_type_id'] = 'Primary';
}
// Just for clarity since 0 is a pseudovalue
// Just for clarity since 0 is a pseudo-value
unset($mappedField['mapping_id']);
// Annoyingly the civicrm_mapping_field name for this differs from civicrm_im.
// Test cover in `CRM_Contact_Import_Parser_ContactTest::testMapFields`
$mappedField['provider_id'] = $mappedField['im_provider_id'];
unset($mappedField['im_provider_id']);
$mappedFields[] = $mappedField;
}
return $mappedFields;
Expand Down

0 comments on commit 395af92

Please sign in to comment.