diff --git a/CRM/Contribute/Import/Form/MapField.php b/CRM/Contribute/Import/Form/MapField.php index 9026f66c5c6c..ccfcdff34317 100644 --- a/CRM/Contribute/Import/Form/MapField.php +++ b/CRM/Contribute/Import/Form/MapField.php @@ -48,11 +48,11 @@ protected static function checkRequiredFields($self, string $contactORContributi } if ($field == $contactORContributionId) { if (!($weightSum >= $threshold || in_array('external_identifier', $importKeys)) && - $self->_onDuplicate != CRM_Import_Parser::DUPLICATE_UPDATE + !$self->isUpdateExisting() ) { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . " $fieldMessage " . ts('(Sum of all weights should be greater than or equal to threshold: %1).', [1 => $threshold]) . '
'; } - elseif ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE && + elseif ($self->isUpdateExisting() && !(in_array('invoice_id', $importKeys) || in_array('trxn_id', $importKeys) || in_array('contribution_id', $importKeys) ) @@ -74,15 +74,10 @@ protected static function checkRequiredFields($self, string $contactORContributi public function preProcess() { parent::preProcess(); - $this->_columnCount = $this->get('columnCount'); - $skipColumnHeader = $this->getSubmittedValue('skipColumnHeader'); - $this->_onDuplicate = $this->getSubmittedValue('onDuplicate'); - $this->assign('skipColumnHeader', $skipColumnHeader); - $highlightedFields = ['financial_type_id', 'total_amount']; //CRM-2219 removing other required fields since for updation only //invoice id or trxn id or contribution id is required. - if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { + if ($this->isUpdateExisting()) { $remove = [ 'contribution_contact_id', 'email', @@ -104,7 +99,7 @@ public function preProcess() { $highlightedFields[] = $key; } } - elseif ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { + elseif ($this->isSkipExisting()) { unset($this->_mapperFields['contribution_id']); $highlightedFieldsArray = [ 'contribution_contact_id', @@ -155,7 +150,7 @@ public function buildQuickForm() { } $sel1 = $this->_mapperFields; - if (!$this->get('onDuplicate')) { + if (!$this->isUpdateExisting()) { unset($sel1['id']); unset($sel1['contribution_id']); } @@ -178,7 +173,7 @@ public function buildQuickForm() { foreach ($columnHeaders as $i => $columnHeader) { $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); $jsSet = FALSE; - if ($this->get('savedMapping')) { + if ($this->getSubmittedValue('savedMapping')) { [$mappingName, $mappingContactType] = CRM_Core_BAO_Mapping::getMappingFields($savedMappingID); $mappingName = $mappingName[1]; @@ -265,7 +260,7 @@ public function buildQuickForm() { $warning++; } } - if ($warning != 0 && $this->get('savedMapping')) { + 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.')); } @@ -294,7 +289,7 @@ public function buildQuickForm() { public static function formRule($fields, $files, $self) { $errors = []; $fieldMessage = NULL; - $contactORContributionId = $self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE ? 'contribution_id' : 'contribution_contact_id'; + $contactORContributionId = $self->isUpdateExisting() ? 'contribution_id' : 'contribution_contact_id'; if (!array_key_exists('savedMapping', $fields)) { $importKeys = []; foreach ($fields['mapper'] as $mapperPart) { @@ -327,7 +322,7 @@ public static function formRule($fields, $files, $self) { $errors = self::checkRequiredFields($self, $contactORContributionId, $importKeys, $errors, $weightSum, $threshold, $fieldMessage); //at least one field should be mapped during update. - if ($self->_onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { + if ($self->isUpdateExisting()) { $atleastOne = FALSE; foreach ($self->_mapperFields as $key => $field) { if (in_array($key, $importKeys) && diff --git a/CRM/Contribute/Import/Form/Preview.php b/CRM/Contribute/Import/Form/Preview.php index 3bfc113f7b4a..85d9bcdf3c1e 100644 --- a/CRM/Contribute/Import/Form/Preview.php +++ b/CRM/Contribute/Import/Form/Preview.php @@ -20,42 +20,6 @@ */ class CRM_Contribute_Import_Form_Preview extends CRM_Import_Form_Preview { - /** - * Set variables up before form is built. - */ - public function preProcess() { - parent::preProcess(); - $invalidRowCount = $this->getRowCount(CRM_Import_Parser::VALID); - - $downloadURL = ''; - if ($invalidRowCount) { - $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution'; - $downloadURL = CRM_Utils_System::url('civicrm/export', $urlParams); - } - - $this->setStatusUrl(); - $this->assign('downloadErrorRecordsUrl', $downloadURL); - } - - /** - * Get the mapped fields as an array of labels. - * - * e.g - * ['First Name', 'Employee Of - First Name', 'Home - Street Address'] - * - * @return array - * @throws \API_Exception - * @throws \CRM_Core_Exception - */ - protected function getMappedFieldLabels(): array { - $mapper = []; - $parser = $this->getParser(); - foreach ($this->getSubmittedValue('mapper') as $columnNumber => $mappedField) { - $mapper[$columnNumber] = $parser->getMappedFieldLabel($parser->getMappingFieldFromMapperInput($mappedField, 0, $columnNumber)); - } - return $mapper; - } - /** * @return \CRM_Contribute_Import_Parser_Contribution */ diff --git a/CRM/Import/Forms.php b/CRM/Import/Forms.php index 571ef0f87e8d..0b37ea76b221 100644 --- a/CRM/Import/Forms.php +++ b/CRM/Import/Forms.php @@ -575,7 +575,6 @@ protected function getParser() { * * @return array * @throws \API_Exception - * @throws \CRM_Core_Exception */ protected function getMappedFieldLabels(): array { $mapper = []; @@ -643,4 +642,12 @@ protected function isUpdateExisting(): bool { return ((int) $this->getSubmittedValue('onDuplicate')) === CRM_Import_Parser::DUPLICATE_UPDATE; } + /** + * Has the user chosen to update existing records. + * @return bool + */ + protected function isSkipExisting(): bool { + return ((int) $this->getSubmittedValue('onDuplicate')) === CRM_Import_Parser::DUPLICATE_SKIP; + } + } diff --git a/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php b/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php deleted file mode 100644 index f051157b0175..000000000000 --- a/tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php +++ /dev/null @@ -1,35 +0,0 @@ -importCSV('contributions.csv', [ - ['name' => 'first_name'], - ['name' => 'total_amount'], - ['name' => 'receive_date'], - ['name' => 'financial_type_id'], - ['name' => 'email'], - ]); - $dataSource = new CRM_Import_DataSource_CSV($this->userJobID); - $row = $dataSource->getRow(); - $this->assertEquals('ERROR', $row['_status']); - $this->assertEquals('No matching Contact found for (mum@example.com )', $row['_status_message']); - } - -}