From 06b038d25fad3456be32910844217c225f4d6924 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 18 Oct 2017 13:06:22 +0000 Subject: [PATCH] Bug 19482 - Add support for defining 'mandatory' mappings To test: 1 - Apply patch 2 - ./installer/data/mysql/updatedatabase.pl 3 - Clear all ES mappings form the db: DELETE FROM search_field; DELETE FROM search_marc_map; DELETE FROM search_marc_to_field; 4 - Reset ES mapping: /cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1 5 - issues should now be uneditable and not removable Signed-off-by: Nicolas Legrand --- Koha/SearchEngine/Elasticsearch.pm | 4 +- admin/searchengine/elasticsearch/mappings.pl | 1 + admin/searchengine/elasticsearch/mappings.yaml | 1 + .../admin/searchengine/elasticsearch/mappings.tt | 139 +++++++++++++-------- 4 files changed, 89 insertions(+), 56 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 9c114fb..bc129f6 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -255,8 +255,10 @@ sub reset_elasticsearch_mappings { while ( my ( $field_name, $data ) = each %$fields ) { 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 }, { key => 'name' }); + my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type, mandatory => $field_mandatory }, { key => 'name' }); 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} } ); diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index ecd8741..9cd3e90 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -126,6 +126,7 @@ for my $index_name (qw| biblios authorities |) { { search_field_name => $s->name, search_field_label => $s->label, search_field_type => $s->type, + search_field_mandatory => $s->mandatory, marc_field => $s->get_column('marc_field'), sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" suggestible => $s->get_column('suggestible'), diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index 18e63fa..a5aef26 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -2216,6 +2216,7 @@ biblios: sort: 1 suggestible: '' type: sum + mandatory: 1 itemnumber: label: itemnumber mappings: 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 cc7b28c..40ec383 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 @@ -145,12 +145,20 @@ a.add, a.delete { [% FOREACH search_field IN all_search_fields %] + [% IF search_field.mandatory %] + [% SET is_readonly = "readonly" %] + [% ELSE %] + [% SET is_readonly = "" %] + [% END %] - + - + + [% IF is_readonly %] + + [% ELSE %] - - [% mapping.search_field_label | html %] - - - - - - - - - - - - - - Delete - - [% END %] + [% IF mapping.search_field_mandatory %] + + + + + [% mapping.search_field_label %] + + + [% IF mapping.sort == 'undef' %]Undef[% ELSE %][% mapping.sort | html %][% END %] + + + [% IF mapping.facet == 1 %]Yes[% ELSE %]No[% END %] + + + [% IF mapping.suggestible == 1 %]Yes[% ELSE %]No[% END %] + + + + + + [% ELSE %] + + + + + [% mapping.search_field_label | html %] + + + + + + + + + + + + + + Delete + + [% END %] -- 2.1.4