fix some dangling records on upgrade, #32456 and #38765
[freeside.git] / FS / FS / cust_pay_pending.pm
index 1a54203..dfb07b8 100644 (file)
@@ -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