Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53399
Change subject: (FR #589) check that Source and Total Amount match. failmail
otherwise.
......................................................................
(FR #589) check that Source and Total Amount match. failmail otherwise.
Change-Id: I755981d53ccc22a87b93b9bd795ea92664ae7f3f
---
M sites/all/modules/offline2civicrm/import_checks.drush.inc
1 file changed, 36 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/civicrm
refs/changes/99/53399/1
diff --git a/sites/all/modules/offline2civicrm/import_checks.drush.inc
b/sites/all/modules/offline2civicrm/import_checks.drush.inc
index 4748149..4a5cb2d 100644
--- a/sites/all/modules/offline2civicrm/import_checks.drush.inc
+++ b/sites/all/modules/offline2civicrm/import_checks.drush.inc
@@ -43,21 +43,27 @@
function drush_import_checks() {
require_once 'offline2civicrm.common.inc';
- try{
- $args = drush_get_arguments();
- $filename = $args[1];
+ $args = drush_get_arguments();
+ $filename = $args[1];
- ini_set( 'auto_detect_line_endings', true );
- if( ( $file = fopen( $filename, 'r' )) === FALSE ){
- watchdog('offline2civicrm', 'Import checks: Could not
open file for reading: ' . $filename, array(), WATCHDOG_ERROR);
- return;
- }
+ ini_set( 'auto_detect_line_endings', true );
+ if( ( $file = fopen( $filename, 'r' )) === FALSE ){
+ watchdog('offline2civicrm', 'Import checks: Could not open file
for reading: ' . $filename, array(), WATCHDOG_ERROR);
+ return;
+ }
- $headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
+ $headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
- while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
- // The following is fairly specific to the format
received for the 2011 fundraiser
- // in csv's generated by Merkle. This may be to be
tweaked if a new format is used
+ while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
+ try {
+ list($currency, $source_amount) = explode( " ",
_get_value( "Source", $row, $headers ) );
+ $total_amount = (float)_get_value( "Total Amount",
$row, $headers );
+
+ if ( abs( $source_amount - $total_amount ) > .01 ) {
+ $pretty_msg = json_encode( array_combine(
array_keys( $headers ), $row ) );
+ throw new WmfException( 'INVALID_MESSAGE',
$pretty_msg );
+ }
+
$msg = array(
"optout" => "1",
"anonymous" => "0",
@@ -75,8 +81,8 @@
"payment_method" => _get_value( "Payment
Instrument", $row, $headers ),
"payment_submethod" => "",
"check_number" => _get_value( "Check Number",
$row, $headers ),
- "currency" => substr( _get_value( "Source",
$row, $headers ), 0, strpos( _get_value( "Source", $row, $headers ), ' ' ) + 1
),
- "original_currency" => substr( _get_value(
"Source", $row, $headers ), 0, strpos( _get_value( "Source", $row, $headers ),
' ' ) + 1 ),
+ "currency" => $currency,
+ "original_currency" => $currency,
"original_gross" => _get_value( "Total Amount",
$row, $headers ),
"fee" => "0",
"gross" => _get_value( "Total Amount", $row,
$headers ),
@@ -134,21 +140,24 @@
continue;
}
- //TODO un-nest
- try {
- $contribution =
wmf_civicrm_contribution_message_import( $msg );
- }
- catch (WmfException $ex) {
- watchdog('offline2civicrm', 'Import checks:
error during import ' + $ex->getMessage(), NULL, WATCHDOG_ERROR);
- if ($ex->isFatal()) {
- watchdog('offline2civicrm', 'Import
checks: fatal error, aborting process', NULL, WATCHDOG_ERROR);
- return;
- }
+ $contribution =
wmf_civicrm_contribution_message_import( $msg );
+ }
+ catch (WmfException $ex) {
+ watchdog('offline2civicrm', 'Import checks: error
during import ' + $ex->getMessage(), NULL, WATCHDOG_ERROR);
+ if ( $ex->isRejectMessage() && !$ex->isNoEmail() ) {
+ wmf_common_failmail( 'offline2civicrm', $ex );
}
- watchdog('offline2civicrm', 'Import checks:
Contribution imported successfully (!id): !msg', array('!id' =>
$contribution['id'], '!msg' => print_r( $msg, true )), WATCHDOG_INFO);
+ if ($ex->isFatal()) {
+ watchdog('offline2civicrm', 'Import checks:
fatal error, aborting process', NULL, WATCHDOG_ERROR);
+ return;
+ }
+ } catch ( Exception $e ){
+ watchdog('offline2civicrm', 'Import checks: Unknown
exception thrown during check processing: ' . print_r( $e, true ), array(),
WATCHDOG_ERROR);
}
- } catch ( Exception $e ){
- watchdog('offline2civicrm', 'Import checks: Exception thrown
during check processing: ' . print_r( $e, true ), array(), WATCHDOG_ERROR);
+
+ watchdog('offline2civicrm', 'Import checks: Contribution
imported successfully (!id): !msg', array('!id' => $contribution['id'], '!msg'
=> print_r( $msg, true )), WATCHDOG_INFO);
}
+
+ watchdog( 'offline2civicrm', 'Import checks: finished', null,
WATCHDOG_INFO );
}
--
To view, visit https://gerrit.wikimedia.org/r/53399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I755981d53ccc22a87b93b9bd795ea92664ae7f3f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/civicrm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits