Adamw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/114112
Change subject: WIP (FR #1371) Begin to generalize checks import files to
handle different formats
......................................................................
WIP (FR #1371) Begin to generalize checks import files to handle different
formats
Change-Id: Ibd54431f40b4fcd3ef795436c6c251b728eeef91
---
A sites/all/modules/offline2civicrm/AzlChecksFile.php
M sites/all/modules/offline2civicrm/ChecksFile.php
M sites/all/modules/offline2civicrm/ChecksImportLog.php
A sites/all/modules/offline2civicrm/PayPalChecksFile.php
M sites/all/modules/offline2civicrm/offline2civicrm.info
M sites/all/modules/offline2civicrm/offline2civicrm.module
6 files changed, 114 insertions(+), 42 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/12/114112/1
diff --git a/sites/all/modules/offline2civicrm/AzlChecksFile.php
b/sites/all/modules/offline2civicrm/AzlChecksFile.php
new file mode 100644
index 0000000..a904ff0
--- /dev/null
+++ b/sites/all/modules/offline2civicrm/AzlChecksFile.php
@@ -0,0 +1,41 @@
+<?php
+
+class AzlChecksFile extends ChecksFile {
+ protected $required_fields = array(
+ 'date',
+ 'gross',
+ 'gift_source',
+ 'import_batch_number',
+ 'check_number',
+ 'restrictions',
+ );
+
+ protected $required_columns = array(
+ 'Batch',
+ 'Check Number',
+ 'City',
+ 'Contribution Type',
+ 'Country',
+ 'Direct Mail Appeal',
+ 'Email',
+ 'Gift Source',
+ 'Payment Instrument',
+ 'Postal Code',
+ 'Postmark Date',
+ 'Received Date',
+ 'Restrictions',
+ 'Source',
+ 'State',
+ 'Street Address',
+ 'Thank You Letter Date',
+ 'Total Amount',
+ );
+
+ function getRequiredColumns() {
+ return $this->required_columns;
+ }
+
+ function getRequiredFields() {
+ return $this->required_fields;
+ }
+}
diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php
b/sites/all/modules/offline2civicrm/ChecksFile.php
index fd4a32a..923024d 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -3,55 +3,30 @@
/**
* CSV batch format for manually-keyed donation checks
*/
-class ChecksFile {
+abstract class ChecksFile {
+ /**
+ * @param string $file_uri path to the file
+ */
+ function __construct( $file_uri ) {
+ $this->file_uri = $file_uri;
+ }
+
/**
* Read checks from a file and save to the database.
- *
- * @param string $filename path to the file
*/
- function import( $filename ) {
- ChecksImportLog::record( "Beginning import of checks file
$filename..." );
+ function import() {
+ ChecksImportLog::record( "Beginning import of checks file
{$this->file_uri}..." );
//TODO: $db->begin();
- $required_fields = array(
- 'date',
- 'gross',
- 'gift_source',
- 'import_batch_number',
- 'check_number',
- 'restrictions',
- );
-
ini_set( 'auto_detect_line_endings', true );
- if( ( $file = fopen( $filename, 'r' )) === FALSE ){
- throw new WmfException( 'FILE_NOT_FOUND', 'Import checks: Could
not open file for reading: ' . $filename );
+ if( ( $file = fopen( $this->file_uri, 'r' )) === FALSE ){
+ throw new WmfException( 'FILE_NOT_FOUND', 'Import checks: Could
not open file for reading: ' . $this->file_uri );
}
$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',
- 'Postmark Date',
- 'Received Date',
- 'Restrictions',
- 'Source',
- 'State',
- 'Street Address',
- 'Thank You Letter Date',
- 'Total Amount',
- );
-
$failed = array();
- foreach ( $required_columns as $name ) {
+ foreach ( $this->getRequiredColumns() as $name ) {
if ( !array_key_exists( $name, $headers ) ) {
$failed[] = $name;
}
@@ -178,7 +153,7 @@
}
$failed = array();
- foreach ( $required_fields as $key ) {
+ foreach ( $this->getRequiredFields() as $key ) {
if ( !array_key_exists( $key, $msg ) or empty( $msg[$key] ) ) {
$failed[] = $key;
}
@@ -202,4 +177,7 @@
ChecksImportLog::record( $message );
watchdog( 'offline2civicrm', $message, array(), WATCHDOG_INFO );
}
+
+ abstract protected function getRequiredFields();
+ abstract protected function getRequiredColumns();
}
diff --git a/sites/all/modules/offline2civicrm/ChecksImportLog.php
b/sites/all/modules/offline2civicrm/ChecksImportLog.php
index 7c7fcf5..c8ad4a7 100644
--- a/sites/all/modules/offline2civicrm/ChecksImportLog.php
+++ b/sites/all/modules/offline2civicrm/ChecksImportLog.php
@@ -1,7 +1,7 @@
<?php
class ChecksImportLog {
- function recentEvents( $pageLength = 20 ) {
+ static function recentEvents( $pageLength = 20 ) {
$result = db_select( 'offline2civicrm_log' )
->fields( 'offline2civicrm_log' )
->orderBy( 'id', 'DESC' )
@@ -16,7 +16,7 @@
return $events;
}
- function record( $description ) {
+ static function record( $description ) {
global $user;
db_insert( 'offline2civicrm_log' )->fields( array(
'who' => $user->name,
diff --git a/sites/all/modules/offline2civicrm/PayPalChecksFile.php
b/sites/all/modules/offline2civicrm/PayPalChecksFile.php
new file mode 100644
index 0000000..bfae037
--- /dev/null
+++ b/sites/all/modules/offline2civicrm/PayPalChecksFile.php
@@ -0,0 +1,32 @@
+<?php
+
+class PayPalChecksFile extends ChecksFile {
+ protected $required_fields = array(
+ 'date',
+ 'gross',
+ 'gift_source',
+ 'restrictions',
+ );
+
+ protected $required_columns = array(
+ 'Batch',
+ 'Contribution Type',
+ 'Date',
+ 'Direct Mail Appeal',
+ 'First Name',
+ 'Gift Source',
+ 'Last Name',
+ 'Restrictions',
+ 'Source',
+ 'Thank You Letter Date',
+ 'Total Amount',
+ );
+
+ function getRequiredColumns() {
+ return $this->required_columns;
+ }
+
+ function getRequiredFields() {
+ return $this->required_fields;
+ }
+}
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.info
b/sites/all/modules/offline2civicrm/offline2civicrm.info
index bfb1889..88b67dc 100644
--- a/sites/all/modules/offline2civicrm/offline2civicrm.info
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.info
@@ -7,8 +7,10 @@
dependencies[] = wmf_communication
dependencies[] = civicrm
# configure = admin/config/offline2civicrm/settings
+files[] = AzlChecksFile.php
files[] = ChecksFile.php
files[] = ChecksImportLog.php
files[] = ContributionConversion.php
files[] = CsvBatchFile.php
+files[] = PayPalChecksFile.php
files[] = tests/ContributionConversion.test
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.module
b/sites/all/modules/offline2civicrm/offline2civicrm.module
index a34151a..4eddf2a 100644
--- a/sites/all/modules/offline2civicrm/offline2civicrm.module
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.module
@@ -91,6 +91,15 @@
'#type' => 'submit',
'#value' => t( 'Upload' ),
);
+ $form['import_upload_format'] = array(
+ '#title' => t( 'File format' ),
+ '#type' => 'radios',
+ '#default_value' => 'azl',
+ '#options' => array(
+ 'azl' => t( 'AZ Lockbox' ),
+ 'paypal' => t( 'PayPal special fund' ),
+ ),
+ );
$form['log'] = array(
'#markup' => $log_html,
);
@@ -115,7 +124,17 @@
civicrm_initialize();
$smellyTmp = CRM_Core_TemporaryErrorScope::useException();
- ChecksFile::import( $file->uri );
+ switch ( $form_state['values']['import_upload_format'] ) {
+ case 'azl':
+ $importer = new AzlChecksFile( $file->uri );
+ break;
+ case 'paypal':
+ $importer = new PayPalChecksFile( $file->uri );
+ break;
+ default:
+ throw new Exception( 'Bad file format selection' );
+ }
+ $importer->import();
drupal_set_message( "Successful import!" );
}
catch ( WmfException $ex ) {
--
To view, visit https://gerrit.wikimedia.org/r/114112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd54431f40b4fcd3ef795436c6c251b728eeef91
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits