From cabd397bd1819f926537fb39672c106b4ebc8df4 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 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 --- C4/ImportBatch.pm | 11 +++++------ misc/commit_file.pl | 1 - tools/manage-marc-import.pl | 4 +--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 222bf74b27..1f7e9ef397 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -580,18 +580,17 @@ sub BatchCommitRecords { my $logged_in_patron = Koha::Patrons->find( $userenv->{number} ); 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') { @@ -708,7 +707,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 threshhold $sth->finish(); SetImportBatchStatus($batch_id, 'imported'); return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored); 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.30.2