From 4b0f2ca2b42f11e84861a9d25e9acc7e842c4cca 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 | 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 428f8e039d..eef4fbcdab 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -612,18 +612,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') { @@ -749,7 +747,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(); 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 a75f8c8581..c0491f428d 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -275,7 +275,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, @@ -338,9 +338,7 @@ sub progress_callback { my $job = shift; return sub { my $progress = shift; - my $schema = shift; $job->progress($progress); - $schema->txn_commit; } } -- 2.30.2