1 package FS::radius_usergroup;
5 use FS::Record qw( qsearch qsearchs );
13 FS::radius_usergroup - Object methods for radius_usergroup records
17 use FS::radius_usergroup;
19 $record = new FS::radius_usergroup \%hash;
20 $record = new FS::radius_usergroup { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::radius_usergroup object links an account (see L<FS::svc_acct>) with a
33 RADIUS group (see L<FS::radius_group>). FS::radius_usergroup inherits from
34 FS::Record. The following fields are currently supported:
38 =item usergroupnum - primary key
40 =item svcnum - Account (see L<FS::svc_acct>).
42 =item groupnum - RADIUS group (see L<FS::radius_group>).
52 Creates a new record. To add the record to the database, see L<"insert">.
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to. You can ask the object for a copy with the I<hash> method.
59 # the new method can be inherited from FS::Record, if a table method is defined
61 sub table { 'radius_usergroup'; }
65 Adds this record to the database. If there is an error, returns the error,
66 otherwise returns false.
70 #inherited from FS::Record
74 Delete this record from the database.
78 #inherited from FS::Record
80 =item replace OLD_RECORD
82 Replaces the OLD_RECORD with this one in the database. If there is an error,
83 returns the error, otherwise returns false.
87 #inherited from FS::Record
91 Checks all fields to make sure this is a valid record. If there is
92 an error, returns the error, otherwise returns false. Called by the insert
100 die "radius_usergroup.groupname is deprecated" if $self->groupname;
102 $self->ut_numbern('usergroupnum')
103 || $self->ut_foreign_key('svcnum','svc_acct','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>).
117 qsearchs('svc_acct', { svcnum => $self->svcnum } );
122 Returns the RADIUS group associated with this record (see L<FS::radius_group>).
128 qsearchs('radius_group', { 'groupnum' => $self->groupnum } );
131 sub _upgrade_data { #class method
132 my ($class, %opts) = @_;
134 my %group_cache = map { $_->groupname => $_->groupnum }
135 qsearch('radius_group', {});
137 my @radius_usergroup = qsearch('radius_usergroup', {} );
139 foreach my $rug ( @radius_usergroup ) {
140 my $groupname = $rug->groupname;
141 next unless $groupname;
142 unless(defined($group_cache{$groupname})) {
143 my $g = new FS::radius_group {
144 'groupname' => $groupname,
145 'description' => $groupname,
148 die $error if $error;
149 $group_cache{$groupname} = $g->groupnum;
151 $rug->groupnum($group_cache{$groupname});
153 $error = $rug->replace;
154 die $error if $error;
162 L<svc_acct>, L<FS::radius_group>, L<FS::Record>, schema.html from the base documentation.