1 package FS::svc_Radius_Mixin;
2 use base qw( FS::m2m_Common FS::svc_Common );
5 use FS::Record qw( qsearch dbh );
7 use FS::radius_usergroup;
8 use Carp qw( confess );
10 # not really a mixin since it overrides insert/replace/delete and has svc_Common
11 # as a base class, should probably be renamed svc_Radius_Common
15 FS::svc_Radius_Mixin - partial base class for services with RADIUS groups
26 local $SIG{HUP} = 'IGNORE';
27 local $SIG{INT} = 'IGNORE';
28 local $SIG{QUIT} = 'IGNORE';
29 local $SIG{TERM} = 'IGNORE';
30 local $SIG{TSTP} = 'IGNORE';
31 local $SIG{PIPE} = 'IGNORE';
33 my $oldAutoCommit = $FS::UID::AutoCommit;
34 local $FS::UID::AutoCommit = 0;
37 my $error = $self->SUPER::insert(@_)
38 || $self->process_m2m(
39 'link_table' => 'radius_usergroup',
40 'target_table' => 'radius_group',
41 'params' => $self->usergroup,
45 $dbh->rollback if $oldAutoCommit;
49 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
56 $old = $new->replace_old if !defined($old);
58 local $SIG{HUP} = 'IGNORE';
59 local $SIG{INT} = 'IGNORE';
60 local $SIG{QUIT} = 'IGNORE';
61 local $SIG{TERM} = 'IGNORE';
62 local $SIG{TSTP} = 'IGNORE';
63 local $SIG{PIPE} = 'IGNORE';
65 my $oldAutoCommit = $FS::UID::AutoCommit;
66 local $FS::UID::AutoCommit = 0;
69 $old->usergroup; # make sure this is cached for exports
71 my $error = $new->check # make sure fixed fields are set before process_m2m
73 'link_table' => 'radius_usergroup',
74 'target_table' => 'radius_group',
75 'params' => $new->usergroup,
77 || $new->SUPER::replace($old, @_);
80 $dbh->rollback if $oldAutoCommit;
84 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
91 local $SIG{HUP} = 'IGNORE';
92 local $SIG{INT} = 'IGNORE';
93 local $SIG{QUIT} = 'IGNORE';
94 local $SIG{TERM} = 'IGNORE';
95 local $SIG{TSTP} = 'IGNORE';
96 local $SIG{PIPE} = 'IGNORE';
98 my $oldAutoCommit = $FS::UID::AutoCommit;
99 local $FS::UID::AutoCommit = 0;
102 my $error = $self->SUPER::delete(@_)
103 || $self->process_m2m(
104 'link_table' => 'radius_usergroup',
105 'target_table' => 'radius_group',
110 $dbh->rollback if $oldAutoCommit;
114 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
121 if ( defined $value ) {
123 return $self->set('usergroup', $value);
126 return $self->set('usergroup', [ split(/\s*,\s*/, $value) ]);
129 $self->get('usergroup') ||
130 # if no argument is passed and usergroup is not set already,
131 # fetch this service's group assignments
132 $self->set('usergroup',
133 [ map { $_->groupnum }
134 qsearch('radius_usergroup', { svcnum => $self->svcnum }) ]
140 'usergroup' => \&usergroup
144 =item radius_groups METHOD
146 Returns a list of RADIUS groups for this service (see L<FS::radius_usergroup>).
147 METHOD is the field to return, and can be any method on L<FS::radius_group>.
148 Useful values for METHOD include 'groupnum', 'groupname', and
149 'long_description'. Defaults to 'groupname' for historical reasons.
155 my $method = shift || 'groupname';
156 my $groups = join(',', @{$self->usergroup}) || return ();
157 my @groups = qsearch({'table' => 'radius_group',
158 'extra_sql' => "where groupnum in ($groups)"});
159 return map {$_->$method} @groups;