X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fnas.pm;h=af5a23a24d470fd2c176d0b025ff9d04fca1717d;hp=58c6827ea261124cb9ea477a7ff94348f92dbdb9;hb=aed8ec35ccb9cdeb7ea0cb6ff2946f9d83d582f6;hpb=0ebeec96313dd7edfca340f01f8fbbbac1f4aa1d diff --git a/FS/FS/nas.pm b/FS/FS/nas.pm index 58c6827ea..af5a23a24 100644 --- a/FS/FS/nas.pm +++ b/FS/FS/nas.pm @@ -1,11 +1,10 @@ package FS::nas; use strict; -use vars qw( @ISA ); -use FS::Record qw(qsearchs); #qsearch); -use FS::UID qw( dbh ); - -@ISA = qw(FS::Record); +use base qw( FS::m2m_Common FS::Record ); +use FS::Record qw( qsearch qsearchs dbh ); +use FS::export_nas; +use FS::part_export; =head1 NAME @@ -16,11 +15,7 @@ FS::nas - Object methods for nas records use FS::nas; $record = new FS::nas \%hash; - $record = new FS::nas { - 'nasnum' => 1, - 'nasip' => '10.4.20.23', - 'nasfqdn' => 'box1.brc.nv.us.example.net', - }; + $record = new FS::nas { 'column' => 'value' }; $error = $record->insert; @@ -30,26 +25,31 @@ FS::nas - Object methods for nas records $error = $record->check; - $error = $record->heartbeat($timestamp); - =head1 DESCRIPTION -An FS::nas object represents an Network Access Server on your network, such as -a terminal server or equivalent. FS::nas inherits from FS::Record. The -following fields are currently supported: +An FS::nas object represents a RADIUS client. FS::nas inherits from +FS::Record. The following fields are currently supported: =over 4 =item nasnum - primary key -=item nas - NAS name +=item nasname - "NAS name", i.e. IP address + +=item shortname - short descriptive name + +=item type - the equipment vendor + +=item ports + +=item secret - the authentication secret for this client + +=item server - virtual server name (optional) -=item nasip - NAS ip address +=item community -=item nasfqdn - NAS fully-qualified domain name +=item description - a longer descriptive name -=item last - timestamp indicating the last instant the NAS was in a known - state (used by the session monitoring). =back @@ -75,30 +75,69 @@ sub table { 'nas'; } Adds this record to the database. If there is an error, returns the error, otherwise returns false. -=cut - -# the insert method can be inherited from FS::Record - =item delete -Delete this record from the database. +Delete this record from the database and remove all linked exports. =cut -# the delete method can be inherited from FS::Record +sub delete { + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $self = shift; + my $error = $self->process_m2m( + link_table => 'export_nas', + target_table => 'part_export', + params => [] + ) || $self->SUPER::delete; + + if ( $error ) { + $dbh->rollback; + return $error; + } + + $dbh->commit if $oldAutoCommit; + ''; +} =item replace OLD_RECORD Replaces the OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false. +To change the list of linked exports, see the C method. + =cut -# the replace method can be inherited from FS::Record +sub replace { + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my ($self, $old) = @_; + $old ||= qsearchs('nas', { 'nasnum' => $self->nasnum }); + + my $error; + foreach my $part_export ( $self->part_export ) { + $error ||= $part_export->export_nas_replace($self, $old); + } + + $error ||= $self->SUPER::replace($old); + + if ( $error ) { + $dbh->rollback; + return $error; + } + + $dbh->commit if $oldAutoCommit; + ''; +} =item check -Checks all fields to make sure this is a valid example. If there is +Checks all fields to make sure this is a valid NAS. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods. @@ -110,38 +149,38 @@ and replace methods. sub check { my $self = shift; - $self->ut_numbern('nasnum') - || $self->ut_text('nas') - || $self->ut_ip('nasip') - || $self->ut_domain('nasfqdn') - || $self->ut_numbern('last'); + my $error = + $self->ut_numbern('nasnum') + || $self->ut_text('nasname') + || $self->ut_textn('shortname') + || $self->ut_text('type') + || $self->ut_numbern('ports') + || $self->ut_text('secret') + || $self->ut_textn('server') + || $self->ut_textn('community') + || $self->ut_text('description') + ; + return $error if $error; + + $self->SUPER::check; } -=item heartbeat TIMESTAMP +=item part_export -Updates the timestamp for this nas +Return all L objects to which this NAS is being exported. =cut -sub heartbeat { - my($self, $timestamp) = @_; - my $dbh = dbh; - my $sth = - $dbh->prepare("UPDATE nas SET last = ? WHERE nasnum = ? AND last < ?"); - $sth->execute($timestamp, $self->nasnum, $timestamp) or die $sth->errstr; - $self->last($timestamp); +sub part_export { + my $self = shift; + map { qsearchs('part_export', { exportnum => $_->exportnum }) } + qsearch('export_nas', { nasnum => $self->nasnum}) } =back -=head1 VERSION - -$Id: nas.pm,v 1.6 2002-03-04 12:48:49 ivan Exp $ - =head1 BUGS -heartbeat method uses SQL directly and doesn't update history tables. - =head1 SEE ALSO L, schema.html from the base documentation.