From 40d543d01fbaf2b869dfd6c3ff5b5f082668edf6 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Mon, 14 Apr 2025 13:17:11 +0000 Subject: [PATCH] Bug 37020: (Followup) 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. --- misc/migration_tools/bulkmarcimport.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index fbdeb0e9b5..ca4f8b2bd3 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -325,10 +325,10 @@ 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++; # get record eval { $record = $batch->next() }; @@ -476,7 +476,6 @@ while () { } } unless ($test_parameter) { - $schema->txn_begin; if ($authorities) { my $authtypecode = GuessAuthTypeCode( $record, $heading_fields ); @@ -727,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"); } -- 2.39.5