From ca39af053fed1d94a87a326df368265db463c97b 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 --- 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 2b82796..d90bae6 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -29,7 +29,6 @@ use C4::AuthoritiesMarc; use C4::Biblio; my $input = new CGI; -my $dbh = C4::Context->dbh; my $op = $input->param('op') // q|form|; my $recordtype = $input->param('recordtype') // 'biblio'; @@ -110,9 +109,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 = { @@ -122,6 +119,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; @@ -133,7 +132,7 @@ if ( $op eq 'form' ) { code => 'item_issued', biblionumber => $biblionumber, }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } @@ -151,7 +150,7 @@ if ( $op eq 'form' ) { reserve_id => $reserve->{reserve_id}, error => $@, }; - $dbh->rollback; + $schema->storage->txn_rollback; next RECORD_IDS; } } @@ -168,7 +167,7 @@ if ( $op eq 'form' ) { itemnumber => $itemnumber, error => ($@ ? $@ : $error), }; - $dbh->rollback; + $schema->storage->txn_rollback; next RECORD_IDS; } } @@ -184,7 +183,7 @@ if ( $op eq 'form' ) { biblionumber => $biblionumber, error => ($@ ? $@ : $error), }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } @@ -194,7 +193,7 @@ if ( $op eq 'form' ) { biblionumber => $biblionumber, }; $report->{total_success}++; - $dbh->commit; + $schema->storage->txn_commit; } else { # Authorities my $authid = $record_id; @@ -206,7 +205,7 @@ if ( $op eq 'form' ) { authid => $authid, error => ($@ ? $@ : 0), }; - $dbh->rollback; + $schema->storage->txn_rollback; next; } else { push @messages, { @@ -215,7 +214,7 @@ if ( $op eq 'form' ) { authid => $authid, }; $report->{total_success}++; - $dbh->commit; + $schema->storage->txn_commit; } } } -- 2.9.3