From d836f196898403c41b146737db4b5e8a2de2c026 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Mon, 14 Apr 2025 13:17:11 +0000 Subject: [PATCH] Bug 37020: (follow-up) Fix txn handling, loop label and record_number counter So, I reviewed the code, which has a bunch of issues: * there's a call to `next RECORD`, but no `RECORD` loop label. * $record_number is incremented twice * and the calls to txn_begin is moved from the outside the loop into each record, starting one transaction per record. Not sure how mysql handles this, but postgres would not like it. This patch fixes those issues: After I fixed the first two issues, I ran the patched script on a file containing 75 authorities (from GND), and not one was added to the DB, presuambly because nested transactions don't work in mysql? So I also moved the BEGIN transaction outside of the main loop and started a new one after each commit, and added a final commit after to loop. Signed-off-by: Jan Kissig Signed-off-by: Thomas Klausner Signed-off-by: Katrin Fischer (cherry picked from commit 01d36c5e8b6a7bfb75dd06f42e7748ae87b0105a) Signed-off-by: Paul Derscheid --- misc/migration_tools/bulkmarcimport.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 52956ba087..55552610ba 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -325,7 +325,8 @@ my $logger = Koha::Logger->get; my $schema = Koha::Database->schema; my $lint = MARC::Lint->new; -while () { +$schema->txn_begin; +RECORD: while () { my $record; $record_number++; @@ -475,7 +476,6 @@ while () { } } unless ($test_parameter) { - $schema->txn_begin; if ($authorities) { my $authtypecode = GuessAuthTypeCode( $record, $heading_fields ); @@ -726,10 +726,15 @@ while () { @search_engine_records = (); } $schema->txn_commit; + $schema->txn_begin; } last if $record_number == $number || $records_exhausted; } +if ( !$test_parameter ) { + $schema->txn_commit; +} + if ($fk_off) { $dbh->do("SET FOREIGN_KEY_CHECKS = 1"); }