jenkins-bot has submitted this change and it was merged. Change subject: More flexible import validation ......................................................................
More flexible 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(-) Approvals: XenoRyet: Looks good to me, approved jenkins-bot: Verified 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: merged Gerrit-Change-Id: I4a861ac6c9032b6bb13d738238a6feee533d64f6 Gerrit-PatchSet: 2 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits