1 package Koha::BackgroundJob::UpdateElasticIndex;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Koha::SearchEngine;
21 use Koha::SearchEngine::Indexer;
23 use base 'Koha::BackgroundJob';
27 Koha::BackgroundJob::UpdateElasticIndex - Update Elastic index
29 This is a subclass of Koha::BackgroundJob.
37 Define the job type of this job: update_elastic_index
42 return 'update_elastic_index';
47 Process the modification.
52 my ( $self, $args ) = @_;
56 my @record_ids = @{ $args->{record_ids} };
57 my $record_server = $args->{record_server};
60 total_records => scalar @record_ids,
67 $record_server eq "authorityserver"
68 ? $Koha::SearchEngine::AUTHORITIES_INDEX
69 : $Koha::SearchEngine::BIBLIOS_INDEX;
70 my $indexer = Koha::SearchEngine::Indexer->new({ index => $es_index });
71 $indexer->update_index(\@record_ids);
77 code => 'index_error',
83 # FIXME This is not correct if some record_ids have been skipped
84 $report->{total_success} = scalar @record_ids;
87 my $data = $self->decoded_data;
88 $data->{messages} = \@messages;
89 $data->{report} = $report;
91 $self->finish( $data );
101 my ( $self, $args) = @_;
103 return unless exists $args->{record_server};
104 return unless exists $args->{record_ids};
106 my $record_server = $args->{record_server};
107 my @record_ids = @{ $args->{record_ids} };
109 $self->SUPER::enqueue({
111 job_args => {record_server => $record_server, record_ids => \@record_ids},