Adamw has uploaded a new change for review.

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


Change subject: Improve check import
......................................................................

Improve check import

* Validation for all variations of name columns
* Factor into functions
* Class wrapper for CSV file handling, returns associative rows

FIXME: chargeback script cannot be used.  Was this deprecated by the WR1 parser?

Change-Id: I2a6bbc134a197bae289beb261b5831aa6c253e30
---
A sites/all/modules/offline2civicrm/ChargebacksFile.php
M sites/all/modules/offline2civicrm/ChecksFile.php
A sites/all/modules/offline2civicrm/CsvFile.php
M sites/all/modules/offline2civicrm/import_chargebacks.drush.inc
D sites/all/modules/offline2civicrm/offline2civicrm.common.inc
M sites/all/modules/offline2civicrm/offline2civicrm.info
M sites/all/modules/offline2civicrm/offline2civicrm.module
7 files changed, 299 insertions(+), 268 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/14/82114/1

diff --git a/sites/all/modules/offline2civicrm/ChargebacksFile.php 
b/sites/all/modules/offline2civicrm/ChargebacksFile.php
new file mode 100644
index 0000000..2494700
--- /dev/null
+++ b/sites/all/modules/offline2civicrm/ChargebacksFile.php
@@ -0,0 +1,81 @@
+<?php
+//FIXME: deprecate, or correctly implement the chargeback api.  Existing code 
will zero out contributions and insert text in contribution_source which is 
incompatible with our triggers.
+
+class ChargebacksFile extends CsvFile {
+  static function import( $filename ) {
+    try{
+      // GlobalCollect actually supplies a semicolon separated file
+      $file = new ChargebacksFile( $filename, ';' );
+
+      while ( $row = $file->readRow() ) {
+
+        $orderid = $row['Order ID'];
+        $effortid = $row['Effort ID'];
+
+        if ( !$orderid ) {
+          watchdog('offline2civicrm', "Empty OrderID for chargeback on row", 
NULL, WATCHDOG_INFO);
+          continue;
+        }
+        if(intval($effortid) > 1){
+          // we only use the Effort ID on recurring transactions, and then 
only the subsequent ones
+          $orderid .= "-{$effortid}";
+        }
+
+        if ( $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
'globalcollect', $orderid ) ) {
+          $contribution = array_shift( $contributions );
+        } else {
+          // still nothing, I'm outta guesses, lets break and give a human a 
try
+          watchdog('offline2civicrm', "Could not find transaction matching 
trxn_id: " .
+            print_r($row, TRUE), NULL, WATCHDOG_ERROR);
+          continue;
+        }
+
+        // execute the chargeback
+        $file->chargeback( $contribution['id'] );
+      }
+    } catch ( Exception $e ){
+      watchdog('offline2civicrm', 'Import chargebacks: Exception thrown during 
chargeback processing: ' .
+        print_r( $e, true ), array(), WATCHDOG_ERROR);
+    }
+  }
+
+  function chargeback( $contribution_id ) {
+    print "\tCharging back $contribution_id\n";
+
+    $contribution = civicrm_api("Contribution", "Get", array(
+      "version" => "3",
+      "id" => $contribution_id
+    ));
+
+    if(!WMFCiviAPICheck::check_api_contribution($contribution, 
$contribution_id)){
+      watchdog('offline2civicrm', "Contribution (id: $contribution_id) could 
not be loaded via CiviCRM API: " .
+        print_r($contribution, TRUE), NULL, WATCHDOG_ERROR);
+      return false;
+    }
+
+    $contribution_flat = WMFCiviAPICheck::check_api_simplify($contribution, 
$contribution_id);
+
+    if($contribution_flat === false){
+      watchdog('offline2civicrm', "Contribution could not be extracted from 
API response: " .
+        print_r($contribution, TRUE), NULL, WATCHDOG_ERROR);
+      return false;
+    }
+
+    $contribution = $contribution_flat;
+
+    if(substr($contribution["contribution_source"], 0, 3) == "RFD"){
+        // the contribution has already been charged back or refunded
+        return true;
+    }
+
+    $contribution["total_amount"] = "0.00";
+    $contribution["net_amount"] = "0.00";
+    $contribution["contribution_source"] = "RFD CHARGEDBACK (" . 
$contribution["contribution_source"] . ")";
+
+    $updated = civicrm_api("Contribution", "Update", 
array_merge($contribution, array('version' => '3',)));
+
+    watchdog('offline2civicrm', "Updated contribution: " . print_r($updated, 
true), NULL, WATCHDOG_INFO);
+
+    return true;
+  }
+}
diff --git a/sites/all/modules/offline2civicrm/ChecksFile.php 
b/sites/all/modules/offline2civicrm/ChecksFile.php
index 538e73c..aad69a2 100644
--- a/sites/all/modules/offline2civicrm/ChecksFile.php
+++ b/sites/all/modules/offline2civicrm/ChecksFile.php
@@ -3,16 +3,156 @@
 /**
  * CSV batch format for manually-keyed donation checks
  */
-class ChecksFile {
+class ChecksFile extends CsvFile {
     /**
      * Read checks from a file and save to the database.
      *
      * @param string $filename path to the file
      */
-    function import( $filename ) {
+    static function import( $filename ) {
         ChecksImportLog::record( "Beginning import of checks file 
$filename..." );
+        $file = new ChecksFile( $filename );
         //TODO: $db->begin();
 
+        $file->validateFileStructure();
+
+        $num_successful = 0;
+        $num_duplicates = 0;
+
+        while ( $row = $file->readRow() ) {
+            $msg = $file->normalizeRow( $row );
+
+            $file->validateRow( $row, $msg );
+
+            // check to see if we have already processed this check
+            if ( $existing = wmf_civicrm_get_contributions_from_gateway_id( 
$msg['gateway'], $msg['gateway_txn_id'] ) ){
+                // if so, move on
+                watchdog( 'offline2civicrm', 'Contribution matches existing 
contribution (id: @id), skipping it.', array( '@id' => $existing[0]['id'] ), 
WATCHDOG_INFO );
+                $num_duplicates++;
+                continue;
+            }
+
+            $contribution = wmf_civicrm_contribution_message_import( $msg );
+
+            watchdog( 'offline2civicrm',
+                'Import checks: Contribution imported successfully (@id): 
!msg', array(
+                    '@id' => $contribution['id'],
+                    '!msg' => print_r( $msg, true ),
+                ), WATCHDOG_INFO
+            );
+            $num_successful++;
+        }
+
+        $message = t( "Checks import complete. @successful imported, not 
including @duplicates duplicates.", array( '@successful' => $num_successful, 
'@duplicates' => $num_duplicates ) );
+        ChecksImportLog::record( $message );
+        watchdog( 'offline2civicrm', $message, array(), WATCHDOG_INFO );
+    }
+
+    function normalizeRow( $row ) {
+        list($currency, $source_amount) = explode( " ", $row['Source'] );
+
+        $msg = array(
+            'anonymous' => "0",
+            'check_number' => $row['Check Number'],
+            'city' => $row['City'],
+            'contact_source' => "check",
+            'country' => $row['Country'],
+            'currency' => $currency,
+            'date' => strtotime( $row['Received Date'] ),
+            'direct_mail_appeal' => $row['Direct Mail Appeal'],
+            'email' => $row['Email'],
+            'fee' => "0",
+            'gift_source' => $row['Gift Source'],
+            'gross' => $row['Total Amount'],
+            'import_batch_number' => $row['Batch'],
+            'language' => "en",
+            'net' => $row['Total Amount'],
+            'optout' => "1",
+            'original_currency' => $currency,
+            'original_gross' => $row['Total Amount'],
+            'payment_method' => $row['Payment Instrument'],
+            'payment_submethod' => "",
+            'postal_code' => $row['Postal Code'],
+            'restrictions' => $row['Restrictions'],
+            'state_province' => $row['State'],
+            'street_address' => $row['Street Address'],
+            'thankyou_date' => strtotime( $row['Thank You Letter Date'] ),
+        );
+
+        $contype = $row['Contribution Type'];
+        switch ( $contype ) {
+            case "Merkle":
+                $msg['gateway'] = "merkle";
+                break;
+
+            case "Arizona Lockbox":
+                $msg['gateway'] = "arizonalockbox";
+                break;
+
+            default:
+                throw new WmfException( 'INVALID_MESSAGE', "Contribution Type 
'$contype' is unknown whilst importing checks!" );
+        }
+
+        // Attempt to get the organization name if it exists...
+        $orgname = null;
+        if ( array_key_exists( 'Organization Name', $row ) ) {
+            $orgname = $row['Organization Name'];
+        } elseif ( array_key_exists( 'Company', $row ) ) {
+            $orgname = $row['Company'];
+        }
+
+        if ( $orgname ) {
+            $msg['contact_type'] = "Organization";
+            $msg['organization_name'] = $orgname;
+        } else {
+            // it's an individual
+            $msg['contact_type'] = "Individual";
+            $msg["first_name"] = $row['First Name'];
+            $msg["middle_name"] = $row['Middle Name'];
+            $msg["last_name"] = $row['Last Name'];
+        }
+
+        if ( array_key_exists( 'Letter Code', $row ) ) {
+            $msg['letter_code'] = $row['Letter Code'];
+        }
+        if ( array_key_exists( 'Additional Address 1', $row ) ) {
+            $msg['supplemental_address_1'] = $row['Additional Address 1'];
+        }
+        if ( array_key_exists( 'Additional Address 2', $row ) ) {
+            $msg['supplemental_address_2'] = $row['Additional Address 2'];
+        }
+
+        // An email address is one of the crucial fields we need
+        if( !$msg['email'] ) {
+            // set to the default, no TY will be sent
+            $msg['email'] = "[email protected]";
+        }
+
+        // CiviCRM gets all weird when there is no country set
+        // Making the assumption that none = US
+        if( !$msg['country'] ) {
+            $msg['country'] = "US";
+        }
+
+        if ( $msg['country'] === "US" ) {
+            // left-pad the zipcode
+            if ( preg_match( '/^(\d{1,4})(-\d+)?$/', $msg['postal_code'], 
$matches ) ) {
+                $msg['postal_code'] = str_pad( $matches[1], 5, "0", 
STR_PAD_LEFT );
+                if ( !empty( $matches[2] ) ) {
+                    $msg['postal_code'] .= $matches[2];
+                }
+            }
+        }
+
+        // Generating a transaction id so that we don't import the same rows 
multiple times
+        $name_salt = $msg['contact_type'] == "Individual" ? $msg["first_name"] 
. $msg["last_name"] : $msg["organization_name"];
+        $msg['gateway_txn_id'] = md5( $msg['check_number'] . $name_salt );
+
+        return $msg;
+    }
+
+    function validateRow( $row, $msg ) {
+        // donations must contain data for each of these fields:
         $required_fields = array(
             'date',
             'gross',
@@ -21,14 +161,28 @@
             '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 );
+        $failed = array();
+        foreach ( $required_fields as $key ) {
+            if ( !array_key_exists( $key, $msg ) or empty( $msg[$key] ) ) {
+                $failed[] = $key;
+            }
+        }
+        if ( $failed ) {
+            throw new WmfException( 'CIVI_REQ_FIELD', t( "Missing required 
fields @keys during check import", array( "@keys" => implode( ", ", $failed ) ) 
) );
         }
 
-        $headers = _load_headers( fgetcsv( $file, 0, ',', '"', '\\') );
+        list($currency, $source_amount) = explode( " ", $row['Source'] );
+        $total_amount = floatval( $row['Total Amount'] );
 
+        if ( abs( $source_amount - $total_amount ) > .01 ) {
+            $pretty_msg = json_encode( $row );
+            throw new WmfException( 'INVALID_MESSAGE', "Amount mismatch: " . 
$pretty_msg );
+        }
+
+    }
+
+    function validateFileStructure() {
+        // batch files must have all of these columns:
         $required_columns = array(
             'Batch',
             'Check Number',
@@ -48,10 +202,9 @@
             'Thank You Letter Date',
             'Total Amount',
         );
-
         $failed = array();
         foreach ( $required_columns as $name ) {
-            if ( !array_key_exists( $name, $headers ) ) {
+            if ( array_search( $name, $this->headers ) === false ) {
                 $failed[] = $name;
             }
         }
@@ -59,144 +212,20 @@
             throw new WmfException( 'INVALID_FILE_FORMAT', "This file is 
missing column headers: " . implode( ", ", $failed ) );
         }
 
-        $num_successful = 0;
-        $num_duplicates = 0;
-
-        while( ( $row = fgetcsv( $file, 0, ',', '"', '\\')) !== FALSE) {
-            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', "Amount mismatch: " 
. $pretty_msg );
+        // ... and must have all elements of one set of name columns.
+        $name_columns = array(
+            array( 'Organization Name' ),
+            array( 'Company' ),
+            array( 'First Name', 'Middle Name', 'Last Name' ),
+        );
+        $has_name_columns = false;
+        foreach ( $name_columns as $columns ) {
+            if ( count( array_intersect( $columns, $this->headers ) ) === 
count( $columns ) ) {
+                $has_name_columns = true;
             }
-
-            $msg = array(
-                "optout" => "1",
-                "anonymous" => "0",
-                "letter_code" => _get_value( "Letter Code", $row, $headers ),
-                "contact_source" => "check",
-                "language" => "en",
-                "street_address" => _get_value( "Street Address", $row, 
$headers ),
-                "supplemental_address_1" => _get_value( "Additional Address 
1", $row, $headers ),
-                "city" => _get_value( "City", $row, $headers ),
-                "state_province" => _get_value( "State", $row, $headers ),
-                "postal_code" => _get_value( "Postal Code", $row, $headers ),
-                "payment_method" => _get_value( "Payment Instrument", $row, 
$headers ),
-                "payment_submethod" => "",
-                "check_number" => _get_value( "Check Number", $row, $headers ),
-                "currency" => $currency,
-                "original_currency" => $currency,
-                "original_gross" => _get_value( "Total Amount", $row, $headers 
),
-                "fee" => "0",
-                "gross" => _get_value( "Total Amount", $row, $headers ),
-                "net" => _get_value( "Total Amount", $row, $headers ),
-                "date" => strtotime( _get_value( "Received Date", $row, 
$headers ) ),
-                "thankyou_date" => strtotime( _get_value( "Thank You Letter 
Date", $row, $headers ) ),
-                "restrictions" => _get_value( "Restrictions", $row, $headers ),
-                "gift_source" => _get_value( "Gift Source", $row, $headers ),
-                "direct_mail_appeal" => _get_value( "Direct Mail Appeal", 
$row, $headers ),
-                "import_batch_number" => _get_value( "Batch", $row, $headers ),
-            );
-
-            $contype = _get_value( 'Contribution Type', $row, $headers );
-            switch ( $contype ) {
-                case "Merkle":
-                    $msg['gateway'] = "merkle";
-                    break;
-
-                case "Arizona Lockbox":
-                    $msg['gateway'] = "arizonalockbox";
-                    break;
-
-                default:
-                    throw new WmfException( 'INVALID_MESSAGE', "Contribution 
Type '$contype' is unknown whilst importing checks!" );
-            }
-
-            // Attempt to get the organization name if it exists...
-            // Merkle used the "Organization Name" column header where AZL 
uses "Company"
-            $orgname = _get_value( 'Organization Name', $row, $headers, FALSE 
);
-            if ( $orgname === FALSE ) {
-                $orgname = _get_value( 'Company', $row, $headers, FALSE );
-            }
-
-            if( $orgname === FALSE ) {
-                // If it's still false let's just assume it's an individual
-                $msg['contact_type'] = "Individual";
-                $msg["first_name"] = _get_value( "First Name", $row, $headers 
);
-                $msg["middle_name"] = _get_value( "Middle Name", $row, 
$headers );
-                $msg["last_name"] = _get_value( "Last Name", $row, $headers );
-            } else {
-                $msg['contact_type'] = "Organization";
-                $msg['organization_name'] = $orgname;
-            }
-
-            // check for additional address information
-            if( _get_value( 'Additional Address 2', $row, $headers ) != ''){
-                $msg['supplemental_address_2'] .= ' ' . _get_value( 
'Additional Address 2', $row, $headers );
-            }
-
-            // An email address is one of the crucial fields we need
-            if( _get_value( 'Email', $row, $headers ) == ''){
-                // set to the default, no TY will be sent
-                $msg['email'] = "[email protected]";
-            } else {
-                $msg['email'] = _get_value( 'Email', $row, $headers );
-            }
-
-            // CiviCRM gets all weird when there is no country set
-            // Making the assumption that none = US
-            if( _get_value( 'Country', $row, $headers ) == ''){
-                $msg['country'] = "US";
-            } else {
-                $msg['country'] = _get_value( 'Country', $row, $headers );
-            }
-
-            if ( $msg['country'] === "US" ) {
-                // left-pad the zipcode
-                if ( preg_match( '/^(\d{1,4})(-\d+)?$/', $msg['postal_code'], 
$matches ) ) {
-                    $msg['postal_code'] = str_pad( $matches[1], 5, "0", 
STR_PAD_LEFT );
-                    if ( !empty( $matches[2] ) ) {
-                        $msg['postal_code'] .= $matches[2];
-                    }
-                }
-            }
-
-            // Generating a transaction id so that we don't import the same 
rows multiple times
-            $name_salt = $msg['contact_type'] == "Individual" ? 
$msg["first_name"] . $msg["last_name"] : $msg["organization_name"];
-            $msg['gateway_txn_id'] = md5( $msg['check_number'] . $name_salt );
-
-            // check to see if we have already processed this check
-            if ( $existing = wmf_civicrm_get_contributions_from_gateway_id( 
$msg['gateway'], $msg['gateway_txn_id'] ) ){
-                // if so, move on
-                watchdog( 'offline2civicrm', 'Contribution matches existing 
contribution (id: @id), skipping it.', array( '@id' => $existing[0]['id'] ), 
WATCHDOG_INFO );
-                $num_duplicates++;
-                continue;
-            }
-
-            $failed = array();
-            foreach ( $required_fields as $key ) {
-                if ( !array_key_exists( $key, $msg ) or empty( $msg[$key] ) ) {
-                    $failed[] = $key;
-                }
-            }
-            if ( $failed ) {
-                throw new WmfException( 'CIVI_REQ_FIELD', t( "Missing required 
fields @keys during check import", array( "@keys" => implode( ", ", $failed ) ) 
) );
-            }
-
-            $contribution = wmf_civicrm_contribution_message_import( $msg );
-
-            watchdog( 'offline2civicrm',
-                'Import checks: Contribution imported successfully (@id): 
!msg', array(
-                    '@id' => $contribution['id'],
-                    '!msg' => print_r( $msg, true ),
-                ), WATCHDOG_INFO
-            );
-            $num_successful++;
         }
-
-        $message = t( "Checks import complete. @successful imported, not 
including @duplicates duplicates.", array( '@successful' => $num_successful, 
'@duplicates' => $num_duplicates ) );
-        ChecksImportLog::record( $message );
-        watchdog( 'offline2civicrm', $message, array(), WATCHDOG_INFO );
+        if ( !$has_name_columns ) {
+            throw new WmfException( 'INVALID_FILE_FORMAT', "This file is 
missing name column headers. Alternatives are: " . json_encode( $name_columns ) 
);
+        }
     }
 }
diff --git a/sites/all/modules/offline2civicrm/CsvFile.php 
b/sites/all/modules/offline2civicrm/CsvFile.php
new file mode 100644
index 0000000..fae38b9
--- /dev/null
+++ b/sites/all/modules/offline2civicrm/CsvFile.php
@@ -0,0 +1,39 @@
+<?php
+
+class CsvFile {
+    protected $file;
+    protected $headers;
+
+    protected $delimiter;
+    protected $quote;
+    protected $escape;
+
+    function __construct( $filename, $delimiter = ',', $quote = '"', $escape = 
'\\' ) {
+        $this->delimiter = $delimiter;
+        $this->quote = $quote;
+        $this->escape = $escape;
+
+        ini_set( 'auto_detect_line_endings', true );
+        if( ( $this->file = fopen( $filename, 'r' )) === false ){
+            throw new WmfException( 'FILE_NOT_FOUND', 'Could not open file for 
reading: ' . $filename );
+        }
+
+        $header_row = fgetcsv( $this->file, 0, $this->delimiter, $this->quote, 
$this->escape );
+        $this->headers = array();
+        foreach ( $header_row as $key ) {
+            $this->headers[] = trim( $key, " \t" );
+        }
+    }
+
+    function readRow() {
+        $row = fgetcsv( $this->file, 0, $this->delimiter, $this->quote, 
$this->escape );
+        if ( $row === false ) {
+            return null;
+        }
+        $trimmed_row = array();
+        foreach ( $row as $value ) {
+            $trimmed_row[] = trim( $value, " \t" );
+        }
+        return array_combine( $this->headers, $trimmed_row );
+    }
+}
diff --git a/sites/all/modules/offline2civicrm/import_chargebacks.drush.inc 
b/sites/all/modules/offline2civicrm/import_chargebacks.drush.inc
index 7686aa0..0c0596d 100755
--- a/sites/all/modules/offline2civicrm/import_chargebacks.drush.inc
+++ b/sites/all/modules/offline2civicrm/import_chargebacks.drush.inc
@@ -40,8 +40,6 @@
  *
  */
 function drush_import_chargebacks($processor=NULL, $filename=NULL){
-  require_once 'offline2civicrm.common.inc';
-
   if(!file_exists($filename)){
     watchdog('offline2civicrm', 'Import chargebacks: File does not exist: ' . 
$filename, array(), WATCHDOG_ERROR);
   }
@@ -49,93 +47,10 @@
   switch(strtoupper($processor)){
     case 'GLOBALCOLLECT':
       civicrm_initialize();
-      _offline2civicrm_import_chargebacks_globalcollect($filename);
+      ChargebacksFile::import($filename);
       break;
     default:
       watchdog('offline2civicrm', 'Import chargebacks: Unsupported processor' 
. $processor, array(), WATCHDOG_ERROR);
       return;
-  }
-}
-
-function _offline2civicrm_import_chargebacks_chargeback_trxn($contribution_id){
-
-  print "\tCharging back $contribution_id\n";
-
-  $contribution = civicrm_api("Contribution", "Get", array(
-    "version" => "3",
-    "id" => $contribution_id
-  ));
-
-  if(!WMFCiviAPICheck::check_api_contribution($contribution, 
$contribution_id)){
-    watchdog('offline2civicrm', "Contribution (id: $contribution_id) could not 
be loaded via CiviCRM API: " .
-      print_r($contribution, TRUE), NULL, WATCHDOG_ERROR);
-    return false;
-  }
-
-  $contribution_flat = WMFCiviAPICheck::check_api_simplify($contribution, 
$contribution_id);
-
-  if($contribution_flat === false){
-    watchdog('offline2civicrm', "Contribution could not be extracted from API 
response: " .
-      print_r($contribution, TRUE), NULL, WATCHDOG_ERROR);
-    return false;
-  }
-
-  $contribution = $contribution_flat;
-
-  if(substr($contribution["contribution_source"], 0, 3) == "RFD"){
-      // the contribution has already been charged back or refunded
-      return true;
-  }
-
-  $contribution["total_amount"] = "0.00";
-  $contribution["net_amount"] = "0.00";
-  $contribution["contribution_source"] = "RFD CHARGEDBACK (" . 
$contribution["contribution_source"] . ")";
-
-  $updated = civicrm_api("Contribution", "Update", array_merge($contribution, 
array('version' => '3',)));
-
-  watchdog('offline2civicrm', "Updated contribution: " . print_r($updated, 
true), NULL, WATCHDOG_INFO);
-
-  return true;
-
-}
-
-function _offline2civicrm_import_chargebacks_globalcollect($filename){
-  if( ( $file = fopen( $filename, 'r' )) === FALSE ){
-    watchdog('offline2civicrm', 'Import chargebacks: Could not open file for 
reading: ' . $filename, array(), WATCHDOG_ERROR);
-  }
-
-  try{
-    // GlobalCollect actually supplies a semicolon separated file
-    $headers = _load_headers( fgetcsv( $file, 0, ';') );
-
-    while( ( $row = fgetcsv( $file, 0, ';')) !== FALSE) {
-
-      $orderid = _get_value('Order ID', $row, $headers);
-      $effortid = _get_value('Effort ID', $row, $headers);
-
-      if($orderid == ''){
-        watchdog('offline2civicrm', "Invalid OrderID for chargeback on row", 
NULL, WATCHDOG_INFO);
-        continue;
-      }
-      if(intval($effortid) > 1){
-        // we only use the Effort ID on recurring transactions, and then only 
the subsequent ones
-        $orderid .= "-{$effortid}";
-      }
-
-      if ( $contributions = wmf_civicrm_get_contributions_from_gateway_id( 
'globalcollect', $orderid ) ) {
-        $contribution = array_shift( $contributions );
-      } else {
-        // still nothing, I'm outta guesses, lets break and give a human a try
-        watchdog('offline2civicrm', "Could not find transaction matching 
trxn_id: " .
-          print_r($row, TRUE), NULL, WATCHDOG_ERROR);
-        continue;
-      }
-
-      // execute the chargeback
-      _offline2civicrm_import_chargebacks_chargeback_trxn($contribution['id']);
-    }
-  } catch ( Exception $e ){
-    watchdog('offline2civicrm', 'Import chargebacks: Exception thrown during 
chargeback processing: ' .
-      print_r( $e, true ), array(), WATCHDOG_ERROR);
   }
 }
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.common.inc 
b/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
deleted file mode 100644
index 802d57a..0000000
--- a/sites/all/modules/offline2civicrm/offline2civicrm.common.inc
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/**
- * Loads the column headers into an array so that they can be used independent
- * of the column order when generating messages
- *
- * @param $row Array containing the column headers for the csv
- * @return Array mapping the header keys to the column index
- */
-function _load_headers( $row ){
-  $header_keys = array();
-
-  # trimming the " from each side
-  foreach( $row as $i => $k ) {
-    $header_keys[trim( $k, '"' )] = $i;
-  }
-  watchdog('offline2civicrm', 'Import checks: Column headers loaded from 
file', array(), WATCHDOG_INFO);
-
-  return $header_keys;
-}
-
-function _get_value( $column, $row, $headers, $default='' ){
-
-  if( !array_key_exists( $column, $headers ) ){
-    return $default;
-  } else {
-    $value = trim( $row[ $headers[ $column ] ] );
-    if ( empty( $value ) ) {
-      return $default;
-    }
-    return $value;
-  }
-}
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.info 
b/sites/all/modules/offline2civicrm/offline2civicrm.info
index 4f77dc4..89c5233 100755
--- a/sites/all/modules/offline2civicrm/offline2civicrm.info
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.info
@@ -1,10 +1,12 @@
 name = Offline Contribution to CiviCRM
 description = Imports offline contributions from a CSV
+package = Wikimedia
 core = 7.x
 dependencies[] = queue2civicrm
 dependencies[] = wmf_civicrm
 dependencies[] = wmf_communication
 dependencies[] = civicrm
-package = offline2civicrm
+files[] = ChargebacksFile.php
 files[] = ChecksFile.php
 files[] = ChecksImportLog.php
+files[] = CsvFile.php
diff --git a/sites/all/modules/offline2civicrm/offline2civicrm.module 
b/sites/all/modules/offline2civicrm/offline2civicrm.module
index 0a0582d..a67bc57 100644
--- a/sites/all/modules/offline2civicrm/offline2civicrm.module
+++ b/sites/all/modules/offline2civicrm/offline2civicrm.module
@@ -1,7 +1,5 @@
 <?php
 
-require_once 'offline2civicrm.common.inc';
-
 use wmf_communication\Templating;
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a6bbc134a197bae289beb261b5831aa6c253e30
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

Reply via email to