[freeside-commits] branch FREESIDE_4_BRANCH updated. 02efed3da5453ada38ba386c7226fcfd99b44ba3

Mark Wells mark at 420.am
Thu May 19 16:59:55 PDT 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  02efed3da5453ada38ba386c7226fcfd99b44ba3 (commit)
      from  71b0cae95c75843bcb80855b696d49d4752dbe35 (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 02efed3da5453ada38ba386c7226fcfd99b44ba3
Author: Mark Wells <mark at freeside.biz>
Date:   Thu May 19 16:57:06 2016 -0700

    fix some dangling records on upgrade, #32456 and #38765

diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 1aae55d..4889ff7 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -529,7 +529,9 @@ sub upgrade_schema_data {
     'cust_bill_pkg_detail' => [],
     #add necessary columns to RT schema
     'TicketSystem' => [],
-
+    #remove possible dangling records
+    'password_history' => [],
+    'cust_pay_pending' => [],
   ;
 
   \%hash;
diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm
index 1a54203..dfb07b8 100644
--- a/FS/FS/cust_pay_pending.pm
+++ b/FS/FS/cust_pay_pending.pm
@@ -470,6 +470,19 @@ sub _upgrade_data {  #class method
 
 }
 
+sub _upgrade_schema {
+  my ($class, %opts) = @_;
+
+  # fix records where jobnum points to a nonexistent queue job
+  my $sql = 'UPDATE cust_pay_pending SET jobnum = NULL
+    WHERE NOT EXISTS (
+      SELECT 1 FROM queue WHERE queue.jobnum = cust_pay_pending.jobnum
+    )';
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  '';
+}
+
 =back
 
 =head1 BUGS
diff --git a/FS/FS/password_history.pm b/FS/FS/password_history.pm
index dd527b9..a34f616 100644
--- a/FS/FS/password_history.pm
+++ b/FS/FS/password_history.pm
@@ -160,6 +160,29 @@ sub password_equals {
 
 }
 
+sub _upgrade_schema {
+  # clean up history records where linked_acct has gone away
+  my @where;
+  for my $fk ( grep /__/, __PACKAGE__->dbdef_table->columns ) {
+    my ($table, $key) = split(/__/, $fk);
+    push @where, "
+      ( $fk IS NOT NULL AND NOT EXISTS(SELECT 1 FROM $table WHERE $table.$key = $fk) )";
+  }
+  my @recs = qsearch({
+      'table'     => 'password_history',
+      'extra_sql' => ' WHERE ' . join(' AND ', @where),
+  });
+  my $error;
+  if (@recs) {
+    warn "Removing unattached password_history records (".scalar(@recs).").\n";
+    foreach my $password_history (@recs) {
+      $error = $password_history->delete;
+      die $error if $error;
+    }
+  }
+  '';
+}
+
 =back
 
 =head1 BUGS

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

Summary of changes:
 FS/FS/Upgrade.pm          |    4 +++-
 FS/FS/cust_pay_pending.pm |   13 +++++++++++++
 FS/FS/password_history.pm |   23 +++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)




More information about the freeside-commits mailing list