summaryrefslogtreecommitdiff
path: root/FS/FS/nas.pm
diff options
context:
space:
mode:
authormark <mark>2011-10-31 19:20:16 +0000
committermark <mark>2011-10-31 19:20:16 +0000
commit2ad6569982365759d7baaf5a97bc836770a54291 (patch)
tree81c72ce1e7687e27ea1f727643f659fdb6335793 /FS/FS/nas.pm
parent588ac92d054671aa13cb61f76b5da472661cb1ac (diff)
export NAS table to sqlradius, #14697
Diffstat (limited to 'FS/FS/nas.pm')
-rw-r--r--FS/FS/nas.pm100
1 files changed, 66 insertions, 34 deletions
diff --git a/FS/FS/nas.pm b/FS/FS/nas.pm
index 7fb7db5..4564a63 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<export_nas> 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<FS::part_export> 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