From b815ff6b8ed7a1ae7f99c8da87dd26fad987ae5a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sun, 25 Jun 2023 23:57:21 -0700 Subject: [PATCH] dev/core#4317 Fix import issue when civicrm_custom_group.name ends in _ --- CRM/Contribute/Import/Form/MapField.php | 4 ++++ CRM/Import/Forms.php | 3 +++ CRM/Import/Parser.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 5e73a7cd30..dbd9899a0b 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -104,6 +104,10 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { } // Swap out dots for double underscores so as not to break the quick form js. // We swap this back on postProcess. + // Arg - we need to swap out _. first as it seems some groups end in a trailing underscore, + // which is indistinguishable to convert back - ie ___ could be _. or ._. + // https://lab.civicrm.org/dev/core/-/issues/4317#note_91322 + $name = str_replace('_.', '~~', $name); $name = str_replace('.', '__', $name); if (($field['entity'] ?? '') === 'Contact' && $this->isFilterContactFields() && empty($field['match_rule'])) { // Filter out metadata that is intended for create & update - this is not available in the quick-form diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index 31df4826e3..41e5654728 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -740,6 +740,9 @@ class CRM_Import_Forms extends CRM_Core_Form { } // Swap out dots for double underscores so as not to break the quick form js. // We swap this back on postProcess. + // Arg - we need to swap out _. first as it seems some groups end in a trailing underscore. + // https://lab.civicrm.org/dev/core/-/issues/4317#note_91322 + $name = str_replace('_.', '~~', $name); $name = str_replace('.', '__', $name); $return[$name] = $field['html']['label'] ?? $field['title']; } diff --git a/CRM/Import/Parser.php b/CRM/Import/Parser.php index 8386bcae81..359070c426 100644 --- a/CRM/Import/Parser.php +++ b/CRM/Import/Parser.php @@ -1696,6 +1696,9 @@ abstract class CRM_Import_Parser implements UserJobInterface { $fieldMap = $this->getOddlyMappedMetadataFields(); $fieldMapName = empty($fieldMap[$fieldName]) ? $fieldName : $fieldMap[$fieldName]; $fieldMapName = str_replace('__', '.', $fieldMapName); + // See https://lab.civicrm.org/dev/core/-/issues/4317#note_91322 - a further hack for quickform not + // handling dots in field names. One day we will get rid of the Quick form screen... + $fieldMapName = str_replace('~~', '_.', $fieldMapName); // This whole business of only loading metadata for one type when we actually need it for all is ... dubious. if (empty($this->getImportableFieldsMetadata()[$fieldMapName])) { if ($loadOptions || !$limitToContactType) { -- 2.25.1