From 74198af0fe01035a6fcbf7af75fedcc06f4ae5d8 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 1 Jun 2018 11:39:45 +0200 Subject: [PATCH] Bug 18316: Fix field weight validation/deletion bug Signed-off-by: Ere Maijala Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- admin/searchengine/elasticsearch/mappings.pl | 12 +++++++++++- .../admin/searchengine/elasticsearch/mappings.tt | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 8650201d87..e42cc38e29 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -72,7 +72,17 @@ if ( $op eq 'edit' ) { my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); $search_field->label($field_label); $search_field->type($field_type); - $search_field->weight($field_weight) if looks_like_number($field_weight) && $field_weight > 0; + + if (!length($field_weight)) { + $search_field->weight(undef); + } + elsif ($field_weight <= 0 || !looks_like_number($field_weight)) { + push @messages, { type => 'error', code => 'invalid_field_weight', 'weight' => $field_weight }; + } + else { + $search_field->weight($field_weight); + } + $search_field->store; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt index bb758bdb19..ac3facf784 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt @@ -79,6 +79,8 @@ a.add, a.delete { [% CASE 'error_on_delete' %] An error occurred when deleting the existing mappings. Nothing has been changed! (search field [% m.values.field_name | html %] with mapping [% m.values.marc_field | html %].) + [% CASE 'invalid_field_weight' %] + Invalid field weight "[% m.weight | html %]", must be a positive decimal number. [% CASE 'success_on_update' %] Mappings updated successfully. [% CASE 'success_on_reset' %] @@ -200,7 +202,7 @@ a.add, a.delete { [% IF search_field.mapped_biblios %] - + [% ELSE %] [% END %] -- 2.39.5