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 <fridolin.somers@biblibre.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2021-11-16 16:04:45 +01:00 committed by Fridolin Somers
parent fc690e8f84
commit 401ce06ffe

View file

@ -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,