Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316021

Change subject: More complex import validation
......................................................................

More complex import validation

Allow overriding column validation to support files that need one of
two possible columns, use for payment instrument.

Bug: T147521
Change-Id: I4a861ac6c9032b6bb13d738238a6feee533d64f6
---
M sites/all/modules/offline2civicrm/ChecksFile.php
M sites/all/modules/offline2civicrm/WmfImportFile.php
2 files changed, 32 insertions(+), 10 deletions(-)


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

diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php 
b/sites/all/modules/offline2civicrm/ChecksFile.php
index 0810c71..f5c428b 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -35,15 +35,7 @@
 
         $headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
 
-        $failed = array();
-        foreach ( $this->getRequiredColumns() as $name ) {
-            if ( !array_key_exists( $name, $headers ) ) {
-                $failed[] = $name;
-            }
-        }
-        if ( $failed ) {
-            throw new WmfException( 'INVALID_FILE_FORMAT', "This file is 
missing column headers: " . implode( ", ", $failed ) );
-        }
+               $this->validateColumns( $headers );
 
         $num_errors = 0;
         $num_ignored = 0;
@@ -429,4 +421,22 @@
                        'gross',
                );
        }
+
+       /**
+        * Ensure the file contains all the data we need.
+        *
+        * @param array $headers Column names
+        * @throws WmfException if required columns are missing
+        */
+       protected function validateColumns( $headers ) {
+               $failed = array();
+               foreach ( $this->getRequiredColumns() as $name ) {
+                       if ( !array_key_exists( $name, $headers ) ) {
+                               $failed[] = $name;
+                       }
+               }
+               if ( $failed ) {
+                       throw new WmfException( 'INVALID_FILE_FORMAT', "This 
file is missing column headers: " . implode( ", ", $failed ) );
+               }
+       }
 }
diff --git a/sites/all/modules/offline2civicrm/WmfImportFile.php 
b/sites/all/modules/offline2civicrm/WmfImportFile.php
index b8d0b85..3689786 100644
--- a/sites/all/modules/offline2civicrm/WmfImportFile.php
+++ b/sites/all/modules/offline2civicrm/WmfImportFile.php
@@ -30,7 +30,6 @@
             'No Thank You',
             'Original Amount',
             'Original Currency',
-            'Raw Payment Instrument',
             'Phone',
             'Postal Code',
             'Postmark Date',
@@ -48,4 +47,17 @@
             'Transaction ID',
         );
     }
+
+       protected function validateColumns( $headers ) {
+               if (
+                       !array_key_exists( 'Raw Payment Instrument', $headers ) 
&&
+                       !array_key_exists( 'Payment Instrument', $headers )
+               ) {
+                       throw new WmfException(
+                               'INVALID_FILE_FORMAT',
+                               'File must contain either \'Payment 
Instrument\' or \'Raw Payment Instrument\''
+                       );
+               }
+               parent::validateColumns( $headers );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a861ac6c9032b6bb13d738238a6feee533d64f6
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to