Eileen has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394221 )

Change subject: Fix checks for existing contributions on Benevity imports to 
check donor AND matching contributions.
......................................................................

Fix checks for existing contributions on Benevity imports to check donor AND 
matching contributions.

Currently donor contributions that have already been imported are marked as 
duplicates but where the matching
contribution has been imported that is not picked up as a duplicate and results 
in an error.

The impact on users is that a string of errors will result in the import 
aborting. On the other hand, a string
of duplicates will be ignored, allowing a mostly imported csv to be 
re-attempted.

Bug: T181548
Change-Id: Iff464153e40c9f751c63e21b0236d552f1e1ceb9
---
M sites/all/modules/offline2civicrm/BenevityFile.php
M sites/all/modules/offline2civicrm/ChecksFile.php
2 files changed, 54 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/21/394221/1

diff --git a/sites/all/modules/offline2civicrm/BenevityFile.php 
b/sites/all/modules/offline2civicrm/BenevityFile.php
index 9c65520..683c8c7 100644
--- a/sites/all/modules/offline2civicrm/BenevityFile.php
+++ b/sites/all/modules/offline2civicrm/BenevityFile.php
@@ -411,4 +411,45 @@
     return FALSE;
   }
 
+  /**
+   * Check for any existing contributions for the given transaction.
+   *
+   * If either the donor transaction of the matching gift transaction have 
already
+   * been imported return (1) imported transaction.
+   *
+   * If both the matching and donor transactions have been imported previously 
it
+   * is OK to return only one
+   *
+   * If it appears there has been a previous partial import
+   *
+   * @param $msg
+   *
+   * @return array|bool
+   *
+   * @throws \WmfException
+   */
+  protected function checkForExistingContributions($msg) {
+    $donorTransactionNeedsProcessing = (!empty($msg['gross']) && $msg['gross'] 
!== "0.00");
+    $matchingTransactionNeedsProcessing = (!empty($msg['matching_amount']) && 
$msg['matching_amount'] !== "0.00");
+
+    $main = $matched = FALSE;
+    if ($donorTransactionNeedsProcessing) {
+      $main = wmf_civicrm_get_contributions_from_gateway_id($msg['gateway'], 
$msg['gateway_txn_id']);
+    }
+
+    if ($matchingTransactionNeedsProcessing) {
+      $matched = 
wmf_civicrm_get_contributions_from_gateway_id($msg['gateway'], 
$msg['gateway_txn_id'] . '_matched');
+    }
+
+    if ($matchingTransactionNeedsProcessing && 
$donorTransactionNeedsProcessing) {
+      // Both transactions need processing. If one finds a match and the other 
doesn't we have a potential error scenario
+      // and should throw an exception.
+      $duplicates = ($main ? 1 : 0) + ($matched ? 1 : 0);
+      if ($duplicates === 1) {
+        throw new WmfException('INVALID_MESSAGE', 'row has already been 
partially imported');
+      }
+    }
+    return $main ? $main : $matched;
+  }
+
 }
diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php 
b/sites/all/modules/offline2civicrm/ChecksFile.php
index 4d6601a..f5f0ae0 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -131,9 +131,10 @@
           throw new IgnoredRowException('IMPORT_CONTRIB', 'Error limit 
reached');
         }
         $msg = $this->parseRow($data);
+        $existing = $this->checkForExistingContributions($msg);
 
         // check to see if we have already processed this check
-        if ($existing = 
wmf_civicrm_get_contributions_from_gateway_id($msg['gateway'], 
$msg['gateway_txn_id'])) {
+        if ($existing) {
           $skipped = $this->handleDuplicate($existing);
           if ($skipped) {
             if ($num_duplicates === 0) {
@@ -662,4 +663,15 @@
     }
   }
 
+  /**
+   * Check for any existing contributions for the given transaction.
+   *
+   * @param $msg
+   *
+   * @return array|bool
+   */
+  protected function checkForExistingContributions($msg) {
+    return  wmf_civicrm_get_contributions_from_gateway_id($msg['gateway'], 
$msg['gateway_txn_id']);
+  }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/394221
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff464153e40c9f751c63e21b0236d552f1e1ceb9
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: deployment
Gerrit-Owner: Eileen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to