1 package FS::radius_group;
4 use base qw( FS::o2m_Common FS::Record );
5 use FS::Record qw( qsearch qsearchs 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;
132 =item replace OLD_RECORD
134 Replaces the OLD_RECORD with this one in the database. If there is an error,
135 returns the error, otherwise returns false.
139 # To keep these things from proliferating, we will follow the same
140 # export/noexport switches that radius_attr uses. If you _don't_ use
141 # Freeside to maintain your RADIUS group attributes, then it probably
142 # shouldn't try to rename groups either.
145 my ($self, $old) = @_;
146 $old ||= $self->replace_old;
148 my $error = $self->check;
149 return $error if $error;
151 if ( !$FS::radius_attr::noexport_hack ) {
152 foreach ( qsearch('part_export', {}) ) {
153 next if !$_->option('export_attrs',1);
154 $error = $_->export_group_replace($self, $old);
155 return $error if $error;
159 $self->SUPER::replace($old);
164 Checks all fields to make sure this is a valid RADIUS group. If there is
165 an error, returns the error, otherwise returns false. Called by the insert
170 # the check method should currently be supplied - FS::Record contains some
171 # data checking routines
177 $self->ut_numbern('groupnum')
178 || $self->ut_text('groupname')
179 || $self->ut_textn('description')
180 || $self->ut_numbern('priority')
181 || $self->ut_numbern('speed_up')
182 || $self->ut_numbern('speed_down')
184 return $error if $error;
189 =item long_description
191 Returns a description for this group consisting of its description field,
192 if any, and the RADIUS group name.
196 sub long_description {
198 $self->description ? $self->description . " (". $self->groupname . ")"
204 Returns all L<FS::radius_attr> objects (check and reply attributes) for
212 table => 'radius_attr',
213 hashref => {'groupnum' => $self->groupnum },
214 order_by => 'ORDER BY attrtype, attrname',
222 This isn't export-specific (i.e. groups are globally unique, as opposed to being
227 L<FS::radius_usergroup>, L<FS::Record>, schema.html from the base documentation.