[freeside-commits] freeside/FS/FS export_nas.pm, 1.1, 1.2 nas.pm, 1.10, 1.11 part_export.pm, 1.109, 1.110

Mark Wells mark at wavetail.420.am
Mon Oct 31 12:20:17 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv27163/FS/FS

Modified Files:
	export_nas.pm nas.pm part_export.pm 
Log Message:
export NAS table to sqlradius, #14697

Index: part_export.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export.pm,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -w -d -r1.109 -r1.110
--- part_export.pm	28 Oct 2011 06:44:26 -0000	1.109
+++ part_export.pm	31 Oct 2011 19:20:15 -0000	1.110
@@ -4,8 +4,8 @@
 use vars qw( @ISA @EXPORT_OK $DEBUG %exports );
 use Exporter;
 use Tie::IxHash;
+use base qw( FS::option_Common FS::m2m_Common ); # m2m for 'export_nas'
 use FS::Record qw( qsearch qsearchs dbh );
-use FS::option_Common;
 use FS::part_svc;
 use FS::part_export_option;
 use FS::export_svc;
@@ -13,7 +13,6 @@
 #for export modules, though they should probably just use it themselves
 use FS::queue;
 
- at ISA = qw( FS::option_Common );
 @EXPORT_OK = qw(export_info);
 
 $DEBUG = 0;

Index: nas.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/nas.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- nas.pm	14 Oct 2011 08:56:03 -0000	1.10
+++ nas.pm	31 Oct 2011 19:20:15 -0000	1.11
@@ -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 @@
 
 =over 4
 
-=item nasnum
-
-primary key
-
-=item nasname
-
-nasname
-
-=item shortname
+=item nasnum - primary key
 
-shortname
+=item nasname - "NAS name", i.e. IP address
 
-=item type
+=item shortname - short descriptive name
 
-type
+=item type - the equipment vendor
 
 =item ports
 
-ports
-
-=item secret
-
-secret
-
-=item server
+=item secret - the authentication secret for this client
 
-server
+=item server - virtual server name (optional)
 
 =item community
 
-community
-
-=item description
-
-description
+=item description - a longer descriptive name
 
 
 =back
@@ -91,26 +75,62 @@
 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 @@
   $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

Index: export_nas.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/export_nas.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- export_nas.pm	25 Oct 2011 23:50:53 -0000	1.1
+++ export_nas.pm	31 Oct 2011 19:20:15 -0000	1.2
@@ -1,9 +1,12 @@
 package FS::export_nas;
 
 use strict;
+use vars qw($noexport_hack);
 use base qw( FS::Record );
 use FS::Record qw( qsearch qsearchs );
 
+$noexport_hack = '';
+
 =head1 NAME
 
 FS::export_nas - Object methods for export_nas records
@@ -70,7 +73,11 @@
 
 =cut
 
-# the insert method can be inherited from FS::Record
+sub insert {
+  my $self = shift;
+  $self->SUPER::insert || 
+  ($noexport_hack ? '' : $self->part_export->export_nas_insert($self->nas));
+}
 
 =item delete
 
@@ -78,16 +85,21 @@
 
 =cut
 
-# the delete method can be inherited from FS::Record
+sub delete {
+  my $self = shift;
+  ($noexport_hack ? '' : $self->part_export->export_nas_delete($self->nas))
+  || $self->SUPER::delete;
+}
 
 =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.
+Unavailable.  Delete the record and create a new one.
 
 =cut
 
-# the replace method can be inherited from FS::Record
+sub replace {
+  die "replace not implemented for export_nas records";
+}
 
 =item check
 
@@ -113,6 +125,16 @@
   $self->SUPER::check;
 }
 
+sub part_export {
+  my $self = shift;
+  qsearchs('part_export', { 'exportnum' => $self->exportnum });
+}
+
+sub nas {
+  my $self = shift;
+  qsearchs('nas', { 'nasnum' => $self->nasnum });
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list