From e982b7d953cbf20b37469770abd261fb47f82650 Mon Sep 17 00:00:00 2001 From: Katrin Fischer Date: Mon, 19 Sep 2022 21:32:12 +0000 Subject: [PATCH] Bug 31577: Use patron category multi-select for OpacHiddenItemsExceptions system preference We are now using the patron category selects on almost all system preferences, but OpacHiddenItemsExceptions was still missing. To test: - Before applying the patch: - Add patron categories to OpacHiddenItemsExceptions using | - Add configuration to OpacHiddenItems - Verify all works as expected in the OPAC - Apply patch, run database update - Verify the system preference shows the correct settings from before - Verify feature still works as expected Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Patron/Category.pm | 2 +- .../bug_31577_OpacHiddenItemsExceptions.pl | 18 ++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 2 +- .../en/modules/admin/preferences/opac.pref | 4 +++- t/db_dependent/Koha/Patron/Category.t | 4 ++-- 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_31577_OpacHiddenItemsExceptions.pl diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index b700cb298c..9eb6d26edc 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -202,7 +202,7 @@ TODO: Remove on bug 22547 sub override_hidden_items { my ($self) = @_; return any { $_ eq $self->categorycode } - split( /\|/, C4::Context->preference('OpacHiddenItemsExceptions') ); + split( ',', C4::Context->preference('OpacHiddenItemsExceptions') ); } =head3 can_make_suggestions diff --git a/installer/data/mysql/atomicupdate/bug_31577_OpacHiddenItemsExceptions.pl b/installer/data/mysql/atomicupdate/bug_31577_OpacHiddenItemsExceptions.pl new file mode 100755 index 0000000000..a1a00dfd17 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_31577_OpacHiddenItemsExceptions.pl @@ -0,0 +1,18 @@ +use Modern::Perl; + +return { + bug_number => "31577", + description => "Add category list pull-down to OpacHiddenItemsExceptions", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + # Do you stuffs here + $dbh->do(q{ + UPDATE systempreferences SET value = REPLACE(value,"|",","), + explanation = REPLACE(explanation,"separated by |,","separated by comma,") + WHERE variable = "OpacHiddenItemsExceptions" + }); + # Print useful stuff here + say $out "Settings for OpacHiddenItemsExceptions have been updated"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 8e66feb75a..8d0e1c35db 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -441,7 +441,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OPACFinesTab','1','','If OFF the patron fines tab in the OPAC is disabled.','YesNo'), ('OPACFRBRizeEditions','0','','If ON, the OPAC will query one or more ISBN web services for associated ISBNs and display an Editions tab on the details pages','YesNo'), ('OpacHiddenItems','','','This syspref allows to define custom rules for hiding specific items at the OPAC. See http://wiki.koha-community.org/wiki/OpacHiddenItems for more information.','Textarea'), -('OpacHiddenItemsExceptions','',NULL,'List of borrower categories, separated by |, that can see items otherwise hidden by OpacHiddenItems','Textarea'), +('OpacHiddenItemsExceptions','',NULL,'List of borrower categories, separated by comma, that can see items otherwise hidden by OpacHiddenItems','Textarea'), ('OpacHiddenItemsHidesRecord','1','','Hide biblio record when all its items are hidden because of OpacHiddenItems','YesNo'), ('OpacHighlightedWords','1','','If Set, then queried words are higlighted in OPAC','YesNo'), ('OPACHoldingsDefaultSortField','first_column','first_column|homebranch|holdingbranch','Default sort field for the holdings table at the OPAC','choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index d9641af5fe..18c74a709b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -592,8 +592,10 @@ OPAC: class: code - Define custom rules to hide specific items from search and view on the OPAC. How to write these rules is documented on the Koha wiki. - - - 'List of patron categories, separated by |, that can see items otherwise hidden by OpacHiddenItems:' + - 'List of patron categories, that can see items otherwise hidden by OpacHiddenItems:' - pref: OpacHiddenItemsExceptions + choices: patron-categories + class: multiple - - pref: OpacHiddenItemsHidesRecord default: 1 diff --git a/t/db_dependent/Koha/Patron/Category.t b/t/db_dependent/Koha/Patron/Category.t index 983c4b2b31..eeed784348 100755 --- a/t/db_dependent/Koha/Patron/Category.t +++ b/t/db_dependent/Koha/Patron/Category.t @@ -155,12 +155,12 @@ subtest 'override_hidden_items() tests' => sub { my $category_1 = $builder->build_object({ class => 'Koha::Patron::Categories' }); my $category_2 = $builder->build_object({ class => 'Koha::Patron::Categories' }); - t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', $category_1->categorycode . '|' . $category_2->categorycode . '|RANDOM' ); + t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', $category_1->categorycode . ',' . $category_2->categorycode . ',RANDOM' ); ok( $category_1->override_hidden_items, 'Category configured to override' ); ok( $category_2->override_hidden_items, 'Category configured to override' ); - t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'RANDOM|' . $category_2->categorycode ); + t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', 'RANDOM,' . $category_2->categorycode ); ok( !$category_1->override_hidden_items, 'Category not configured to override' ); ok( $category_2->override_hidden_items, 'Category configured to override' ); -- 2.39.5