default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / FS / device_Common.pm
1 package FS::device_Common;
2
3 use strict;
4 use NEXT;
5 use FS::Record qw( qsearch dbh ); # qsearchs );
6
7 =head1 NAME
8
9 FS::device_Common - Base class for svc_X classes which have associated X_devices
10
11 =head1 SYNOPSIS
12
13   package FS::svc_newservice
14   use base qw( FS::device_Common FS::svc_Common );
15
16 =head1 DESCRIPTION
17
18 =cut
19
20 sub _device_table {
21   my $self = shift;
22   ( my $device_table = $self->table ) =~ s/^svc_//;
23   $device_table.'_device';
24 }
25
26 sub device_table {
27   my $self = shift;
28   my $device_table = $self->_device_table;
29   eval "use FS::$device_table;";
30   die $@ if $@;
31   $device_table;
32 }
33
34 sub device_objects {
35   my $self = shift;
36   qsearch($self->device_table, { 'svcnum' => $self->svcnum } );
37 }
38
39 sub delete {
40   my $self = shift;
41
42   local $SIG{HUP} = 'IGNORE';
43   local $SIG{INT} = 'IGNORE';
44   local $SIG{QUIT} = 'IGNORE';
45   local $SIG{TERM} = 'IGNORE';
46   local $SIG{TSTP} = 'IGNORE';
47   local $SIG{PIPE} = 'IGNORE';
48
49   my $oldAutoCommit = $FS::UID::AutoCommit;
50   local $FS::UID::AutoCommit = 0;
51   my $dbh = dbh;
52
53   foreach my $device ( $self->device_objects ) {
54     my $error = $device->delete;
55     if ( $error ) {
56       $dbh->rollback if $oldAutoCommit;
57       return $error;
58     }
59   }
60
61   my $error = $self->NEXT::delete;
62   if ( $error ) {
63     $dbh->rollback if $oldAutoCommit;
64     return $error;
65   }
66
67   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
68   '';
69
70 }
71
72 =head1 BUGS
73
74 =head1 SEE ALSO
75
76 =cut
77
78 1;