RT# 82942 Replace DBI->connect() with FS::DBI->connect()
[freeside.git] / FS / FS / part_export / sqlradius.pm
index dcb20bc..dfe4c3d 100644 (file)
@@ -11,6 +11,7 @@ use FS::export_svc;
 use Carp qw( cluck );
 use NEXT;
 use Net::OpenSSH;
+use FS::DBI;
 
 @ISA = qw(FS::part_export);
 @EXPORT_OK = qw( sqlradius_connect );
@@ -26,6 +27,10 @@ tie %options, 'Tie::IxHash',
                    type    => 'select',
                    options => [qw( usergroup radusergroup ) ],
                  },
+  'skip_provisioning' => {
+    type  => 'checkbox',
+    label => 'Skip provisioning records to this database'
+  },
   'ignore_accounting' => {
     type  => 'checkbox',
     label => 'Ignore accounting records from this database'
@@ -80,10 +85,6 @@ tie %options, 'Tie::IxHash',
   'disconnect_port' => {
     label => 'Port to send disconnection requests to, default 1700',
   },
-  'disconnect_ignore_error' => {
-    label => 'Ignore disconnection request errors',
-    type => 'checkbox',
-  },
 ;
 
 $notes1 = <<'END';
@@ -158,6 +159,8 @@ sub radius_check { #override for other svcdb
 sub _export_insert {
   my($self, $svc_x) = (shift, shift);
 
+  return '' if $self->option('skip_provisioning');
+
   foreach my $table (qw(reply check)) {
     my $method = "radius_$table";
     my %attrib = $self->$method($svc_x);
@@ -183,6 +186,8 @@ sub _export_insert {
 sub _export_replace {
   my( $self, $new, $old ) = (shift, shift, shift);
 
+  return '' if $self->option('skip_provisioning');
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -270,7 +275,6 @@ sub _export_replace {
       'disconnect_ssh'    => $self->option('disconnect_ssh'),
       'svc_acct_username' => $old->username,
       'disconnect_port'   => $self->option('disconnect_port'),
-      'ignore_error'      => $self->option('disconnect_ignore_error'),
     );
     unless ( ref($err_or_queue) ) {
       $dbh->rollback if $oldAutoCommit;
@@ -294,6 +298,8 @@ sub _export_replace {
 sub _export_suspend {
   my( $self, $svc_acct ) = (shift, shift);
 
+  return '' if $self->option('skip_provisioning');
+
   my $new = $svc_acct->clone_suspended;
   
   local $SIG{HUP} = 'IGNORE';
@@ -365,6 +371,8 @@ sub _export_suspend {
 sub _export_unsuspend {
   my( $self, $svc_x ) = (shift, shift);
 
+  return '' if $self->option('skip_provisioning');
+
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE';
@@ -404,6 +412,8 @@ sub _export_unsuspend {
 sub _export_delete {
   my( $self, $svc_x ) = (shift, shift);
 
+  return '' if $self->option('skip_provisioning');
+
   my $jobnum = '';
 
   my $usergroup = $self->option('usergroup') || 'usergroup';
@@ -418,7 +428,6 @@ sub _export_delete {
       'disconnect_ssh'    => $self->option('disconnect_ssh'),
       'svc_acct_username' => $svc_x->username,
       'disconnect_port'   => $self->option('disconnect_port'),
-      'ignore_error'      => $self->option('disconnect_ignore_error'),
     );
     return $err_or_queue unless ref($err_or_queue);
     if ( $jobnum ) {
@@ -616,7 +625,7 @@ sub sqlradius_delete { #subroutine, not method
 sub sqlradius_connect {
   #my($datasrc, $username, $password) = @_;
   #DBI->connect($datasrc, $username, $password) or die $DBI::errstr;
-  DBI->connect(@_) or die $DBI::errstr;
+  FS::DBI->connect(@_) or die $FS::DBI::errstr;
 }
 
 # on success, returns '' in scalar context, ('',$jobnum) in list context
@@ -1255,8 +1264,6 @@ I<svc_acct_username> - the user to be disconnected (required)
 
 I<disconnect_port> - the port (on the nas) to send disconnect requests to (defaults to 1700)
 
-I<ignore_error> - do not die on error with the disconnect request
-
 Note this is NOT the opposite of sqlradius_connect.
 
 =cut
@@ -1291,7 +1298,7 @@ sub sqlradius_user_disconnect {
     if $error && (@$nas > 1);
   $error = "No clients found"
     unless @$nas;
-  die $error if $error && !$opt{'ignore_error'};
+  die $error if $error;
   return '';
 }
 
@@ -1314,10 +1321,10 @@ sub _upgrade_exporttype {
 
 sub import_attrs {
   my $self = shift;
-  my $dbh =  DBI->connect( map $self->option($_),
+  my $dbh =  FS::DBI->connect( map $self->option($_),
                                    qw( datasrc username password ) );
   unless ( $dbh ) {
-    warn "Error connecting to RADIUS server: $DBI::errstr\n";
+    warn "Error connecting to RADIUS server: $FS::DBI::errstr\n";
     return;
   }