@@ -, +, @@
---
.../atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl | 2 +-
.../prog/en/modules/admin/searchengine/elasticsearch/mappings.tt | 2 +-
t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t | 4 +++-
t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t | 6 +++++-
t/db_dependent/Koha/SearchField.t | 9 ++++++++-
5 files changed, 18 insertions(+), 5 deletions(-)
--- a/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl
+++ a/installer/data/mysql/atomicupdate/bug_19482_add_mandatory_field_to_mapping.perl
@@ -2,7 +2,7 @@ $DBversion = 'XXX'; # will be replaced by the RM
if( CheckVersion( $DBversion ) ) {
if( !column_exists( 'search_field', 'mandatory' ) ) {
- $dbh->do( "ALTER TABLE search_field ADD COLUMN mandatory tinyint(1) NULL DEFAULT NULL" );
+ $dbh->do( "ALTER TABLE search_field ADD COLUMN mandatory tinyint(1) NULL DEFAULT NULL AFTER opac" );
}
SetVersion( $DBversion );
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt
@@ -197,7 +197,7 @@ a.add, a.delete {
[% ELSE %]
[% END %]
-
+
[% IF search_field.mandatory %]
--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t
+++ a/t/db_dependent/Koha/SearchEngine/Elasticsearch/ExportConfig.t
@@ -17,7 +17,7 @@
use Modern::Perl;
-use Test::More tests => 18;
+use Test::More tests => 19;
use Koha::Database;
use Koha::SearchFields;
@@ -43,6 +43,7 @@ my $search_field = Koha::SearchFields->find_or_create(
weight => 17,
staff_client => 0,
opac => 1,
+ mandatory => 1
},
{ key => 'name' } );
@@ -95,6 +96,7 @@ is( $mappings->{biblios}{title}{label}, 'Title', 'title has label Title');
is( $mappings->{biblios}{title}{facet_order}, undef, 'Facet order is undef');
is( $mappings->{biblios}{title}{opac}, 1, 'title is opac searchable');
is( $mappings->{biblios}{title}{staff_client}, 0, 'title is not staff searchable');
+is( $mappings->{biblios}{title}{mandatory}, 1, 'title is mandatory');
is(scalar(@{ $mappings->{biblios}{title}{mappings} }), 3, 'Title has 3 mappings');
--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t
+++ a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t
@@ -17,7 +17,7 @@
use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 7;
use Test::MockModule;
use Koha::Database;
@@ -29,6 +29,7 @@ my $indexes = {
'label' => 'Match',
'type' => '',
'weight' => 15,
+ 'mandatory' => 0,
'mappings' => []
}
},
@@ -37,6 +38,7 @@ my $indexes = {
'label' => 'title',
'type' => '',
'weight' => 20,
+ 'mandatory' => 1,
'mapping' => []
}
}
@@ -66,9 +68,11 @@ is($search_fields->count, 2, 'There is 2 search fields after reset');
my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next;
is($match_sf->weight, '15.00', 'Match search field is weighted with 15');
+is($match_sf->mandatory, '0', 'Match search field is not mandatory');
my $title_sf = Koha::SearchFields->search({ name => 'title' })->next;
is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
+is($title_sf->mandatory, '1', 'Title search field is mandatory');
$schema->storage->txn_rollback;
--- a/t/db_dependent/Koha/SearchField.t
+++ a/t/db_dependent/Koha/SearchField.t
@@ -19,7 +19,7 @@
use Modern::Perl;
-use Test::More tests => 8;
+use Test::More tests => 10;
use Koha::Database;
use Koha::SearchFields;
@@ -128,11 +128,18 @@ ok($search_field->is_mapped_biblios, 'Search field is mapped with authorities an
my $sf3 = $builder->build({
source => 'SearchField',
+ value => {
+ mandatory => 1,
+ }
});
$search_field = Koha::SearchFields->find($sf3->{id});
ok(!$search_field->is_mapped_biblios, 'Search field is not mapped');
+ok($search_field->mandatory, 'Search field can be marked mandatory');
+$search_field->mandatory(0)->store;
+ok(!$search_field->mandatory, 'Search field can be marked not mandatory');
+
Koha::SearchFields->search({})->delete;
$schema->storage->txn_rollback;
--
|