From d17db253ea6ec2c96662aade8cb8d8b6665d768d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Nov 2021 16:04:45 +0100 Subject: [PATCH] Bug 29436: ES mappings not saved if zebra is configured The mappings must be editable even if ES is not turned on yet. Using a separate array to store the errors as we are testing for $@ || @messages. There is still something wrong that should be improve, but this patch should be safe for backport. Signed-off-by: Fridolin Somers Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall --- admin/searchengine/elasticsearch/mappings.pl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 35ee78e9f7..b3a05aca64 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -50,7 +50,7 @@ unless ( can_load( modules => { 'Koha::SearchEngine::Elasticsearch::Indexer' => my $index = $input->param('index') || 'biblios'; my $op = $input->param('op') || 'list'; -my @messages; +my ( @messages, @errors ); push @messages, { type => 'message', code => 'elasticsearch_disabled' } if ( C4::Context->preference('SearchEngine') ne 'Elasticsearch' ); @@ -68,7 +68,7 @@ my $update_mappings = sub { $indexer->update_mappings(); } catch { my $conf = $indexer->get_elasticsearch_params(); - push @messages, { + push @errors, { type => 'error', code => 'error_on_update_es_mappings', message => $_[0], @@ -124,7 +124,7 @@ if ( $op eq 'edit' ) { $search_field->weight(undef); } elsif ($field_weight <= 0 || !looks_like_number($field_weight)) { - push @messages, { type => 'error', code => 'invalid_field_weight', 'weight' => $field_weight }; + push @errors, { type => 'error', code => 'invalid_field_weight', 'weight' => $field_weight }; } else { $search_field->weight($field_weight); @@ -170,10 +170,10 @@ if ( $op eq 'edit' ) { search => $mapping_search }); } - push @messages, { type => 'error', code => 'missing_mandatory_fields' } if $mandatory_after < $mandatory_before; + push @errors, { type => 'error', code => 'missing_mandatory_fields' } if $mandatory_after < $mandatory_before; }; - if ($@ || @messages) { - push @messages, { type => 'error', code => 'error_on_update', message => $@, }; + if ($@ || @errors) { + push @errors, { type => 'error', code => 'error_on_update', message => $@, }; # FIXME $@ can be empty but @errors $schema->storage->txn_rollback; } else { push @messages, { type => 'message', code => 'success_on_update' }; @@ -203,14 +203,14 @@ for my $index_name (@index_names) { if (!$indexer->is_index_status_ok) { my $conf = $indexer->get_elasticsearch_params(); if ($indexer->is_index_status_reindex_required) { - push @messages, { + push @errors, { type => 'error', code => 'reindex_required', index => $conf->{index_name}, }; } elsif($indexer->is_index_status_recreate_required) { - push @messages, { + push @errors, { type => 'error', code => 'recreate_required', index => $conf->{index_name}, @@ -277,6 +277,7 @@ while ( my $search_field = $search_fields->next ) { push @all_search_fields, $search_field_unblessed; } +push @messages, @errors; $template->param( indexes => \@indexes, all_search_fields => \@all_search_fields, -- 2.39.5