fix dangling RADIUS attributes on upgrade (and prevent new ones from showing up)...
authorIvan Kohler <ivan@freeside.biz>
Fri, 10 Mar 2017 19:42:24 +0000 (11:42 -0800)
committerIvan Kohler <ivan@freeside.biz>
Fri, 10 Mar 2017 19:42:24 +0000 (11:42 -0800)
FS/FS/Upgrade.pm
FS/FS/radius_attr.pm
FS/FS/radius_group.pm

index 8a3e83c..0a083db 100644 (file)
@@ -570,6 +570,7 @@ sub upgrade_schema_data {
     'cust_msg' => [],
     'cust_bill_pay_batch' => [],
     'cust_event_fee' => [],
+    'radius_attr' => [],
     #update records referencing removed things with their FKs
     'cust_pkg' => [],
   ;
index 16d3f62..1b7df2e 100644 (file)
@@ -3,7 +3,7 @@ use base qw( FS::Record );
 
 use strict;
 use vars qw( $noexport_hack );
-use FS::Record qw( qsearch ); #qsearchs );
+use FS::Record qw( qsearch dbh );
 
 $noexport_hack = 0;
 
@@ -202,6 +202,21 @@ sub ops {
 
 =back
 
+=cut
+
+sub _upgrade_schema {
+  my ($class, %opts) = @_;
+
+  my $sql = '
+    DELETE FROM radius_attr WHERE NOT EXISTS
+      ( SELECT 1 FROM radius_group WHERE radius_group.groupnum = radius_attr.groupnum )
+  ';
+
+  my $sth = dbh->prepare($sql) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  '';
+}
+
 =head1 BUGS
 
 =head1 SEE ALSO
index f1a4efe..21ce25f 100644 (file)
@@ -1,8 +1,8 @@
 package FS::radius_group;
+use base qw( FS::o2m_Common FS::Record );
 
 use strict;
-use base qw( FS::o2m_Common FS::Record );
-use FS::Record qw( qsearch qsearchs dbh );
+use FS::Record qw( qsearch dbh );
 use FS::radius_attr;
 
 =head1 NAME
@@ -125,6 +125,15 @@ sub delete {
       return $error;
     }
   }
+
+  foreach my $radius_attr ( $self->radius_attr ) {
+    $error = $radius_attr->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   dbh->commit;
   '';
 }