Skip to content

Commit

Permalink
Merge pull request #23737 from eileenmcnaughton/import_up_multi
Browse files Browse the repository at this point in the history
Add upgrade for label to name conversion in `civicrm_mapping_field` for multiple custom imports
  • Loading branch information
colemanw authored Jun 9, 2022
2 parents a56a8ca + 5d0287e commit 8720f08
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFiftyOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,30 @@ public static function convertMappingFieldLabelsToNames(): bool {
}
}

// Multiple custom
$mappings = MappingField::get(FALSE)
->setSelect(['id', 'name'])
->addWhere('mapping_id.mapping_type_id:name', '=', 'Import Multi value custom data')
->execute();
$allFields = civicrm_api3('custom_field', 'get', ['custom_group_id.is_multiple' => TRUE, 'return' => ['label', 'custom_group_id.title']])['values'];
$fieldMap = [];
foreach ($allFields as $field) {
$label = $field['label'] . ' :: ' . $field['custom_group_id.title'];
$fieldMap[$label] = 'custom_' . $field['id'];
}

$fieldMap[ts('- do not import -')] = 'do_not_import';
$fieldMap[ts('Contact ID')] = 'contact_id';
$fieldMap[ts('External Identifier')] = 'external_identifier';
foreach ($mappings as $mapping) {
if (!empty($fieldMap[$mapping['name']])) {
MappingField::update(FALSE)
->addWhere('id', '=', $mapping['id'])
->addValue('name', $fieldMap[$mapping['name']])
->execute();
}
}

return TRUE;
}

Expand Down

0 comments on commit 8720f08

Please sign in to comment.