Browse Source

Bug 18316: Fix field weight validation/deletion bug

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
David Gustafsson 3 years ago
committed by Nick Clemens
parent
commit
74198af0fe
  1. 12
      admin/searchengine/elasticsearch/mappings.pl
  2. 4
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt

12
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;
}

4
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 {
</td>
<td>
[% IF search_field.mapped_biblios %]
<input type="number" step="0.01" min="0" max="999" name="search_field_weight" value="[% search_field.weight %]" />
<input type="number" step="0.01" min="0.01" max="999.99" name="search_field_weight" value="[% search_field.weight %]" />
[% ELSE %]
<input type="hidden" name="search_field_weight" value="">
[% END %]

Loading…
Cancel
Save