diff options
author | Ivan Kohler <ivan@freeside.biz> | 2013-05-14 00:28:33 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2013-05-14 00:28:33 -0700 |
commit | 7c41eea8dca02a399739c29a0dfbda7efdd6df86 (patch) | |
tree | dcbd7f399dffcb899b64f18a00d49cb8d9034c4b /FS/FS/device_Common.pm | |
parent | 7a33a40d9f17d73e7f14410070675da02e25ad5e (diff) |
svc_cable, RT#22009
Diffstat (limited to 'FS/FS/device_Common.pm')
-rw-r--r-- | FS/FS/device_Common.pm | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/FS/FS/device_Common.pm b/FS/FS/device_Common.pm new file mode 100644 index 0000000..ac00b76 --- /dev/null +++ b/FS/FS/device_Common.pm @@ -0,0 +1,78 @@ +package FS::device_Common; + +use strict; +use NEXT; +use FS::Record qw( qsearch dbh ); # qsearchs ); + +=head1 NAME + +FS::device_Common - Base class for svc_X classes which have associated X_devices + +=head1 SYNOPSIS + + package FS::svc_newservice + use base qw( FS::device_Common FS::svc_Common ); + +=head1 DESCRIPTION + +=cut + +sub _device_table { + my $self = shift; + ( my $device_table = $self->table ) =~ s/^svc_//; + $device_table.'_device'; +} + +sub device_table { + my $self = shift; + my $device_table = $self->_device_table; + eval "use FS::$device_table;"; + die $@ if $@; + $device_table; +} + +sub device_objects { + my $self = shift; + qsearch($self->device_table, { 'svcnum' => $self->svcnum } ); +} + +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 $device ( $self->device_objects ) { + my $error = $device->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + my $error = $self->NEXT::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + +=head1 BUGS + +=head1 SEE ALSO + +=cut + +1; |