[freeside-commits] branch master updated. 66631c3f1b7c9c2a532f04eded5a472fcf780a00

Mark Wells mark at 420.am
Mon Mar 18 13:45:44 PDT 2013


The branch, master has been updated
       via  66631c3f1b7c9c2a532f04eded5a472fcf780a00 (commit)
      from  8a26002c6bf6d2c42df5eb90ed760accb71acbb7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 66631c3f1b7c9c2a532f04eded5a472fcf780a00
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Mar 18 13:45:14 2013 -0700

    fix upgrade of cust_pay.auth, #18548

diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index 4535aad..fa5672c 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -1032,18 +1032,42 @@ sub _upgrade_data {  #class method
   ###
 
   # not only cust_pay, but also voided and refunded payments
-  if (!FS::upgrade_journal->is_done('cust_pay__parse_paybatch')) {
+  if (!FS::upgrade_journal->is_done('cust_pay__parse_paybatch_1')) {
     # really inefficient, but again, only has to run once
     foreach my $table (qw(cust_pay cust_pay_void cust_refund)) {
       foreach my $object ( qsearch({
             table     => $table,
             extra_sql => "WHERE payby IN('CARD','CHEK') ".
-                         "AND paybatch IS NOT NULL",
+                         "AND (paybatch IS NOT NULL ".
+                         "OR (paybatch IS NULL AND auth IS NULL) )",
           }) )
       {
+        if ( $object->paybatch eq '' ) {
+          # repair for a previous upgrade that didn't save 'auth'
+          my $pkey = $object->primary_key;
+          # find the last history record that had a paybatch value
+          my $h = qsearchs({
+              table   => "h_$table",
+              hashref => {
+                $pkey     => $object->$pkey,
+                paybatch  => { op=>'!=', value=>''},
+                history_action => 'replace_old',
+              },
+              order_by => 'ORDER BY history_date DESC LIMIT 1',
+          });
+          if (!$h) {
+            warn "couldn't find paybatch history record for $table ".$object->$pkey."\n";
+            next;
+          }
+          # set paybatch to what it was in that record
+          $object->set('paybatch', $h->paybatch)
+          # and then upgrade it like the old records
+        }
+
         my $parsed = $object->_parse_paybatch;
         if (keys %$parsed) {
           $object->set($_ => $parsed->{$_}) foreach keys %$parsed;
+          $object->set('auth' => $parsed->{authorization});
           $object->set('paybatch', '');
           my $error = $object->replace;
           warn "error parsing CARD/CHEK paybatch fields on $object #".

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_pay.pm |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)




More information about the freeside-commits mailing list