Skip to content

Commit

Permalink
Fix some a couple of places where form variables were passed, remove …
Browse files Browse the repository at this point in the history
…a couple more things
  • Loading branch information
eileenmcnaughton committed Jun 9, 2022
1 parent 112e13f commit cdbe53f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 86 deletions.
23 changes: 9 additions & 14 deletions CRM/Contribute/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) . '<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)
)
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -155,7 +150,7 @@ public function buildQuickForm() {
}
$sel1 = $this->_mapperFields;

if (!$this->get('onDuplicate')) {
if (!$this->isUpdateExisting()) {
unset($sel1['id']);
unset($sel1['contribution_id']);
}
Expand All @@ -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];
Expand Down Expand Up @@ -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.'));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) &&
Expand Down
36 changes: 0 additions & 36 deletions CRM/Contribute/Import/Form/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 8 additions & 1 deletion CRM/Import/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ protected function getParser() {
*
* @return array
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function getMappedFieldLabels(): array {
$mapper = [];
Expand Down Expand Up @@ -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;
}

}
35 changes: 0 additions & 35 deletions tests/phpunit/CRM/Custom/Import/Parser/ApiTest.php

This file was deleted.

0 comments on commit cdbe53f

Please sign in to comment.