diff options
author | Ivan Kohler <ivan@freeside.biz> | 2017-03-10 12:02:32 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2017-03-10 12:02:32 -0800 |
commit | 67ae4f570a0092d0e3b6852572aa47e96a8adb46 (patch) | |
tree | 495d607e0efa16aa4c22014e4bb9d48ec6f37cb7 | |
parent | 4b0392ecbf8f912ce1499cd243b78cb51512aef8 (diff) |
fix upgrade of cust_pay_pending for deleted customers, RT#75118
-rw-r--r-- | FS/FS/cust_pay_pending.pm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/FS/FS/cust_pay_pending.pm b/FS/FS/cust_pay_pending.pm index d1083411c..8f313f422 100644 --- a/FS/FS/cust_pay_pending.pm +++ b/FS/FS/cust_pay_pending.pm @@ -504,6 +504,16 @@ sub _upgrade_schema { )'; my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; + + # fix records where custnum points to a nonexistent customer + $sql = 'UPDATE cust_pay_pending SET custnum = NULL + WHERE NOT EXISTS ( + SELECT 1 FROM cust_main WHERE cust_main.custnum = cust_pay_pending.custnum + )'; + $sth = dbh->prepare($sql) or die dbh->errstr; + $sth->execute or die $sth->errstr; + + ''; } |