package FS::phone_device;
+use base qw( FS::MAC_Mixin FS::Record );
use strict;
-use base qw( FS::Record );
use Scalar::Util qw( blessed );
-use FS::Record qw( dbh qsearchs ); # qsearch );
-use FS::part_device;
-use FS::svc_phone;
+use FS::Record qw( dbh ); # qsearch qsearchs dbh );
=head1 NAME
return $error;
}
- $self->svc_phone->export('device_insert', $self); #call device export
+ $self->export('device_insert');
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
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 ) {
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;
'';
Returns the device type record (see L<FS::part_device>) associated with this
customer device.
+=item svc_phone
+
+Returns the phone number (see L<FS::svc_phone>) associated with this customer
+device.
+
+=item export HOOK [ EXPORT_ARGS ]
+
+Runs the provided export hook (i.e. "device_insert") for this service.
+
=cut
-sub part_device {
- my $self = shift;
- qsearchs( 'part_device', { 'devicepart' => $self->devicepart } );
+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 svc_phone
+=item export_links
-Returns the phone number (see L<FS::svc_phone>) associated with this customer
-device.
+Returns a list of html elements associated with this device's exports.
=cut
-sub svc_phone {
+sub export_links {
my $self = shift;
- qsearchs( 'svc_phone', { 'svcnum' => $self->svcnum } );
+ my $return = [];
+ $self->export('export_device_links', $return);
+ $return;
}
=back