From 4266969f2c69f6fc07672f118b86716f52a95b86 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 9 Mar 2017 12:53:27 -0800 Subject: [PATCH] fix upgrade for cust_bill_pay_batch when a batched payment was deleted by legacy code in the past, RT#75089 --- FS/FS/Upgrade.pm | 1 + FS/FS/cust_bill_pay_batch.pm | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 727663893..db993725c 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -568,6 +568,7 @@ sub upgrade_schema_data { 'pkg_referral' => [], 'cust_bill_pkg_discount' => [], 'cust_msg' => [], + 'cust_bill_pay_batch' => [], #update records referencing removed things with their FKs 'cust_pkg' => [], ; diff --git a/FS/FS/cust_bill_pay_batch.pm b/FS/FS/cust_bill_pay_batch.pm index 8a8bef315..a9d07d3a8 100644 --- a/FS/FS/cust_bill_pay_batch.pm +++ b/FS/FS/cust_bill_pay_batch.pm @@ -2,6 +2,7 @@ package FS::cust_bill_pay_batch; use base qw( FS::Record ); use strict; +use FS::Record qw( dbh ); =head1 NAME @@ -103,6 +104,24 @@ sub check { =back +=cut + + +sub _upgrade_schema { + my ($class, %opts) = @_; + + my $sql = ' + DELETE FROM cust_bill_pay_batch WHERE NOT EXISTS + ( SELECT 1 FROM cust_pay_batch WHERE cust_pay_batch.paybatchnum = cust_bill_pay_batch.paybatchnum ) + '; + + my $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + ''; + +} + + =head1 BUGS Just hangs there. -- 2.11.0