add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / cust_pay_pending.pm
index 63274b1..dfb07b8 100644 (file)
@@ -393,6 +393,8 @@ sub approve {
       warn $e;
       return $e;
     }
+    
+    $self->set('jobnum','');
   }
 
   if ( $opt{'paynum_ref'} ) {
@@ -468,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