fix upgrade for dangling cust_event_fee (how?), RT#75113
authorIvan Kohler <ivan@freeside.biz>
Fri, 10 Mar 2017 18:14:03 +0000 (10:14 -0800)
committerIvan Kohler <ivan@freeside.biz>
Fri, 10 Mar 2017 18:14:03 +0000 (10:14 -0800)
FS/FS/Upgrade.pm
FS/FS/cust_event_fee.pm

index db99372..8a3e83c 100644 (file)
@@ -569,6 +569,7 @@ sub upgrade_schema_data {
     'cust_bill_pkg_discount' => [],
     'cust_msg' => [],
     'cust_bill_pay_batch' => [],
     'cust_bill_pkg_discount' => [],
     'cust_msg' => [],
     'cust_bill_pay_batch' => [],
+    'cust_event_fee' => [],
     #update records referencing removed things with their FKs
     'cust_pkg' => [],
   ;
     #update records referencing removed things with their FKs
     'cust_pkg' => [],
   ;
index 375a533..5db4039 100644 (file)
@@ -1,8 +1,8 @@
 package FS::cust_event_fee;
 package FS::cust_event_fee;
+use base qw( FS::Record FS::FeeOrigin_Mixin );
 
 use strict;
 
 use strict;
-use base qw( FS::Record FS::FeeOrigin_Mixin );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch dbh );
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -194,6 +194,24 @@ sub cust_pkg {
   }
 }
 
   }
 }
 
+=back
+
+=cut
+
+sub _upgrade_schema {
+  my ($class, %opts) = @_;
+
+  my $sql = '
+    DELETE FROM cust_event_Fee WHERE NOT EXISTS
+      ( SELECT 1 FROM cust_event WHERE cust_event.eventnum = cust_event_fee.eventnum )
+  ';
+
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  '';
+}
+
+
 =head1 BUGS
 
 =head1 SEE ALSO
 =head1 BUGS
 
 =head1 SEE ALSO