Bug 33576: Index records after import transaction is committed

This patch simply moves our indexing call after the transaction is committed so
that the job will exist in the DB when called.

To test:
 1 - Have Koha using Elasticsearch
 2 - Stage and import a file of records
 3 - View the job in Admin->Manage jobs
 4 - Note it is not finished
 5 - Check log: /var/log/koha/kohadev/es-indexer-output.log
 6 - Note: [WARN] No job found for id=###
 7 - Apply patch
 8 - Stage and import
 9 - Note no error in log
10 - Note successful completion of indexing job

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2023-04-20 16:02:09 +00:00 committed by Tomas Cohen Arazi
parent ff93ce714b
commit 9af2f3d12c
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 5 additions and 4 deletions

View File

@ -714,15 +714,16 @@ sub BatchCommitRecords {
$sth->finish();
SetImportBatchStatus($batch_id, 'imported');
# Moved final commit to the end
$schema->txn_commit;
if ( @biblio_ids ) {
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
$indexer->index_records( \@biblio_ids, "specialUpdate", "biblioserver" );
}
SetImportBatchStatus($batch_id, 'imported');
# Moved final commit to the end
$schema->txn_commit;
return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored);
}