X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-sqlradius-reset;h=7d1d34336417dbc99b61f1c5820ce95f77f072a3;hb=04a69f9d197efee6fa396bd35d04ae553e669978;hp=2ac5012d4843106340cdabdda90c5b3dcc2638a7;hpb=803369ee5939d4b82a1784b392f2264a05acabf7;p=freeside.git diff --git a/FS/bin/freeside-sqlradius-reset b/FS/bin/freeside-sqlradius-reset index 2ac5012d4..7d1d34336 100755 --- a/FS/bin/freeside-sqlradius-reset +++ b/FS/bin/freeside-sqlradius-reset @@ -1,12 +1,16 @@ #!/usr/bin/perl -w use strict; +use vars qw( $opt_n ); +use Getopt::Std; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::part_export; -use FS::svc_acct; +#use FS::svc_acct; use FS::cust_svc; +getopts("n"); + my $user = shift or die &usage; adminsuidsetup $user; @@ -15,7 +19,7 @@ adminsuidsetup $user; my @exports = (); if ( @ARGV ) { foreach my $exportnum ( @ARGV ) { - foreach my $exporttype (qw( sqlradius sqlradius_withdomain )) { + foreach my $exporttype (qw( sqlradius sqlradius_withdomain phone_sqlradius )) { push @exports, qsearch('part_export', { exportnum => $exportnum, exporttype => $exporttype, } ); } @@ -25,34 +29,43 @@ if ( @ARGV ) { push @exports, qsearch('part_export', { exporttype=>'sqlradius_withdomain' } ); } -foreach my $export ( @exports ) { - my $icradius_dbh = DBI->connect( - map { $export->option($_) } qw( datasrc username password ) - ) or die $DBI::errstr; - for my $table (qw( radcheck radreply usergroup )) { - my $sth = $icradius_dbh->prepare("DELETE FROM $table"); - $sth->execute or die "Can't reset $table table: ". $sth->errstr; +unless ( $opt_n ) { + foreach my $export ( @exports ) { + my $icradius_dbh = DBI->connect( + map { $export->option($_) } qw( datasrc username password ) + ) or die $DBI::errstr; + for my $table (qw( radcheck radreply usergroup )) { + my $sth = $icradius_dbh->prepare("DELETE FROM $table"); + $sth->execute or die "Can't reset $table table: ". $sth->errstr; + } + $icradius_dbh->disconnect; } - $icradius_dbh->disconnect; } foreach my $export ( @exports ) { #my @svcparts = map { $_->svcpart } $export->export_svc; + my $overlimit_groups = $export->option('overlimit_groups'); + + my @svc_x = + map { $_->svc_x } + map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } + $export->export_svc; - my @svc_acct = - map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) } - map { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } - grep { qsearch('cust_svc', { 'svcpart' => $_->svcpart } ) } - $export->export_svc; + foreach my $svc_x ( @svc_x ) { - foreach my $svc_acct ( @svc_acct ) { + $svc_x->check; #set any fixed usergroup so it'll export even if all + #svc_acct records don't have the group yet - $svc_acct->check; #set any fixed usergroup so it'll export even if all - #svc_acct records don't have the group yet + if ($overlimit_groups && $svc_x->overlimit) { + $svc_x->usergroup( &{ $svc_x->_fieldhandlers->{'usergroup'} } + ($svc_x, $overlimit_groups) + ); + } #false laziness with FS::svc_acct::insert (like it matters) - my $error = $export->export_insert($svc_acct); + my $error = $export->export_insert($svc_x); die $error if $error; } @@ -68,7 +81,7 @@ freeside-sqlradius-reset - Command line interface to reset and recreate RADIUS S =head1 SYNOPSIS - freeside-sqlradius-reset username [ EXPORTNUM, ... ] + freeside-sqlradius-reset [ -n ] username [ EXPORTNUM, ... ] =head1 DESCRIPTION @@ -78,11 +91,13 @@ specified, for all sqlradius and sqlradius_withdomain exports. B is a username added by freeside-adduser. +The B<-n> option, if supplied, supresses the deletion of the existing data in +the tables. + =head1 SEE ALSO L, L, L =cut - - +1;