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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Fridolin Somers 2017-03-24 16:07:16 +01:00 committed by Kyle M Hall
parent 664d653417
commit 0f32bd9999
1 changed files with 10 additions and 11 deletions

View File

@ -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;
}
}
}