X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_phone.pm;h=11a5a0ee0d1dec024a831635f45f87452dc2e231;hb=2cb70470a8e5c3287146008e4ce2c4eb9f242373;hp=73ea8e7317589ea2fff227beb60bf9abd3b44bd2;hpb=eaf25d783191d2a6f14701442c491d78efd3b996;p=freeside.git diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index 73ea8e731..11a5a0ee0 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -3,10 +3,11 @@ package FS::svc_phone; use strict; use vars qw( @ISA @pw_set $conf ); use FS::Conf; -use FS::Record qw( qsearch qsearchs ); +use FS::Record qw( qsearch qsearchs dbh ); use FS::Msgcat qw(gettext); use FS::svc_Common; use FS::part_svc; +use FS::phone_device; @ISA = qw( FS::svc_Common ); @@ -151,6 +152,39 @@ Delete this record from the database. =cut +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; + + foreach my $phone_device ( $self->phone_device ) { + my $error = $phone_device->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + # the delete method can be inherited from FS::Record =item replace OLD_RECORD @@ -326,6 +360,17 @@ sub radius_groups { (); } +=item phone_device + +Returns any FS::phone_device records associated with this service. + +=cut + +sub phone_device { + my $self = shift; + qsearch('phone_device', { 'svcnum' => $self->svcnum } ); +} + =back =head1 BUGS