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

[REF] [Import] Minor code cleanup #23444

Merged
merged 1 commit into from
May 13, 2022
Merged
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
42 changes: 11 additions & 31 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2451,42 +2451,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 @@ -3249,6 +3224,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 @@ -3260,8 +3236,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