From 1aeda577df1aa534576e26614f146d8e815d7997 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 1 Jun 2022 19:57:14 +0000 Subject: [PATCH] Bug 29325: Handle the transaction in BatchCommitRecords Content-Type: text/plain; charset=utf-8 Requiring the callback to commit was breaking reversion, and likely elsewhere Let's simplify and say that the routine iteself will handle the txn and commit TO test: 1 - Stage a file 2 - Import a file 3 - Revert a file 4 - Test staff client and command line Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/ImportBatch.pm | 10 ++++------ misc/commit_file.pl | 1 - tools/manage-marc-import.pl | 4 +--- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 5dd8095513..cb0b6430d7 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -583,18 +583,16 @@ sub BatchCommitRecords { my $rec_num = 0; my @biblio_ids; + $schema->txn_begin; # We commit in a transaction while (my $rowref = $sth->fetchrow_hashref) { $record_type = $rowref->{'record_type'}; - # first record, begin transaction - $schema->txn_begin - unless $rec_num; - $rec_num++; if ($progress_interval and (0 == ($rec_num % $progress_interval))) { # report progress and commit - &$progress_callback($rec_num, $schema); + $schema->txn_commit; + &$progress_callback( $rec_num ); $schema->txn_begin; } if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') { @@ -720,7 +718,7 @@ sub BatchCommitRecords { SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); } } - &$progress_callback($rec_num, $schema); # Make sure to commit the final chunk that didn't hit the commit threshhold + $schema->txn_commit; # Commit final records that may not have hit callback threshold $sth->finish(); if ( @biblio_ids ) { diff --git a/misc/commit_file.pl b/misc/commit_file.pl index 2e404e7e3c..da504d2a3a 100755 --- a/misc/commit_file.pl +++ b/misc/commit_file.pl @@ -129,7 +129,6 @@ _SUMMARY_ sub print_progress_and_commit { my ( $recs, $schema ) = @_; print "... processed $recs records\n"; - $schema->txn_commit; } sub print_usage { diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 64e3180dfd..f74db44358 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -277,7 +277,7 @@ sub revert_batch { my $callback = sub { }; if ($runinbackground) { $job = put_in_background($import_batch_id); - $callback = progress_callback( $job, $dbh ); + $callback = progress_callback( $job ); } ( $num_deleted, $num_errors, $num_reverted, @@ -345,9 +345,7 @@ sub progress_callback { my $job = shift; return sub { my $progress = shift; - my $schema = shift; $job->progress($progress); - $schema->txn_commit; } } -- 2.20.1