[freeside-commits] branch master updated. edd6a339eb7ea156272264ffd164711fc8af792e

Ivan ivan at 420.am
Wed Feb 1 09:32:32 PST 2017


The branch, master has been updated
       via  edd6a339eb7ea156272264ffd164711fc8af792e (commit)
       via  b9c9835fc3a990958b21bed560f1ff758735add0 (commit)
       via  148e5eb45acfa3b4da44330fa889cfbd1cd9c15d (commit)
       via  7c4fa413c85f69296f9f2be5796703f7700fb461 (commit)
       via  18af4f3316291938fa8f0a74e083209f62eac4fa (commit)
      from  d8dcec0a073b96794328195d4327e28b56996705 (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 edd6a339eb7ea156272264ffd164711fc8af792e
Merge: b9c9835 d8dcec0
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Feb 1 09:32:28 2017 -0800

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit b9c9835fc3a990958b21bed560f1ff758735add0
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Feb 1 09:32:26 2017 -0800

    fix Tokenized payinfo on upgrade if we can, RT#71513

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 62c50ad..1bf9dd6 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5452,8 +5452,8 @@ sub _upgrade_next_recnum {
             ' FROM '.$table.
             ' WHERE '.$tclass->primary_key.' > '.$$lastrecnum.
             "   AND payby IN ( 'CARD', 'DCRD', 'CHEK', 'DCHK' ) ".
-            "   AND ( length(payinfo) > 80 OR paycardtype = 'Tokenized' ) ".
-            ' ORDER BY '.$tclass->primary_key.' LIMIT 500';;
+            "   AND ( length(payinfo) < 80 OR paycardtype = 'Tokenized' ) ".
+            ' ORDER BY '.$tclass->primary_key.' LIMIT 500';
   my $sth = $dbh->prepare($sql) or die $dbh->errstr;
   $sth->execute() or die $sth->errstr;
   my @recnums;

commit 148e5eb45acfa3b4da44330fa889cfbd1cd9c15d
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Feb 1 09:20:35 2017 -0800

    fix Tokenized payinfo on upgrade if we can, RT#71513

diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 90256bd..62c50ad 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -5386,10 +5386,11 @@ sub queueable_upgrade {
     FS::upgrade_journal->set_done('clear_payinfo_history');
   }
 
-  # encrypt old records
-  if ( $conf->exists('encryption')
-         && ! FS::upgrade_journal->is_done('encryption_check')
-  ) {
+  # fix Tokenized paycardtype and encrypt old records
+  if (    ! FS::upgrade_journal->is_done('paycardtype_Tokenized')
+       || ! FS::upgrade_journal->is_done('encryption_check')
+     )
+  {
 
     # allow replacement of closed cust_pay/cust_refund records
     local $FS::payinfo_Mixin::allow_closed_replace = 1;
@@ -5419,6 +5420,7 @@ sub queueable_upgrade {
         if (!$record->custnum && $table eq 'cust_pay_pending') {
           $record->set('custnum_pending',1);
         }
+        $record->paycardtype('') if $record->paycardtype eq 'Tokenized';
 
         local($ignore_expired_card) = 1;
         local($ignore_banned_card) = 1;
@@ -5430,7 +5432,8 @@ sub queueable_upgrade {
       }
     }
 
-    FS::upgrade_journal->set_done('encryption_check');
+    FS::upgrade_journal->set_done('paycardtype_Tokenized');
+    FS::upgrade_journal->set_done('encryption_check') if $conf->exists('encryption');
   }
 
   # now that everything's encrypted, tokenize...
@@ -5448,6 +5451,8 @@ sub _upgrade_next_recnum {
   my $sql = 'SELECT '.$tclass->primary_key.
             ' FROM '.$table.
             ' WHERE '.$tclass->primary_key.' > '.$$lastrecnum.
+            "   AND payby IN ( 'CARD', 'DCRD', 'CHEK', 'DCHK' ) ".
+            "   AND ( length(payinfo) > 80 OR paycardtype = 'Tokenized' ) ".
             ' ORDER BY '.$tclass->primary_key.' LIMIT 500';;
   my $sth = $dbh->prepare($sql) or die $dbh->errstr;
   $sth->execute() or die $sth->errstr;

commit 7c4fa413c85f69296f9f2be5796703f7700fb461
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Feb 1 09:08:01 2017 -0800

    deal with the data we have as best we can without erroring out, RT#71513

diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm
index ac92623..7401eb9 100644
--- a/FS/FS/payinfo_Mixin.pm
+++ b/FS/FS/payinfo_Mixin.pm
@@ -197,10 +197,20 @@ sub payinfo_check {
 
   if ( $self->payby eq 'CARD' && ! $self->is_encrypted($self->payinfo) ) {
 
-    if ( $self->tokenized && ! $self->paycardtype ) {
-      return "paycardtype required (cannot be derived from a token)";
-    } else {
-      $self->set('paycardtype', cardtype($self->payinfo));
+    unless ( $self->paycardtype ) {
+
+      if ( $self->tokenized ) {
+        if ( $self->paymask =~ /^\d+x/ ) {
+          $self->set('paycardtype', cardtype($self->paymask));
+        } else {
+          $self->set('paycardtype', '');
+         # return "paycardtype required ".
+         #        "(can't derive from a token and no paymask w/prefix provided)";
+        }
+      } else {
+        $self->set('paycardtype', cardtype($self->payinfo));
+      }
+
     }
 
     if ( $ignore_masked_payinfo and $self->mask_payinfo eq $self->payinfo ) {
@@ -219,13 +229,22 @@ sub payinfo_check {
         $self->payinfo('N/A'); #??? re-masks card
       }
     }
+
   } else {
-    if ( $self->payby eq 'CARD' and $self->paymask ) {
-      # if we can't decrypt the card, at least detect the cardtype
-      $self->set('paycardtype', cardtype($self->paymask));
-    } else {
-      $self->set('paycardtype', '');
+
+    unless ( $self->paycardtype ) {
+
+      if ( $self->payby eq 'CARD' && $self->paymask =~ /^\d+x/  ) {
+        # if we can't decrypt the card, at least detect the cardtype
+        $self->set('paycardtype', cardtype($self->paymask));
+      } else {
+        $self->set('paycardtype', '');
+        # return "paycardtype required ".
+        #        "(can't derive from a token and no paymask w/prefix provided)";
+      }
+
     }
+
     if ( $self->is_encrypted($self->payinfo) ) {
       #something better?  all it would cause is a decryption error anyway?
       my $error = $self->ut_anything('payinfo');

commit 18af4f3316291938fa8f0a74e083209f62eac4fa
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Jan 31 19:17:13 2017 -0800

    further optimize condition_sql for "Invoice eligible for automatic collection" condition, RT#74451

diff --git a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
index 0276255..d782c12 100644
--- a/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
+++ b/FS/FS/part_event/Condition/cust_bill_hasnt_noauto.pm
@@ -26,32 +26,18 @@ sub condition {
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
   
-  # XXX: can be made faster with optimizations?
-  # -remove some/all sub-selects?
-  # -remove the two main separate selects?
-
-  "0 = (select count(1) from cust_pkg 
-            where cust_pkg.no_auto = 'Y' and cust_pkg.pkgnum in
-                (select distinct cust_bill_pkg.pkgnum 
-                    from cust_bill_pkg, cust_pkg 
-                    where cust_bill_pkg.pkgnum = cust_pkg.pkgnum
-                        and cust_bill_pkg.invnum = cust_bill.invnum
-                        and cust_bill_pkg.pkgnum > 0
-                )
-        )
-   AND
-   0 = (select count(1) from part_pkg 
-            where part_pkg.no_auto = 'Y' and part_pkg.pkgpart in
-                (select cust_pkg.pkgpart from cust_pkg 
-                    where pkgnum in 
-                        (select distinct cust_bill_pkg.pkgnum 
-                            from cust_bill_pkg, cust_pkg 
-                            where cust_bill_pkg.pkgnum = cust_pkg.pkgnum 
-                                and cust_bill_pkg.invnum = cust_bill.invnum
-                                and cust_bill_pkg.pkgnum > 0
-                        ) 
-                )
-        )
+  # can be made still faster with optimizations?
+
+  "NOT EXISTS ( SELECT 1 FROM cust_pkg 
+                           LEFT JOIN part_pkg USING (pkgpart)
+                  WHERE ( cust_pkg.no_auto = 'Y' OR part_pkg.no_auto = 'Y' )
+                    AND cust_pkg.pkgnum IN
+                          ( SELECT DISTINCT cust_bill_pkg.pkgnum 
+                              FROM cust_bill_pkg
+                              WHERE cust_bill_pkg.invnum = cust_bill.invnum
+                                AND cust_bill_pkg.pkgnum > 0
+                          )
+              )
   ";
 }
 

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

Summary of changes:
 FS/FS/cust_main.pm                                 |   17 +++++----
 .../part_event/Condition/cust_bill_hasnt_noauto.pm |   38 +++++++-------------
 FS/FS/payinfo_Mixin.pm                             |   37 ++++++++++++++-----
 3 files changed, 51 insertions(+), 41 deletions(-)




More information about the freeside-commits mailing list