X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FBP.pm;h=724ab2767e9e5db7366fde0d1cd4c7f212172367;hb=0e60202e4d9de0e0377e63fccc3a2f93e68bd24f;hp=867b5ca1979df76bd8b9417d60b41158e6ea2200;hpb=bed19453fb654f69ad972911a4533ca89f8ae0c9;p=kivitendo-erp.git diff --git a/SL/BP.pm b/SL/BP.pm index 867b5ca19..724ab2767 100644 --- a/SL/BP.pm +++ b/SL/BP.pm @@ -25,7 +25,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Batch printing module backend routines @@ -35,6 +36,7 @@ package BP; use SL::DBUtils; +use SL::DB; use strict; @@ -83,8 +85,6 @@ sub get_vc { $sth->finish; } - $dbh->disconnect; - $main::lxdebug->leave_sub(); } @@ -94,7 +94,7 @@ sub payment_accounts { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = qq|SELECT DISTINCT ON (s.chart_id) c.accno, c.description | . @@ -109,7 +109,6 @@ sub payment_accounts { } $sth->finish; - $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -119,8 +118,7 @@ sub get_spoolfiles { my ($self, $myconfig, $form) = @_; - # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my ($query, $arap, @values); my $invnumber = "invnumber"; @@ -227,7 +225,6 @@ sub get_spoolfiles { } $sth->finish; - $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -239,42 +236,37 @@ sub delete_spool { my $spool = $::lx_office_conf{paths}->{spool}; - # connect to database, turn AutoCommit off - my $dbh = $form->dbconnect_noauto($myconfig); + SL::DB->client->with_transaction(sub { + my $dbh = SL::DB->client->dbh; - my $query; + my $query; - if ($form->{type} =~ /(check|receipt)/) { - $query = qq|DELETE FROM status WHERE spoolfile = ?|; - } else { - $query = - qq|UPDATE status SET spoolfile = NULL, printed = '1' | . - qq|WHERE spoolfile = ?|; - } - my $sth = $dbh->prepare($query) || $form->dberror($query); - - foreach my $i (1 .. $form->{rowcount}) { - if ($form->{"checked_$i"}) { - $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query); - $sth->finish; + if ($form->{type} =~ /(check|receipt)/) { + $query = qq|DELETE FROM status WHERE spoolfile = ?|; + } else { + $query = + qq|UPDATE status SET spoolfile = NULL, printed = '1' | . + qq|WHERE spoolfile = ?|; } - } + my $sth = $dbh->prepare($query) || $form->dberror($query); - # commit - my $rc = $dbh->commit; - $dbh->disconnect; + foreach my $i (1 .. $form->{rowcount}) { + if ($form->{"checked_$i"}) { + $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query); + $sth->finish; + } + } - if ($rc) { foreach my $i (1 .. $form->{rowcount}) { if ($form->{"checked_$i"}) { unlink(qq|$spool/$form->{"spoolfile_$i"}|); } } - } + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); - - return $rc; + return 1; } sub print_spool { @@ -285,7 +277,7 @@ sub print_spool { my $spool = $::lx_office_conf{paths}->{spool}; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = qq|UPDATE status SET printed = '1' | . @@ -316,8 +308,6 @@ sub print_spool { } } - $dbh->disconnect; - $main::lxdebug->leave_sub(); }