From bac873b711db94457429f2cf176bebb7f4f850a7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 18 Dec 2020 14:41:12 +0100 Subject: [PATCH] Bug 27245: Replace AutoCommit=0 with txn_begin in bulkmarcimport.pl To prevent DBD::mysql::db begin_work failed: Already in a transaction at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1588, line 1. Test plan: Export more than 100 records Use bulkmarcimport (with -commit=10) to import them Modify a record to make the import fail (for instance having a too long lccn) Use bulkmarcimport (with -commit=10) to import them Notice that the import stops but that the imported record are imported (a part from the last batch of 10) Signed-off-by: Fridolin Somers --- misc/migration_tools/bulkmarcimport.pl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 80d3396cad..0ae54ee9c1 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -252,13 +252,14 @@ else { # the SQL query to search on isbn my $sth_isbn = $dbh->prepare("SELECT biblionumber,biblioitemnumber FROM biblioitems WHERE isbn=?"); -$dbh->{AutoCommit} = 0; my $loghandle; if ($logfile){ $loghandle= IO::File->new($logfile, $writemode) ; print $loghandle "id;operation;status\n"; } +my $schema = Koha::Database->schema; +$schema->txn_begin; RECORD: while ( ) { my $record; # get records @@ -537,14 +538,15 @@ RECORD: while ( ) { } $yamlhash->{$originalid} = $biblionumber if ($yamlfile); } - $dbh->commit() if (0 == $i % $commitnum); + if ( 0 == $i % $commitnum ) { + $schema->txn_commit; + $schema->txn_begin; + } } print $record->as_formatted()."\n" if ($verbose//0)==2; last if $i == $number; } -$dbh->commit(); -$dbh->{AutoCommit} = 1; - +$schema->txn_commit; if ($fk_off) { $dbh->do("SET FOREIGN_KEY_CHECKS = 1"); -- 2.29.2