diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 00fd7f3d43..2fb22c64fd 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -538,9 +538,6 @@ sub BatchCommitRecords { $progress_interval = 0 unless ref($progress_callback) eq 'CODE'; my $schema = Koha::Database->schema; - $schema->txn_begin; - # NOTE: Moved this transaction to the front of the routine. Note that inside the while loop below - # transactions may be committed and started too again. The final commit is close to the end. my $record_type; my $num_added = 0; @@ -571,15 +568,14 @@ sub BatchCommitRecords { my @biblio_ids; my @updated_ids; while (my $rowref = $sth->fetchrow_hashref) { + $schema->txn_begin; $record_type = $rowref->{'record_type'}; $rec_num++; if ($progress_interval and (0 == ($rec_num % $progress_interval))) { - # report progress and commit - $schema->txn_commit unless $skip_intermediate_commit; + # report progress &$progress_callback( $rec_num ); - $schema->txn_begin unless $skip_intermediate_commit; } if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') { $num_ignored++; @@ -708,6 +704,7 @@ sub BatchCommitRecords { } SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); } + $schema->txn_commit; } if ($progress_interval){ @@ -718,8 +715,6 @@ sub BatchCommitRecords { SetImportBatchStatus($batch_id, 'imported'); - # final commit should be before Elastic background indexing in order to find job data - $schema->txn_commit; if (@biblio_ids) { my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );