X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_svc.pm;h=1f46cf14105632dc71dc21fe89c04d0840acfb9b;hb=5b77b3d0c9aa2d0fa15ca5284d7e34ed68f4ee12;hp=a1df059c55e82b1b4dc00bdcf914d6d4decd0fcc;hpb=b03bd63dcee4fce35d86e906b0379acdb6c76c27;p=freeside.git diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index a1df059c5..1f46cf141 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -2,7 +2,7 @@ package FS::cust_svc; use strict; use vars qw( @ISA $DEBUG $me $ignore_quantity $conf $ticket_system ); -use Carp; +use Carp qw(cluck); #use Scalar::Util qw( blessed ); use List::Util qw( max ); use FS::Conf; @@ -15,6 +15,7 @@ use FS::domain_record; use FS::part_export; use FS::cdr; use FS::UI::Web; +use FS::export_cust_svc; #most FS::svc_ classes are autoloaded in svc_x emthod use FS::svc_acct; #this one is used in the cache stuff @@ -32,6 +33,15 @@ FS::UID->install_callback( sub { $ticket_system = $conf->config('ticket_system') }); +our $cache_enabled = 0; + +sub _simplecache { + my( $self, $hashref ) = @_; + if ( $cache_enabled && $hashref->{'svc'} ) { + $self->{'_svcpart'} = FS::part_svc->new($hashref); + } +} + sub _cache { my $self = shift; my ( $hashref, $cache ) = @_; @@ -121,7 +131,7 @@ sub insert { my $error = $self->SUPER::insert; #check if this releases a hold (see FS::pkg_svc provision_hold) - $error ||= $self->_provision_hold; + $error ||= $self->_check_provision_hold; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -149,8 +159,35 @@ sub delete { my $cust_pkg = $self->cust_pkg; my $custnum = $cust_pkg->custnum if $cust_pkg; + 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; + + # delete associated export_cust_svc + foreach my $export_cust_svc ( + qsearch('export_cust_svc',{ 'svcnum' => $self->svcnum }) + ) { + my $error = $export_cust_svc->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + my $error = $self->SUPER::delete; - return $error if $error; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; if ( $ticket_system eq 'RT_Internal' ) { unless ( $rt_session ) { @@ -392,7 +429,7 @@ sub replace { } # if this is a location change #check if this releases a hold (see FS::pkg_svc provision_hold) - $error ||= $new->_provision_hold; + $error ||= $new->_check_provision_hold; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -492,9 +529,9 @@ L). sub part_svc { my $self = shift; - $self->{'_svcpart'} - ? $self->{'_svcpart'} - : qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); + return $self->{_svcpart} if $self->{_svcpart}; + cluck 'cust_svc->part_svc called' if $DEBUG; + qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); } =item cust_pkg @@ -1072,9 +1109,10 @@ sub smart_search_param { my @or = map { my $table = $_; my $search_sql = "FS::$table"->search_sql($string); + my $addl_from = "FS::$table"->search_sql_addl_from(); "SELECT $table.svcnum AS svcnum, '$table' AS svcdb ". - "FROM $table WHERE $search_sql"; + "FROM $table $addl_from WHERE $search_sql"; } FS::part_svc->svc_tables; @@ -1113,12 +1151,12 @@ sub smart_search_param { # then removes hold from pkg # returns $error or '' on success, # does not indicate if pkg status was changed -sub _provision_hold { +sub _check_provision_hold { my $self = shift; # check status of cust_pkg my $cust_pkg = $self->cust_pkg; - return '' unless $cust_pkg->status eq 'on hold'; + return '' unless $cust_pkg && $cust_pkg->status eq 'on hold'; # check flag on this svc # small false laziness with $self->pkg_svc