From: Sven Schöling Date: Wed, 27 Jul 2016 16:05:08 +0000 (+0200) Subject: IR: single-dbh X-Git-Tag: release-3.5.4~2105 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=4812c08443aa4df5b178d1dbfb0737619accb012;p=kivitendo-erp.git IR: single-dbh --- diff --git a/SL/IR.pm b/SL/IR.pm index 5985f66b7..f1a1b7c17 100644 --- a/SL/IR.pm +++ b/SL/IR.pm @@ -47,17 +47,25 @@ use SL::IO; use SL::MoreCommon; use SL::DB::Default; use SL::DB::TaxZone; +use SL::DB; use List::Util qw(min); use strict; sub post_invoice { + my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_post_invoice, $self, $myconfig, $form, $provided_dbh, $payments_only); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _post_invoice { my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; - # connect to database, turn off autocommit - my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig); + my $dbh = $provided_dbh || SL::DB->client->dbh; my $restricter = SL::HTML::Restrict->create; $form->{defaultcurrency} = $form->get_default_currency($myconfig); @@ -691,12 +699,7 @@ SQL $query = qq|UPDATE ap SET paid = ? WHERE id = ?|; do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); $form->new_lastmtime('ap'); - if (!$provided_dbh) { - $dbh->commit(); - $dbh->disconnect(); - } - $main::lxdebug->leave_sub(); return; } @@ -820,20 +823,11 @@ SQL $datev->export; if ($datev->errors) { - $dbh->rollback; die join "\n", $::locale->text('DATEV check returned errors:'), $datev->errors; } } - my $rc = 1; - if (!$provided_dbh) { - $rc = $dbh->commit(); - $dbh->disconnect(); - } - - $main::lxdebug->leave_sub(); - - return $rc; + return 1; } sub reverse_invoice { @@ -919,31 +913,29 @@ sub delete_invoice { my ($self, $myconfig, $form) = @_; my $query; # connect to database - my $dbh = $form->dbconnect_noauto($myconfig); + my $dbh = SL::DB->client->dbh; - &reverse_invoice($dbh, $form); + SL::DB->client->with_transaction(sub{ - my @values = (conv_i($form->{id})); - - # delete zero entries - # wtf? use case for this? - $query = qq|DELETE FROM acc_trans WHERE amount = 0|; - do_query($form, $dbh, $query); + &reverse_invoice($dbh, $form); + my @values = (conv_i($form->{id})); - my @queries = ( - qq|DELETE FROM invoice WHERE trans_id = ?|, - qq|DELETE FROM ap WHERE id = ?|, - ); + # delete zero entries + # wtf? use case for this? + $query = qq|DELETE FROM acc_trans WHERE amount = 0|; + do_query($form, $dbh, $query); - map { do_query($form, $dbh, $_, @values) } @queries; - my $rc = $dbh->commit; - $dbh->disconnect; + my @queries = ( + qq|DELETE FROM invoice WHERE trans_id = ?|, + qq|DELETE FROM ap WHERE id = ?|, + ); - $main::lxdebug->leave_sub(); + map { do_query($form, $dbh, $_, @values) } @queries; + }); - return $rc; + return 1; } sub retrieve_invoice { @@ -1564,12 +1556,19 @@ sub _delete_payments { } sub post_payment { + my ($self, $myconfig, $form, $locale) = @_; $main::lxdebug->enter_sub(); + my $rc = SL::DB->client->with_transaction(\&_post_payment, $self, $myconfig, $form, $locale); + + $::lxdebug->leave_sub; + return $rc; +} + +sub _post_payment { my ($self, $myconfig, $form, $locale) = @_; - # connect to database, turn off autocommit - my $dbh = $form->dbconnect_noauto($myconfig); + my $dbh = SL::DB->client->dbh; my (%payments, $old_form, $row, $item, $query, %keep_vars); @@ -1625,12 +1624,7 @@ sub post_payment { restore_form($old_form); - my $rc = $dbh->commit(); - $dbh->disconnect(); - - $main::lxdebug->leave_sub(); - - return $rc; + return 1; } sub get_duedate {