summaryrefslogtreecommitdiff
path: root/FS/FS/phone_device.pm
diff options
context:
space:
mode:
authorjeff <jeff>2010-02-08 15:37:29 +0000
committerjeff <jeff>2010-02-08 15:37:29 +0000
commitd0221fabd4656b3a04251ca6168cc45f54d23574 (patch)
tree6edf3792883e58294de4d1c42a9ddbe52be1be85 /FS/FS/phone_device.pm
parent942c8b05b17b119a3dad84d7035c76b481dc5b99 (diff)
grandstream device configuration support #4220
Diffstat (limited to 'FS/FS/phone_device.pm')
-rw-r--r--FS/FS/phone_device.pm64
1 files changed, 61 insertions, 3 deletions
diff --git a/FS/FS/phone_device.pm b/FS/FS/phone_device.pm
index 914f735..ba765e0 100644
--- a/FS/FS/phone_device.pm
+++ b/FS/FS/phone_device.pm
@@ -97,7 +97,7 @@ sub insert {
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 @@ sub delete {
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 @@ sub replace {
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 @@ sub svc_phone {
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