X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_pay_pending.pm;h=8f313f422117a553531cb3ca4932df6410d335f1;hp=d1083411c0031cfbcaf928beb96f647ea1c0c206;hb=5372897f367498972c96f5494e142e6e11b29eb8;hpb=5ed934c7206d2fc2aef1911ec29be83b9a028625 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; + + ''; }