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
99 my $svcnum = $self->svcnum;
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('svcnum','svc_broadband','svcnum')
105 && "Can't find radius_usergroup.svcnum $svcnum in svc_acct.svcnum or svc_broadband.svcnum" )
106 || $self->ut_foreign_key('groupnum','radius_group','groupnum')
107 || $self->SUPER::check
113 Returns the account associated with this record (see L<FS::svc_acct> and
114 L<FS::svc_broadband>).
120 qsearchs('svc_acct', { svcnum => $self->svcnum } ) ||
121 qsearchs('svc_broadband', { svcnum => $self->svcnum } )
126 Returns the RADIUS group associated with this record (see L<FS::radius_group>).
132 qsearchs('radius_group', { 'groupnum' => $self->groupnum } );
135 sub _upgrade_data { #class method
136 my ($class, %opts) = @_;
138 my %group_cache = map { $_->groupname => $_->groupnum }
139 qsearch('radius_group', {});
141 my @radius_usergroup = qsearch('radius_usergroup', {} );
143 foreach my $rug ( @radius_usergroup ) {
144 my $groupname = $rug->groupname;
145 next unless $groupname;
146 unless(defined($group_cache{$groupname})) {
147 my $g = new FS::radius_group {
148 'groupname' => $groupname,
149 'description' => $groupname,
152 die $error if $error;
153 $group_cache{$groupname} = $g->groupnum;
155 $rug->groupnum($group_cache{$groupname});
157 $error = $rug->replace;
158 die $error if $error;
166 L<svc_acct>, L<FS::radius_group>, L<FS::Record>, schema.html from the base documentation.