summaryrefslogtreecommitdiff
path: root/FS/FS/cust_pkg.pm
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2017-02-24 10:22:29 -0800
committerIvan Kohler <ivan@freeside.biz>2017-02-24 10:22:29 -0800
commit3951dc9619a5a0c5f148e89754ddd4ce54ede281 (patch)
tree6ba36a2f761e8ce9584cfbd928f8b19855e5d604 /FS/FS/cust_pkg.pm
parent7e67fa95effacabe5380653ccdab3957f10931c0 (diff)
fix upgrades when cust_pkg.change_to_pkgnum points to a package that was removed, RT#74825
Diffstat (limited to 'FS/FS/cust_pkg.pm')
-rw-r--r--FS/FS/cust_pkg.pm17
1 files changed, 17 insertions, 0 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index bd9ab81..3d54439 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -5565,6 +5565,23 @@ sub forward_emails {
}
# Used by FS::Upgrade to migrate to a new database.
+sub _upgrade_schema { # class method
+ my ($class, %opts) = @_;
+
+ my $sql = '
+ UPDATE cust_pkg SET change_to_pkgnum = NULL
+ WHERE change_to_pkgnum IS NOT NULL
+ AND NOT EXISTS ( SELECT 1 FROM cust_pkg AS ctcp
+ WHERE ctcp.pkgnum = cust_pkg.change_to_pkgnum
+ )
+ ';
+
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute or die $sth->errstr;
+ '';
+}
+
+# Used by FS::Upgrade to migrate to a new database.
sub _upgrade_data { # class method
my ($class, %opts) = @_;
$class->_upgrade_otaker(%opts);