From c8b038cc9276b88bfb5bf7b04bf5184a21792b2d 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 --- 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 c6837ca00f..05766545a7 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') ); } =head2 Internal methods 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 db99d68f81..944d5e2b82 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -437,7 +437,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 7c3d2d2df9..b24da1e98e 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 @@ -631,8 +631,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 be7f32b8de..9a3dc27c50 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.30.2