prevent multiple additions to usergroup table (work around #1606)
[freeside.git] / FS / FS / part_export / sqlradius.pm
index 5bf9b7a..114ca0b 100644 (file)
@@ -33,7 +33,7 @@ tie %options, 'Tie::IxHash',
   },
   'overlimit_groups' => { label => 'Radius groups to assign to svc_acct which has exceeded its bandwidth or time limit', } ,
   'groups_susp_reason' => { label =>
-                             'Radius group mapping to reason (via template user)',
+                             'Radius group mapping to reason (via template user) (svcnum|username|username@domain  reasonnum|reason)',
                             type  => 'textarea',
                           },
 
@@ -374,10 +374,17 @@ sub sqlradius_usergroup_insert { #subroutine, not method
   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;
+    next if $s_sth->fetchrow_arrayref->[0];
     $sth->execute( $username, $group )
       or die "can't insert into groupname table: ". $sth->errstr;
   }