[freeside-commits] freeside/FS/FS export_device.pm, 1.1, 1.2 Mason.pm, 1.28, 1.29 Schema.pm, 1.189, 1.190 part_device.pm, 1.1, 1.2 part_export.pm, 1.102, 1.103 phone_device.pm, 1.3, 1.4

Jeff Finucane,420,, jeff at wavetail.420.am
Mon Feb 8 07:37:30 PST 2010


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

Modified Files:
	Mason.pm Schema.pm part_device.pm part_export.pm 
	phone_device.pm 
Added Files:
	export_device.pm 
Log Message:
grandstream device configuration support #4220

Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- Mason.pm	6 Feb 2010 02:54:09 -0000	1.28
+++ Mason.pm	8 Feb 2010 15:37:28 -0000	1.29
@@ -174,6 +174,7 @@
   use FS::part_export;
   use FS::part_export_option;
   use FS::export_svc;
+  use FS::export_device;
   use FS::msgcat;
   use FS::rate;
   use FS::rate_region;

Index: part_export.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export.pm,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- part_export.pm	18 Jul 2008 22:28:09 -0000	1.102
+++ part_export.pm	8 Feb 2010 15:37:28 -0000	1.103
@@ -226,6 +226,17 @@
   qsearch('export_svc', { 'exportnum' => $self->exportnum } );
 }
 
+=item export_device
+
+Returns a list of associated FS::export_device records.
+
+=cut
+
+sub export_device {
+  my $self = shift;
+  qsearch('export_device', { 'exportnum' => $self->exportnum } );
+}
+
 =item part_export_option
 
 Returns all options as FS::part_export_option objects (see

--- NEW FILE: export_device.pm ---
package FS::export_device;

use strict;
use base qw( FS::Record );
use FS::Record qw( qsearch qsearchs dbh );
use FS::part_export;
use FS::part_device;

=head1 NAME

FS::export_device - Object methods for export_device records

=head1 SYNOPSIS

  use FS::export_device;

  $record = new FS::export_device \%hash;
  $record = new FS::export_device { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::export_device object links a device definition (see L<FS::part_device>)
to an export (see L<FS::part_export>).  FS::export_device inherits from
FS::Record.  The following fields are currently supported:

=over 4

=item exportdevicenum - primary key

=item exportnum - export (see L<FS::part_export>)

=item devicepart - device definition (see L<FS::part_device>)

=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new record.  To add the record to the database, see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

sub table { 'export_device'; }

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

=cut

# may want to check for duplicates against either services or devices
# cf FS::export_svc

=item delete

Delete this record from the database.

=cut

=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.

=cut

=item check

Checks all fields to make sure this is a valid record.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

sub check {
  my $self = shift;

  $self->ut_numbern('exportdevicenum')
    || $self->ut_number('exportnum')
    || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum')
    || $self->ut_number('devicepart')
    || $self->ut_foreign_key('devicepart', 'part_device', 'devicepart')
    || $self->SUPER::check
  ;
}

=item part_export

Returns the FS::part_export object (see L<FS::part_export>).

=cut

sub part_export {
  my $self = shift;
  qsearchs( 'part_export', { 'exportnum' => $self->exportnum } );
}

=item part_device

Returns the FS::part_device object (see L<FS::part_device>).

=cut

sub part_device {
  my $self = shift;
  qsearchs( 'part_device', { 'svcpart' => $self->devicepart } );
}

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::part_export>, L<FS::part_device>, L<FS::Record>, schema.html from the base
documentation.

=cut

1;


Index: part_device.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_device.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- part_device.pm	30 Jun 2009 01:42:55 -0000	1.1
+++ part_device.pm	8 Feb 2010 15:37:28 -0000	1.2
@@ -1,8 +1,10 @@
 package FS::part_device;
 
 use strict;
-use base qw( FS::Record );
-use FS::Record; # qw( qsearch qsearchs );
+use base qw( FS::Record FS::m2m_Common );
+use FS::Record qw( qsearch qsearchs );
+use FS::part_export;
+use FS::export_device;
 
 =head1 NAME
 
@@ -107,6 +109,18 @@
   $self->SUPER::check;
 }
 
+=item part_export
+
+Returns a list of all exports (see L<FS::part_export>) for this device.
+
+=cut
+
+sub part_export {
+  my $self = shift;
+  map { qsearchs( 'part_export', { 'exportnum' => $_->exportnum } ) }
+    qsearch( 'export_device', { 'devicepart' => $self->devicepart } );
+}
+
 sub process_batch_import {
   my $job = shift;
 

Index: phone_device.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/phone_device.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- phone_device.pm	28 Dec 2009 05:26:07 -0000	1.3
+++ phone_device.pm	8 Feb 2010 15:37:28 -0000	1.4
@@ -97,7 +97,7 @@
     return $error;
   }
 
-  $self->svc_phone->export('device_insert', $self); #call device export
+  $self->export('device_insert');
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
@@ -124,7 +124,7 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  $self->svc_phone->export('device_delete', $self); #call device export
+  $self->export('device_delete');
 
   my $error = $self->SUPER::delete;
   if ( $error ) {
@@ -167,7 +167,7 @@
     return $error;
   }
 
-  $new->svc_phone->export('device_replace', $new, $old); #call device export
+  $new->export('device_replace', $old);
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   '';
@@ -227,6 +227,64 @@
   qsearchs( 'svc_phone', { 'svcnum' => $self->svcnum } );
 }
 
+=item export HOOK [ EXPORT_ARGS ]
+
+Runs the provided export hook (i.e. "device_insert") for this service.
+
+=cut
+
+sub export {
+  my( $self, $method ) = ( shift, shift );
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $svc_phone = $self->svc_phone;
+  my $error = $svc_phone->export($method, $self, @_); #call device export
+  if ( $error ) {                                     #netsapiens at least
+    $dbh->rollback if $oldAutoCommit;
+    return "error exporting $method event to svc_phone ". $svc_phone->svcnum.
+           " (transaction rolled back): $error";
+  }
+
+  $method = "export_$method" unless $method =~ /^export_/;
+
+  foreach my $part_export ( $self->part_device->part_export ) {
+    next unless $part_export->can($method);
+    my $error = $part_export->$method($svc_phone, $self, @_);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "error exporting $method event to ". $part_export->exporttype.
+             " (transaction rolled back): $error";
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
+
+=item export_links
+
+Returns a list of html elements associated with this device's exports.
+
+=cut
+
+sub export_links {
+  my $self = shift;
+  my $return = [];
+  $self->export('export_device_links', $return);
+  $return;
+}
+
 =back
 
 =head1 BUGS

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- Schema.pm	6 Feb 2010 02:54:08 -0000	1.189
+++ Schema.pm	8 Feb 2010 15:37:28 -0000	1.190
@@ -1851,6 +1851,17 @@
       'index'       => [ [ 'exportnum' ], [ 'svcpart' ] ],
     },
 
+    'export_device' => {
+      'columns' => [
+        'exportdevicenum' => 'serial', '', '', '', '', 
+        'exportnum'    => 'int', '', '', '', '', 
+        'devicepart'      => 'int', '', '', '', '', 
+      ],
+      'primary_key' => 'exportdevicenum',
+      'unique'      => [ [ 'exportnum', 'devicepart' ] ],
+      'index'       => [ [ 'exportnum' ], [ 'devicepart' ] ],
+    },
+
     'part_export' => {
       'columns' => [
         'exportnum', 'serial', '', '', '', '', 



More information about the freeside-commits mailing list