}
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]) . '<br />';
}
- 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)
)
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',
$highlightedFields[] = $key;
}
}
- elseif ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
+ elseif ($this->isSkipExisting()) {
unset($this->_mapperFields['contribution_id']);
$highlightedFieldsArray = [
'contribution_contact_id',
}
$sel1 = $this->_mapperFields;
- if (!$this->get('onDuplicate')) {
+ if (!$this->isUpdateExisting()) {
unset($sel1['id']);
unset($sel1['contribution_id']);
}
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];
$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.'));
}
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) {
$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) &&
*/
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
*/
+++ /dev/null
-<?php
-/**
- * @file
- * File for the CRM_Contribute_Import_Parser_ContributionTest class.
- */
-
-/**
- * Test Contribution import parser.
- *
- * @package CiviCRM
- * @group headless
- */
-class CRM_Custom_Import_Parser_ApiTest extends CiviUnitTestCase {
-
- use CRMTraits_Custom_CustomDataTrait;
- use CRMTraits_Import_ParserTrait;
-
- /**
- * Test the full form-flow import.
- */
- public function testImport(): void {
- $this->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']);
- }
-
-}