Adamw has submitted this change and it was merged.
Change subject: fail entire check import if required columns are missing
......................................................................
fail entire check import if required columns are missing
Change-Id: Ie289ea00c5fea5fcca2a2a3c727037a11cb7adeb
---
M sites/all/modules/offline2civicrm/import_checks.drush.inc
M sites/all/modules/offline2civicrm/offline2civicrm.common.inc
M sites/all/modules/wmf_common/errors.inc
3 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/sites/all/modules/offline2civicrm/import_checks.drush.inc
b/sites/all/modules/offline2civicrm/import_checks.drush.inc
index 9a817d1..e56f2b0 100644
--- a/sites/all/modules/offline2civicrm/import_checks.drush.inc
+++ b/sites/all/modules/offline2civicrm/import_checks.drush.inc
@@ -63,6 +63,36 @@
$headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
+ $required_columns = array(
+ 'Batch',
+ 'Check Number',
+ 'City',
+ 'Contribution Type',
+ 'Country',
+ 'Direct Mail Appeal',
+ 'Email',
+ 'Gift Source',
+ 'Payment Instrument',
+ 'Postal Code',
+ 'Received Date',
+ 'Restrictions',
+ 'Source',
+ 'State',
+ 'Street Address',
+ 'Thank You Letter Date',
+ 'Total Amount',
+ );
+
+ $failed = array();
+ foreach ( $required_columns as $name ) {
+ if ( !array_key_exists( $name, $headers ) ) {
+ $failed[] = $name;
+ }
+ }
+ if ( $failed ) {
+ throw new WmfException( 'INVALID_FILE_FORMAT', "This file is
missing headers: " . implode( ", ", $failed ) );
+ }
+
while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
try {
list($currency, $source_amount) = explode( " ",
_get_value( "Source", $row, $headers ) );
@@ -76,8 +106,6 @@
$msg = array(
"optout" => "1",
"anonymous" => "0",
- "utm_source" => _get_value( "Payment
Instrument", $row, $headers ),
- "utm_medium" => str_replace(' ', '',
_get_value( "Appeal", $row, $headers ) ),
"letter_code" => _get_value( "Letter Code",
$row, $headers ),
"contact_source" => "check",
"language" => "en",
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
b/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
index 3ba258e..802d57a 100644
--- a/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
@@ -24,6 +24,10 @@
if( !array_key_exists( $column, $headers ) ){
return $default;
} else {
- return trim( $row[ $headers[ $column ] ] );
+ $value = trim( $row[ $headers[ $column ] ] );
+ if ( empty( $value ) ) {
+ return $default;
+ }
+ return $value;
}
}
diff --git a/sites/all/modules/wmf_common/errors.inc
b/sites/all/modules/wmf_common/errors.inc
index 54244f6..f7989a3 100644
--- a/sites/all/modules/wmf_common/errors.inc
+++ b/sites/all/modules/wmf_common/errors.inc
@@ -50,6 +50,9 @@
'UNSUBSCRIBE_WARN' => array(
'no-email' => TRUE,
),
+ 'INVALID_FILE_FORMAT' => array(
+ 'fatal' => TRUE,
+ ),
);
var $type;
--
To view, visit https://gerrit.wikimedia.org/r/72616
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie289ea00c5fea5fcca2a2a3c727037a11cb7adeb
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits