1 package FS::radius_group;
2 use base qw( FS::o2m_Common FS::Record );
5 use FS::Record qw( qsearch dbh );
10 FS::radius_group - Object methods for radius_group records
16 $record = new FS::radius_group \%hash;
17 $record = new FS::radius_group { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::radius_group object represents a RADIUS group. FS::radius_group inherits from
30 FS::Record. The following fields are currently supported:
50 =item speed_up, speed_down - connection speeds in bits per second. Some
51 exports may use this to generate appropriate RADIUS attributes.
61 Creates a new RADIUS group. To add the RADIUS group to the database, see L<"insert">.
63 Note that this stores the hash reference, not a distinct copy of the hash it
64 points to. You can ask the object for a copy with the I<hash> method.
68 # the new method can be inherited from FS::Record, if a table method is defined
70 sub table { 'radius_group'; }
74 Adds this record to the database. If there is an error, returns the error,
75 otherwise returns false.
79 # the insert method can be inherited from FS::Record
83 Delete this record from the database.
88 # okay, I guess we support it now
90 local $SIG{HUP} = 'IGNORE';
91 local $SIG{INT} = 'IGNORE';
92 local $SIG{QUIT} = 'IGNORE';
93 local $SIG{TERM} = 'IGNORE';
94 local $SIG{TSTP} = 'IGNORE';
95 local $SIG{PIPE} = 'IGNORE';
97 my $oldAutoCommit = $FS::UID::AutoCommit;
98 local $FS::UID::AutoCommit = 0;
101 my $groupnum = $self->groupnum;
102 my $error = $self->process_o2m(
103 'table' => 'radius_usergroup',
104 'num_col' => 'groupnum',
105 'fields' => ['groupnum'], # just delete them
107 ) || $self->SUPER::delete(@_);
110 $dbh->rollback if $oldAutoCommit;
114 foreach my $part_svc_column (
115 qsearch('part_svc_column', { columnname => 'usergroup' })
117 my $new_values = join(',',
118 grep { $_ != $groupnum } split(',', $part_svc_column->columnvalue)
120 next if $new_values eq $part_svc_column->columnvalue;
121 $part_svc_column->set(columnvalue => $new_values);
122 $error = $part_svc_column->replace;
124 $dbh->rollback if $oldAutoCommit;
129 foreach my $radius_attr ( $self->radius_attr ) {
130 $error = $radius_attr->delete;
132 $dbh->rollback if $oldAutoCommit;
141 =item replace OLD_RECORD
143 Replaces the OLD_RECORD with this one in the database. If there is an error,
144 returns the error, otherwise returns false.
148 # To keep these things from proliferating, we will follow the same
149 # export/noexport switches that radius_attr uses. If you _don't_ use
150 # Freeside to maintain your RADIUS group attributes, then it probably
151 # shouldn't try to rename groups either.
154 my ($self, $old) = @_;
155 $old ||= $self->replace_old;
157 my $error = $self->check;
158 return $error if $error;
160 if ( !$FS::radius_attr::noexport_hack ) {
161 foreach ( qsearch('part_export', {}) ) {
162 next if !$_->option('export_attrs',1);
163 $error = $_->export_group_replace($self, $old);
164 return $error if $error;
168 $self->SUPER::replace($old);
173 Checks all fields to make sure this is a valid RADIUS group. If there is
174 an error, returns the error, otherwise returns false. Called by the insert
179 # the check method should currently be supplied - FS::Record contains some
180 # data checking routines
186 $self->ut_numbern('groupnum')
187 || $self->ut_text('groupname')
188 || $self->ut_textn('description')
189 || $self->ut_numbern('priority')
190 || $self->ut_numbern('speed_up')
191 || $self->ut_numbern('speed_down')
193 return $error if $error;
198 =item long_description
200 Returns a description for this group consisting of its description field,
201 if any, and the RADIUS group name.
205 sub long_description {
207 $self->description ? $self->description . " (". $self->groupname . ")"
213 Returns all L<FS::radius_attr> objects (check and reply attributes) for
221 table => 'radius_attr',
222 hashref => {'groupnum' => $self->groupnum },
223 order_by => 'ORDER BY attrtype, attrname',
231 This isn't export-specific (i.e. groups are globally unique, as opposed to being
236 L<FS::radius_usergroup>, L<FS::Record>, schema.html from the base documentation.