From ab7021195e15f94f77906c4190a7fd004e945d17 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 3 May 2023 12:54:39 +0100 Subject: [PATCH] Revert "Bug 33486: Remove Koha::BackgroundJob::UpdateElasticIndex->process" This reverts commit aa9645f546469c8a11d46af01e4994ec7ecc8119. Signed-off-by: Martin Renvoize --- Koha/BackgroundJob/UpdateElasticIndex.pm | 59 +++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/Koha/BackgroundJob/UpdateElasticIndex.pm b/Koha/BackgroundJob/UpdateElasticIndex.pm index 70f5e79243..432d34fa97 100644 --- a/Koha/BackgroundJob/UpdateElasticIndex.pm +++ b/Koha/BackgroundJob/UpdateElasticIndex.pm @@ -42,17 +42,54 @@ sub job_type { return 'update_elastic_index'; } -# While most background jobs provide this method, the ES indexing has its own dedicated worker: -# misc/workers/es_index_daemon.pl -# That worker will handle all job processing. -#=head3 process -# -#Process the modification. -# -#=cut -# -#sub process { -#} +=head3 process + +Process the modification. + +=cut + +sub process { + my ( $self, $args ) = @_; + + $self->start; + + my @record_ids = @{ $args->{record_ids} }; + my $record_server = $args->{record_server}; + + my $report = { + total_records => scalar @record_ids, + total_success => 0, + }; + + my @messages; + eval { + my $es_index = + $record_server eq "authorityserver" + ? $Koha::SearchEngine::AUTHORITIES_INDEX + : $Koha::SearchEngine::BIBLIOS_INDEX; + my $indexer = Koha::SearchEngine::Indexer->new({ index => $es_index }); + $indexer->update_index(\@record_ids); + }; + if ( $@ ) { + warn $@; + push @messages, { + type => 'error', + code => 'index_error', + error => $@, + + } + } else { + $self->step; + # FIXME This is not correct if some record_ids have been skipped + $report->{total_success} = scalar @record_ids; + } + + my $data = $self->decoded_data; + $data->{messages} = \@messages; + $data->{report} = $report; + + $self->finish( $data ); +} =head3 enqueue -- 2.39.5