From f0dadd169b08f3b486ea387cdbb7f93c13b8d3db 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: 1 - Export more than 100 records 2 - Use bulkmarcimport (with -commit=10) to import them perl misc/migration_tools/bulkmarcimport.pl -b -file testbmi.xml -v -m=MARCXML --commit=10 3 - Modify a record to make the import fail (for instance having a too long lccn) 4 - Use bulkmarcimport (with -commit=10) to import them perl misc/migration_tools/bulkmarcimport.pl -b -file testbmi.xml -v -m=MARCXML --commit=10 5 - Notice that the import stops but that the imported record are imported (apart from the last batch of 10) Signed-off-by: Fridolin Somers Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart (cherry picked from commit 4a90c0b647fdfdb0a39b43f6b10adba3bca53215) 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.39.5