use FS::part_export;
use FS::svc_acct;
use FS::export_svc;
+use Carp qw( cluck );
@ISA = qw(FS::part_export);
}
my @groups = $svc_acct->radius_groups;
if ( @groups ) {
+ cluck localtime(). ": queuing usergroup_insert for ". $svc_acct->svcnum.
+ " (". $self->export_username($svc_acct). " with ". join(", ", @groups)
+ if $DEBUG;
my $err_or_queue = $self->sqlradius_queue(
$svc_acct->svcnum, 'usergroup_insert',
$self->export_username($svc_acct), @groups );
my $dbh = sqlradius_connect(shift, shift, shift);
my( $username, @groups ) = @_;
+ my $s_sth = $dbh->prepare(
+ "SELECT COUNT(*) FROM usergroup WHERE UserName = ? AND GroupName = ?"
+ ) or die $dbh->errstr;
+
my $sth = $dbh->prepare(
"INSERT INTO usergroup ( UserName, GroupName ) VALUES ( ?, ? )"
) or die $dbh->errstr;
+
foreach my $group ( @groups ) {
+ $s_sth->execute( $username, $group ) or die $s_sth->errstr;
+ if ($s_sth->fetchrow_arrayref->[0]) {
+ warn localtime() . ": sqlradius_usergroup_insert attempted to reinsert " .
+ "$group for $username\n"
+ if $DEBUG;
+ next;
+ }
$sth->execute( $username, $group )
or die "can't insert into groupname table: ". $sth->errstr;
}
}
if ( @newgroups ) {
+ cluck localtime(). ": queuing usergroup_insert for $svcnum ($username) ".
+ "with ". join(", ", @newgroups)
+ if $DEBUG;
my $err_or_queue = $self->sqlradius_queue( $svcnum, 'usergroup_insert',
$username, @newgroups );
return $err_or_queue