[freeside-commits] branch FREESIDE_2_3_BRANCH updated. ae4e0da4cd2dae3b7a8b50a8bb6be9ec419ac815

Ivan ivan at 420.am
Thu Jun 14 02:45:06 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  ae4e0da4cd2dae3b7a8b50a8bb6be9ec419ac815 (commit)
      from  7adee3e2e061d08fef5f47e0df8ac818db8d04d2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ae4e0da4cd2dae3b7a8b50a8bb6be9ec419ac815
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Jun 14 02:45:06 2012 -0700

    fix svc_broadband / svc_acct dangling services getting left behind w/radius groups (hopefully), RT#17826

diff --git a/FS/FS/svc_Radius_Mixin.pm b/FS/FS/svc_Radius_Mixin.pm
index 731c832..ac97eab 100644
--- a/FS/FS/svc_Radius_Mixin.pm
+++ b/FS/FS/svc_Radius_Mixin.pm
@@ -1,11 +1,14 @@
 package FS::svc_Radius_Mixin;
+use base qw( FS::m2m_Common FS::svc_Common );
 
 use strict;
-use base qw(FS::m2m_Common FS::svc_Common);
-use FS::Record qw(qsearch);
+use FS::Record qw( qsearch dbh );
 use FS::radius_group;
 use FS::radius_usergroup;
-use Carp qw(confess);
+use Carp qw( confess );
+
+# not really a mixin since it overrides insert/replace/delete and has svc_Common
+#  as a base class, should probably be renamed svc_Radius_Common
 
 =head1 NAME
 
@@ -17,15 +20,34 @@ FS::svc_Radius_Mixin - partial base class for services with RADIUS groups
 
 =cut
 
-
 sub insert {
   my $self = shift;
-  $self->SUPER::insert(@_)
-  || $self->process_m2m(
-    'link_table' => 'radius_usergroup',
-    'target_table' => 'radius_group',
-    'params' => $self->usergroup,
-  );
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error =  $self->SUPER::insert(@_)
+            || $self->process_m2m(
+                                   'link_table'   => 'radius_usergroup',
+                                   'target_table' => 'radius_group',
+                                   'params'       => $self->usergroup,
+                                 );
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 sub replace  {
@@ -33,22 +55,63 @@ sub replace  {
   my $old = shift;
   $old = $new->replace_old if !defined($old);
 
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
   $old->usergroup; # make sure this is cached for exports
-  $new->process_m2m(
-    'link_table' => 'radius_usergroup',
-    'target_table' => 'radius_group',
-    'params' => $new->usergroup,
-  ) || $new->SUPER::replace($old, @_);
+
+  my $error =  $new->process_m2m(
+                                 'link_table'   => 'radius_usergroup',
+                                 'target_table' => 'radius_group',
+                                 'params'       => $new->usergroup,
+                               )
+            || $new->SUPER::replace($old, @_);
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 sub delete {
   my $self = shift;
-  $self->SUPER::delete(@_)
-  || $self->process_m2m(
-    'link_table' => 'radius_usergroup',
-    'target_table' => 'radius_group',
-    'params' => [],
-  );
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error =  $self->SUPER::delete(@_)
+            || $self->process_m2m(
+                                   'link_table'   => 'radius_usergroup',
+                                   'target_table' => 'radius_group',
+                                   'params'       => [],
+                                 );
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 sub usergroup {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/svc_Radius_Mixin.pm |  105 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 84 insertions(+), 21 deletions(-)




More information about the freeside-commits mailing list