From 58a65f77cb2d8381b0128bcdaf30fc33aa802124 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 8 Jun 2022 11:34:20 +1200 Subject: [PATCH] Switch contribution to use same error handling --- CRM/Contribute/Import/Form/Summary.php | 72 +------------------ CRM/Import/DataSource.php | 13 +++- CRM/Import/Form/Summary.php | 6 ++ .../Import/Parser/data/.~lock.pledge.csv# | 1 + ...ontributions_amount_validate.csv.error.log | 0 .../Contribute/Import/Parser/data/pledge.csv | 2 + .../Import/Parser/data/pledge.csv.error.log | 0 7 files changed, 20 insertions(+), 74 deletions(-) create mode 100644 tests/phpunit/CRM/Contribute/Import/Parser/data/.~lock.pledge.csv# create mode 100644 tests/phpunit/CRM/Contribute/Import/Parser/data/contributions_amount_validate.csv.error.log create mode 100644 tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv create mode 100644 tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv.error.log diff --git a/CRM/Contribute/Import/Form/Summary.php b/CRM/Contribute/Import/Form/Summary.php index 9bf6214f80..c1d5d06b6f 100644 --- a/CRM/Contribute/Import/Form/Summary.php +++ b/CRM/Contribute/Import/Form/Summary.php @@ -24,77 +24,7 @@ class CRM_Contribute_Import_Form_Summary extends CRM_Import_Form_Summary { * Set variables up before form is built. */ public function preProcess() { - // set the error message path to display - $this->assign('errorFile', $this->get('errorFile')); - - $totalRowCount = $this->get('totalRowCount'); - $this->set('totalRowCount', $totalRowCount); - - $invalidRowCount = $this->get('invalidRowCount'); - $invalidSoftCreditRowCount = $this->get('invalidSoftCreditRowCount'); - if ($invalidSoftCreditRowCount) { - $urlParams = 'type=' . CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution'; - $this->set('downloadSoftCreditErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); - } - $validSoftCreditRowCount = $this->get('validSoftCreditRowCount'); - $invalidPledgePaymentRowCount = $this->get('invalidPledgePaymentRowCount'); - if ($invalidPledgePaymentRowCount) { - $urlParams = 'type=' . CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR . '&parser=CRM_Contribute_Import_Parser_Contribution'; - $this->set('downloadPledgePaymentErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); - } - $validPledgePaymentRowCount = $this->get('validPledgePaymentRowCount'); - $duplicateRowCount = $this->get('duplicateRowCount'); - $onDuplicate = $this->get('onDuplicate'); - if ($duplicateRowCount > 0) { - $urlParams = 'type=' . CRM_Import_Parser::DUPLICATE . '&parser=CRM_Contribute_Import_Parser_Contribution'; - $this->set('downloadDuplicateRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); - } - else { - $duplicateRowCount = 0; - $this->set('duplicateRowCount', $duplicateRowCount); - } - - $this->assign('dupeError', FALSE); - - if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) { - $dupeActionString = ts('These records have been updated with the imported data.'); - } - elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) { - $dupeActionString = ts('These records have been filled in with the imported data.'); - } - else { - /* Skip by default */ - - $dupeActionString = ts('These records have not been imported.'); - - $this->assign('dupeError', TRUE); - - /* only subtract dupes from successful import if we're skipping */ - - $this->set('validRowCount', $totalRowCount - $invalidRowCount - - $duplicateRowCount - $invalidSoftCreditRowCount - $invalidPledgePaymentRowCount - ); - } - $this->assign('dupeActionString', $dupeActionString); - - $properties = [ - 'totalRowCount', - 'validRowCount', - 'invalidRowCount', - 'validSoftCreditRowCount', - 'invalidSoftCreditRowCount', - 'downloadErrorRecordsUrl', - 'duplicateRowCount', - 'downloadDuplicateRecordsUrl', - 'groupAdditions', - 'validPledgePaymentRowCount', - 'invalidPledgePaymentRowCount', - 'downloadPledgePaymentErrorRecordsUrl', - 'downloadSoftCreditErrorRecordsUrl', - ]; - foreach ($properties as $property) { - $this->assign($property, $this->get($property)); - } + parent::preProcess(); } } diff --git a/CRM/Import/DataSource.php b/CRM/Import/DataSource.php index 47bc3f6e1e..3b4ed98785 100644 --- a/CRM/Import/DataSource.php +++ b/CRM/Import/DataSource.php @@ -447,7 +447,10 @@ abstract class CRM_Import_DataSource { " . $this->getAdditionalTrackingFields() . " ADD COLUMN _status VARCHAR(32) DEFAULT 'NEW' NOT NULL, ADD COLUMN _status_message TEXT, - ADD COLUMN _id INT PRIMARY KEY NOT NULL AUTO_INCREMENT" + ADD COLUMN _id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, + ADD INDEX(_id), + ADD INDEX(_status) + " ); } @@ -548,11 +551,15 @@ abstract class CRM_Import_DataSource { */ protected function getStatusMapping(): array { return [ - CRM_Import_Parser::VALID => ['imported', 'new'], - CRM_Import_Parser::ERROR => ['error', 'invalid'], + CRM_Import_Parser::VALID => ['imported', 'new', 'soft_credit_imported', 'pledge_payment_imported'], + CRM_Import_Parser::ERROR => ['error', 'invalid', 'soft_credit_error', 'pledge_payment_error'], CRM_Import_Parser::DUPLICATE => ['duplicate'], CRM_Import_Parser::NO_MATCH => ['invalid_no_match'], CRM_Import_Parser::UNPARSED_ADDRESS_WARNING => ['warning_unparsed_address'], + CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR => ['soft_credit_error'], + CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT => ['soft_credit_imported'], + CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT => ['pledge_payment_imported'], + CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR => ['pledge_payment_error'], 'new' => ['new'], ]; } diff --git a/CRM/Import/Form/Summary.php b/CRM/Import/Form/Summary.php index 461990ce01..352d9f27cf 100644 --- a/CRM/Import/Form/Summary.php +++ b/CRM/Import/Form/Summary.php @@ -62,11 +62,17 @@ abstract class CRM_Import_Form_Summary extends CRM_Import_Forms { $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR)); $this->assign('duplicateRowCount', $this->getRowCount(CRM_Import_Parser::DUPLICATE)); $this->assign('unMatchCount', $this->getRowCount(CRM_Import_Parser::NO_MATCH)); + $this->assign('validSoftCreditRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT)); + $this->assign('invalidSoftCreditRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR)); + $this->assign('validPledgePaymentRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT)); + $this->assign('invalidPledgePaymentRowCount', $this->getRowCount(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR)); $this->assign('unparsedAddressCount', $this->getRowCount(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING)); $this->assign('downloadDuplicateRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::DUPLICATE)); $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR)); $this->assign('downloadMismatchRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::NO_MATCH)); $this->assign('downloadAddressRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::UNPARSED_ADDRESS_WARNING)); + $this->assign('downloadPledgePaymentErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::PLEDGE_PAYMENT_ERROR)); + $this->assign('downloadSoftCreditErrorRecordsUrl', $this->getDownloadURL(CRM_Contribute_Import_Parser_Contribution::SOFT_CREDIT_ERROR)); $userJobID = CRM_Utils_Request::retrieve('user_job_id', 'String', $this, TRUE); $userJob = UserJob::get(TRUE)->addWhere('id', '=', $userJobID)->execute()->first(); $onDuplicate = (int) $userJob['metadata']['submitted_values']['onDuplicate']; diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/.~lock.pledge.csv# b/tests/phpunit/CRM/Contribute/Import/Parser/data/.~lock.pledge.csv# new file mode 100644 index 0000000000..32d7c594e0 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Import/Parser/data/.~lock.pledge.csv# @@ -0,0 +1 @@ +,eileen,eileen-laptop,08.06.2022 11:54,file:///home/eileen/.config/libreoffice/4; \ No newline at end of file diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions_amount_validate.csv.error.log b/tests/phpunit/CRM/Contribute/Import/Parser/data/contributions_amount_validate.csv.error.log new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv b/tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv new file mode 100644 index 0000000000..1ce47a4434 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv @@ -0,0 +1,2 @@ +Email,Amount,Pledge ID,Receive date,Financial Type +mum@example.com,5,1,2022-01-07,Donation diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv.error.log b/tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv.error.log new file mode 100644 index 0000000000..e69de29bb2 -- 2.25.1