From 0f32bd99997c82cf7b70eef32818dc817cbff64b Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Fri, 24 Mar 2017 16:07:16 +0100 Subject: [PATCH] Bug 18329 - Batch record deletion broken Hie, Tools > Batch record deletion seems broken. Any deletion returns error : Bibliographic record YYY was not deleted. An error occurred. (The error was: {UNKNOWN}: DBD::mysql::db begin_work failed: Already in a transaction at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1560. at /home/koha/src/C4/Biblio.pm line 3468 , see the Koha log file for more information). Looks like it is because of Bug 18242 which added a transaction in C4::Biblio::_koha_delete_biblio_metadata : $schema->txn_do. The script batch_delete_records created a transaction with $dbh->{AutoCommit} = 0; This patch fixes by using also Koha::Schema in batch_delete_records to manage transaction. It also removes "$dbh->{RaiseError} = 1", this behavior is managed in Koha::Database. Test plan : - Go to Staff interface : Tools > Batch record deletion - Enter a few existing biblionumbers - Click on "Continue" - Click on "Delete selected records" => Without patch you get a DB error => With patch you get confirmation message - Try to get the biblios to confirm they are deleted : /cgi-bin/koha/catalogue/detail.pl?biblionumber=xxx - Test with and without Plack Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall --- tools/batch_delete_records.pl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 195f767e7f..46b9c88977 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -31,7 +31,6 @@ use C4::Biblio; use Koha::Biblios; my $input = new CGI; -my $dbh = C4::Context->dbh; my $op = $input->param('op') // q|form|; my $recordtype = $input->param('recordtype') // 'biblio'; @@ -114,9 +113,7 @@ if ( $op eq 'form' ) { } elsif ( $op eq 'delete' ) { # We want to delete selected records! my @record_ids = $input->multi_param('record_id'); - my $dbh = C4::Context->dbh; - $dbh->{AutoCommit} = 0; - $dbh->{RaiseError} = 1; + my $schema = Koha::Database->new->schema; my $error; my $report = { @@ -126,6 +123,8 @@ if ( $op eq 'form' ) { RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { $report->{total_records}++; next unless $record_id; + $schema->storage->txn_begin; + if ( $recordtype eq 'biblio' ) { # Biblios my $biblionumber = $record_id; @@ -140,7 +139,7 @@ if ( $op eq 'form' ) { code => 'item_issued', biblionumber => $biblionumber, }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } @@ -158,7 +157,7 @@ if ( $op eq 'form' ) { reserve_id => $hold->reserve_id, error => $@, }; - $dbh->rollback; + $schema->storage->txn_rollback; next RECORD_IDS; } } @@ -175,7 +174,7 @@ if ( $op eq 'form' ) { itemnumber => $itemnumber, error => ($@ ? $@ : $error), }; - $dbh->rollback; + $schema->storage->txn_rollback; next RECORD_IDS; } } @@ -191,7 +190,7 @@ if ( $op eq 'form' ) { biblionumber => $biblionumber, error => ($@ ? $@ : $error), }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } @@ -201,7 +200,7 @@ if ( $op eq 'form' ) { biblionumber => $biblionumber, }; $report->{total_success}++; - $dbh->commit; + $schema->storage->txn_commit; } else { # Authorities my $authid = $record_id; @@ -213,7 +212,7 @@ if ( $op eq 'form' ) { authid => $authid, error => ($@ ? $@ : 0), }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } else { push @messages, { @@ -222,7 +221,7 @@ if ( $op eq 'form' ) { authid => $authid, }; $report->{total_success}++; - $dbh->commit; + $schema->storage->txn_commit; } } } -- 2.39.5