diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-04-27 17:43:55 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-04-27 17:43:55 -0700 |
commit | 496842b7db855bd616844c7667e5d70de42535fd (patch) | |
tree | d3fa958a3ad292e07459cb169a8c708de19232c2 /FS/FS/cust_location.pm | |
parent | 2745cc5da9e4ef3ce98f71740b3f692de28540d7 (diff) |
allow cust_http export to be triggered for location changes, RT#22830
Diffstat (limited to 'FS/FS/cust_location.pm')
-rw-r--r-- | FS/FS/cust_location.pm | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 51fcba35b..70ccbfd7e 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -12,6 +12,7 @@ use FS::Conf; use FS::prospect_main; use FS::cust_main; use FS::cust_main_county; +use FS::part_export; use FS::GeocodeCache; $import = 0; @@ -205,19 +206,49 @@ sub insert { $self->set('censusyear' => $conf->config('census_year') || 2012); } + 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; + } #false laziness with cust_main, will go away eventually - if ( !$import and !$error and $conf->config('tax_district_method') ) { + if ( !$import and $conf->config('tax_district_method') ) { my $queue = new FS::queue { 'job' => 'FS::geocode_Mixin::process_district_update' }; $error = $queue->insert( ref($self), $self->locationnum ); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } } - $error || ''; + # cust_location exports + #my $export_args = $options{'export_args'} || []; + + my @part_export = + map qsearch( 'part_export', {exportnum=>$_} ), + $conf->config('cust_location-exports'); #, $agentnum + + foreach my $part_export ( @part_export ) { + my $error = $part_export->export_insert($self); #, @$export_args); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; } =item delete @@ -242,7 +273,35 @@ sub replace { } } - $self->SUPER::replace($old); + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->SUPER::replace($old); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + # cust_location exports + #my $export_args = $options{'export_args'} || []; + + my @part_export = + map qsearch( 'part_export', {exportnum=>$_} ), + $conf->config('cust_location-exports'); #, $agentnum + + foreach my $part_export ( @part_export ) { + my $error = $part_export->export_replace($self, $old); #, @$export_args); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "exporting to ". $part_export->exporttype. + " (transaction rolled back): $error"; + } + } + + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; } |