1 package FS::radius_attr;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use vars qw( $noexport_hack );
10 FS::radius_attr - Object methods for radius_attr records
16 $record = new FS::radius_attr \%hash;
17 $record = new FS::radius_attr { '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_attr object represents a RADIUS group attribute.
30 FS::radius_attr inherits from FS::Record. The following fields are
35 =item attrnum - primary key
37 =item groupnum - L<FS::radius_group> to assign this attribute
39 =item attrname - Attribute name, as defined in the RADIUS server's dictionary
41 =item value - Attribute value
43 =item attrtype - 'C' (check) or 'R' (reply)
45 =item op - Operator (see L<http://wiki.freeradius.org/Operators>)
55 Creates a new record. To add the record to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 # the new method can be inherited from FS::Record, if a table method is defined
64 sub table { 'radius_attr'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false. If any sqlradius-type exports exist and have the
70 C<export_attrs> option enabled, the new attribute will be exported to them.
76 my $error = $self->SUPER::insert;
77 return $error if $error;
78 return if $noexport_hack;
80 foreach ( qsearch('part_export', {}) ) {
81 next if !$_->option('export_attrs',1);
82 $error = $_->export_attr_insert($self);
83 return $error if $error;
92 Delete this record from the database. Like C<insert>, this will delete
93 the attribute from any attached RADIUS databases.
100 if ( !$noexport_hack ) {
101 foreach ( qsearch('part_export', {}) ) {
102 next if !$_->option('export_attrs',1);
103 $error = $_->export_attr_delete($self);
104 return $error if $error;
108 $self->SUPER::delete;
111 =item replace OLD_RECORD
113 Replaces the OLD_RECORD with this one in the database. If there is an error,
114 returns the error, otherwise returns false.
119 my ($self, $old) = @_;
120 $old ||= $self->replace_old;
121 return 'can\'t change radius_attr.groupnum'
122 if $self->groupnum != $old->groupnum;
124 unless grep { $self->$_ ne $old->$_ } qw(attrname value op attrtype);
126 # don't attempt export on an invalid record
127 my $error = $self->check;
128 return $error if $error;
131 $old->set('groupname', $old->radius_group->groupname);
132 if ( !$noexport_hack ) {
133 foreach ( qsearch('part_export', {}) ) {
134 next if !$_->option('export_attrs',1);
135 $error = $_->export_attr_replace($self, $old);
136 return $error if $error;
140 $self->SUPER::replace($old);
146 Checks all fields to make sure this is a valid record. If there is
147 an error, returns the error, otherwise returns false. Called by the insert
156 $self->ut_numbern('attrnum')
157 || $self->ut_foreign_key('groupnum', 'radius_group', 'groupnum')
158 || $self->ut_text('attrname')
159 || $self->ut_text('value')
160 || $self->ut_enum('attrtype', [ 'C', 'R' ])
162 return $error if $error;
164 my @ops = $self->ops($self->get('attrtype'));
165 $self->set('op' => $ops[0]) if !$self->get('op');
166 $error ||= $self->ut_enum('op', \@ops);
168 return $error if $error;
175 Returns the L<FS::radius_group> object to which this attribute applies.
181 qsearchs('radius_group', { 'groupnum' => $self->groupnum });
192 Returns a list of all legal values of the "op" field. ATTRTYPE must be C for
193 check or R for reply.
198 C => [ '=', '==', ':=', '+=', '!=', '>', '>=', '<', '<=', '=~', '!~', '=*', '!*' ],
199 R => [ '=', ':=', '+=' ],
204 my $attrtype = shift;
205 return @{ $ops{$attrtype} };
214 L<FS::Record>, schema.html from the base documentation.