From 5d0287e34be4877652220fadeaedd4cb238349e5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 9 Jun 2022 15:49:03 +1200 Subject: [PATCH] Add upgrade for label to name conversion It wouldn't be that much more to go further & use the group.fieldname format - .... Add upgrade script to convert saved field mappings to use names --- CRM/Upgrade/Incremental/php/FiveFiftyOne.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CRM/Upgrade/Incremental/php/FiveFiftyOne.php b/CRM/Upgrade/Incremental/php/FiveFiftyOne.php index 3d1a83f16b53..4f440dfb01d1 100644 --- a/CRM/Upgrade/Incremental/php/FiveFiftyOne.php +++ b/CRM/Upgrade/Incremental/php/FiveFiftyOne.php @@ -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; }