1 package FS::radius_usergroup;
2 use base qw(FS::Record);
5 use FS::Record qw( qsearch qsearchs );
11 FS::radius_usergroup - Object methods for radius_usergroup records
15 use FS::radius_usergroup;
17 $record = new FS::radius_usergroup \%hash;
18 $record = new FS::radius_usergroup { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::radius_usergroup object links an account (see L<FS::svc_acct>) with a
31 RADIUS group (see L<FS::radius_group>). FS::radius_usergroup inherits from
32 FS::Record. The following fields are currently supported:
36 =item usergroupnum - primary key
38 =item svcnum - Account (see L<FS::svc_acct>).
40 =item groupnum - RADIUS group (see L<FS::radius_group>).
50 Creates a new record. To add the record to the database, see L<"insert">.
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to. You can ask the object for a copy with the I<hash> method.
57 # the new method can be inherited from FS::Record, if a table method is defined
59 sub table { 'radius_usergroup'; }
63 Adds this record to the database. If there is an error, returns the error,
64 otherwise returns false.
68 #inherited from FS::Record
72 Delete this record from the database.
76 #inherited from FS::Record
78 =item replace OLD_RECORD
80 Replaces the OLD_RECORD with this one in the database. If there is an error,
81 returns the error, otherwise returns false.
85 #inherited from FS::Record
89 Checks all fields to make sure this is a valid record. If there is
90 an error, returns the error, otherwise returns false. Called by the insert
97 my $svcnum = $self->svcnum;
98 die "radius_usergroup.groupname is deprecated" if $self->groupname;
100 $self->ut_numbern('usergroupnum')
101 || ( $self->ut_foreign_key('svcnum','svc_acct','svcnum')
102 && $self->ut_foreign_key('svcnum','svc_broadband','svcnum')
103 && "Can't find radius_usergroup.svcnum $svcnum in svc_acct.svcnum or svc_broadband.svcnum" )
104 || $self->ut_foreign_key('groupnum','radius_group','groupnum')
105 || $self->SUPER::check
111 Returns the account associated with this record (see L<FS::svc_acct> and
112 L<FS::svc_broadband>).
118 qsearchs('svc_acct', { svcnum => $self->svcnum } ) ||
119 qsearchs('svc_broadband', { svcnum => $self->svcnum } )
124 Returns the RADIUS group associated with this record (see L<FS::radius_group>).
128 sub _upgrade_data { #class method
129 my ($class, %opts) = @_;
131 my %group_cache = map { $_->groupname => $_->groupnum }
132 qsearch('radius_group', {});
134 my @radius_usergroup = qsearch('radius_usergroup', {} );
136 foreach my $rug ( @radius_usergroup ) {
137 my $groupname = $rug->groupname;
138 next unless $groupname;
139 unless(defined($group_cache{$groupname})) {
140 my $g = new FS::radius_group {
141 'groupname' => $groupname,
142 'description' => $groupname,
145 die $error if $error;
146 $group_cache{$groupname} = $g->groupnum;
148 $rug->groupnum($group_cache{$groupname});
150 $error = $rug->replace;
151 die $error if $error;
159 L<svc_acct>, L<FS::radius_group>, L<FS::Record>, schema.html from the base documentation.