Switch contribution to use same error handling
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 7 Jun 2022 23:34:20 +0000 (11:34 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 8 Jun 2022 00:52:04 +0000 (12:52 +1200)
CRM/Contribute/Import/Form/Summary.php
CRM/Import/DataSource.php
CRM/Import/Form/Summary.php
tests/phpunit/CRM/Contribute/Import/Parser/data/.~lock.pledge.csv# [new file with mode: 0644]
tests/phpunit/CRM/Contribute/Import/Parser/data/contributions_amount_validate.csv.error.log [new file with mode: 0644]
tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv [new file with mode: 0644]
tests/phpunit/CRM/Contribute/Import/Parser/data/pledge.csv.error.log [new file with mode: 0644]

index 9bf6214f8042118e0397fed00a330c1aaf04fc74..c1d5d06b6fba6b93a0f4d45c59792121ef9acbc4 100644 (file)
@@ -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();
   }
 
 }
index 47bc3f6e1e621fe064b93bf6b2f778ec6edae9c2..3b4ed98785584951cf9955a5cbffcc0c85e5b528 100644 (file)
@@ -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'],
     ];
   }
index 461990ce017fe462ac36910323003014415610b1..352d9f27cf71cf27501d078f21eea3fc3dc20217 100644 (file)
@@ -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 (file)
index 0000000..32d7c59
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
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 (file)
index 0000000..1ce47a4
--- /dev/null
@@ -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 (file)
index 0000000..e69de29