From: Eileen McNaughton Date: Sun, 12 Jun 2022 00:21:18 +0000 (+1200) Subject: Fix import regression - contribution import borks on do_not_import X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=66673bfe41af8493dd48d6a92b0cd08929571b87;p=civicrm-core.git Fix import regression - contribution import borks on do_not_import --- diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index ccfcdff343..419d91dd30 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -143,6 +143,7 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $dataPatterns = $this->getDataPatterns(); $mapperKeysValues = $this->getSubmittedValue('mapper'); $columnHeaders = $this->getColumnHeaders(); + $fieldMappings = $this->getFieldMappings(); /* Initialize all field usages to false */ foreach ($mapperKeys as $key) { @@ -174,12 +175,13 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); $jsSet = FALSE; if ($this->getSubmittedValue('savedMapping')) { + // $mappingContactType is not really a contact type - the data has been mangled + // into that field - see https://lab.civicrm.org/dev/core/-/issues/654 [$mappingName, $mappingContactType] = CRM_Core_BAO_Mapping::getMappingFields($savedMappingID); - - $mappingName = $mappingName[1]; + $fieldMapping = $fieldMappings[$i] ?? NULL; $mappingContactType = $mappingContactType[1]; - if (isset($mappingName[$i])) { - if ($mappingName[$i] != ts('do_not_import')) { + if (isset($fieldMappings[$i])) { + if ($fieldMapping['name'] !== ts('do_not_import')) { $softField = $mappingContactType[$i] ?? ''; if (!$softField) { @@ -189,7 +191,7 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { $js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n"; $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; $defaults["mapper[$i]"] = [ - $mappingName[$i], + $fieldMapping['name'], $softField, // Since the soft credit type id is not stored we can't load it here. '', @@ -253,22 +255,6 @@ class CRM_Contribute_Import_Form_MapField extends CRM_Import_Form_MapField { } $js .= "\n"; $this->assign('initHideBoxes', $js); - - //set warning if mismatch in more than - if (isset($mappingName)) { - if (($this->_columnCount != count($mappingName))) { - $warning++; - } - } - if ($warning != 0 && $this->getSubmittedValue('savedMapping')) { - $session = CRM_Core_Session::singleton(); - $session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.')); - } - else { - $session = CRM_Core_Session::singleton(); - $session->setStatus(NULL); - } - $this->setDefaults($defaults); $this->addFormButtons(); diff --git a/CRM/Contribute/Import/Parser/Contribution.php b/CRM/Contribute/Import/Parser/Contribution.php index 91095018a4..7784c9d955 100644 --- a/CRM/Contribute/Import/Parser/Contribution.php +++ b/CRM/Contribute/Import/Parser/Contribution.php @@ -160,7 +160,7 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { public function getMappedRow(array $values): array { $params = []; foreach ($this->getFieldMappings() as $i => $mappedField) { - if ($mappedField['name'] === 'do_not_import' || $mappedField['name'] === NULL) { + if ($mappedField['name'] === 'do_not_import' || !$mappedField['name']) { continue; } if (!empty($mappedField['soft_credit_match_field'])) { @@ -223,6 +223,7 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { 'softCredit' => TRUE, 'headerPattern' => '/Soft Credit/i', 'options' => FALSE, + 'type' => CRM_Utils_Type::T_STRING, ], ] ); @@ -926,6 +927,9 @@ class CRM_Contribute_Import_Parser_Contribution extends CRM_Import_Parser { if (empty($this->importableFieldsMetadata)) { $this->setFieldMetadata(); } + if ($mappedField['name'] === '') { + return ''; + } $title = []; $title[] = $this->getFieldMetadata($mappedField['name'])['title']; if ($mappedField['soft_credit_match_field']) {