#!/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::cust_svc;
+getopts("n");
+
my $user = shift or die &usage;
adminsuidsetup $user;
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_acct =
map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
foreach my $svc_acct ( @svc_acct ) {
+ $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_acct->overlimit) {
+ $svc_acct->usergroup( &{ $svc_acct->_fieldhandlers->{'usergroup'} }
+ ($svc_acct, $overlimit_groups)
+ );
+ }
+
#false laziness with FS::svc_acct::insert (like it matters)
my $error = $export->export_insert($svc_acct);
die $error if $error;
=head1 SYNOPSIS
- freeside-sqlradius-reset username [ EXPORTNUM, ... ]
+ freeside-sqlradius-reset [ -n ] username [ EXPORTNUM, ... ]
=head1 DESCRIPTION
B<username> 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<freeside-reexport>, L<FS::part_export>, L<FS::part_export::sqlradius>