X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fphone_device.pm;h=ba765e026f260f5f1e729af7be58127f230c268b;hp=a7097a1134124f47d4cfdedb17ccdbfc652e42eb;hb=20f38e4c256094bd938b732950e8f93319f851a5;hpb=665067cef48a5516e0bfb2dd79d99b8495e25ee5 diff --git a/FS/FS/phone_device.pm b/FS/FS/phone_device.pm index a7097a113..ba765e026 100644 --- a/FS/FS/phone_device.pm +++ b/FS/FS/phone_device.pm @@ -2,7 +2,8 @@ package FS::phone_device; use strict; use base qw( FS::Record ); -use FS::Record qw( qsearchs ); # qsearch ); +use Scalar::Util qw( blessed ); +use FS::Record qw( dbh qsearchs ); # qsearch ); use FS::part_device; use FS::svc_phone; @@ -76,7 +77,32 @@ otherwise returns false. =cut -# the insert method can be inherited from FS::Record +sub insert { + my $self = 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 $error = $self->SUPER::insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $self->export('device_insert'); + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; +} + =item delete @@ -84,7 +110,31 @@ Delete this record from the database. =cut -# the delete method can be inherited from FS::Record +sub delete { + my $self = 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; + + $self->export('device_delete'); + + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; +} =item replace OLD_RECORD @@ -93,7 +143,35 @@ returns the error, otherwise returns false. =cut -# the replace method can be inherited from FS::Record +sub replace { + my $new = shift; + + my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') ) + ? shift + : $new->replace_old; + + 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 $error = $new->SUPER::replace($old); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $new->export('device_replace', $old); + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; +} =item check @@ -137,6 +215,76 @@ sub part_device { qsearchs( 'part_device', { 'devicepart' => $self->devicepart } ); } +=item svc_phone + +Returns the phone number (see L) associated with this customer +device. + +=cut + +sub svc_phone { + my $self = shift; + 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