X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fnas.pm;fp=FS%2FFS%2Fnas.pm;h=4564a634206c0083c8a7cd51c7dbcf6a8c0a64c2;hp=7fb7db5e511868a69198183bc04b6dea7b09149b;hb=2ad6569982365759d7baaf5a97bc836770a54291;hpb=588ac92d054671aa13cb61f76b5da472661cb1ac diff --git a/FS/FS/nas.pm b/FS/FS/nas.pm index 7fb7db5e5..4564a6342 100644 --- a/FS/FS/nas.pm +++ b/FS/FS/nas.pm @@ -1,8 +1,10 @@ package FS::nas; use strict; -use base qw( FS::Record ); -use FS::Record qw( qsearch qsearchs ); +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 @@ -30,41 +32,23 @@ FS::Record. The following fields are currently supported: =over 4 -=item nasnum +=item nasnum - primary key -primary key +=item nasname - "NAS name", i.e. IP address -=item nasname +=item shortname - short descriptive name -nasname - -=item shortname - -shortname - -=item type - -type +=item type - the equipment vendor =item ports -ports +=item secret - the authentication secret for this client -=item secret - -secret - -=item server - -server +=item server - virtual server name (optional) =item community -community - -=item description - -description +=item description - a longer descriptive name =back @@ -91,26 +75,62 @@ 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([]) + || $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 @@ -142,6 +162,18 @@ sub check { $self->SUPER::check; } +=item part_export + +Return all L objects to which this NAS is being exported. + +=cut + +sub part_export { + my $self = shift; + map { qsearchs('part_export', { exportnum => $_->exportnum }) } + qsearch('export_nas', { nasnum => $self->nasnum}) +} + =back =head1 BUGS