X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_pay.pm;h=0e9e8a716bf00c1a26e01874110a1d321fc0e497;hb=7b5a266236857fbb4bbf8d4ac3031c3fec75cac2;hp=4535aadb2dd85b044bc86826c8d743d809a0422e;hpb=7a618d4493ab7a87f6eabfd1ce3630a6b3436c2f;p=freeside.git diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 4535aadb2..0e9e8a716 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -1032,18 +1032,48 @@ 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')) { + local $FS::Record::nowarn_classload=1; # really inefficient, but again, only has to run once foreach my $table (qw(cust_pay cust_pay_void cust_refund)) { + my $and_batchnum_is_null = + ( $table =~ /^cust_pay/ ? ' AND batchnum IS NULL' : '' ); 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 + $and_batchnum_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; + } + # if the paybatch didn't have an auth string, then it's fine + $h->paybatch =~ /:(\w+):/ or 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 #". @@ -1052,7 +1082,7 @@ sub _upgrade_data { #class method } } #$object } #$table - FS::upgrade_journal->set_done('cust_pay__parse_paybatch'); + FS::upgrade_journal->set_done('cust_pay__parse_paybatch_1'); } }