From e1aaadb25b34b1162b5559df7db7ecd11dd2e7a5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 17 Nov 2017 18:33:34 +0000 Subject: [PATCH] Bug 19482 - Make reset mappings reset also reset fields I think this makes sense, we should reset to the mappings file completely To test: 1 - Change a field label in es 2 - Save it 3 - Reset mapping 4 - Label should be reset --- Koha/SearchEngine/Elasticsearch.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index cb8ecaa..ca7e8e6 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -294,9 +294,17 @@ sub reset_elasticsearch_mappings { my $field_type = $data->{type}; my $field_label = $data->{label}; my $field_mandatory = $data->{mandatory}; - warn $field_mandatory; my $mappings = $data->{mappings}; - my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type, mandatory => $field_mandatory }, { key => 'name' }); + my $search_field = Koha::SearchFields->find({ name => $field_name }); + if( $search_field ){ + $search_field->type($field_type); + $search_field->label($field_label); + $search_field->mandatory($field_mandatory); + $search_field->store; + } else { + $search_field = Koha::SearchFields->new({ name => $field_name, label => $field_label, type => $field_type, mandatory => $field_mandatory }); + $search_field->store; + } for my $mapping ( @$mappings ) { my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} }); $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } ); -- 2.1.4