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 <bibliothek@th-wildau.de>
Signed-off-by: Thomas Klausner <domm@plix.at>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Thomas Klausner 2025-04-14 13:17:11 +00:00 committed by Katrin Fischer
parent ba0979a4c9
commit 01d36c5e8b
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 7 additions and 2 deletions

View File

@ -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++;
@ -476,7 +477,6 @@ while () {
}
}
unless ($test_parameter) {
$schema->txn_begin;
if ($authorities) {
my $authtypecode = GuessAuthTypeCode( $record, $heading_fields );
@ -727,10 +727,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");
}