Bugzilla – Attachment 119246 Details for
Bug 23583
Handle OpacHiddenItems with yaml_preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23583: Handle OpacHiddenItems with yaml_preference
Bug-23583-Handle-OpacHiddenItems-with-yamlpreferen.patch (text/plain), 5.34 KB, created by
David Nind
on 2021-04-06 20:44:43 UTC
(
hide
)
Description:
Bug 23583: Handle OpacHiddenItems with yaml_preference
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-04-06 20:44:43 UTC
Size:
5.34 KB
patch
obsolete
>From aaba64ac77c1a3de1de5394fe3facbde3fb0e3ce Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 6 Apr 2021 11:28:35 -0300 >Subject: [PATCH] Bug 23583: Handle OpacHiddenItems with yaml_preference > >This patch makes all places in Koha that rely on OpacHiddenItems >actually use C4::Context->yaml_preference instead of manually calling >the YAML libraries and handling it. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Items* \ > t/db_dependent/Koha/Item* \ > t/db_dependent/Koha/Filter/EmbedItems.t >=> SUCCESS: Tests pass! >3. Try hiding things with opac-ISBDdetail.pl and opac-search.pl >=> SUCCESS: Things work the same! >4. Sign off :-D > >Signed-off-by: David Nind <david@davidnind.com> >--- > C4/Items.pm | 18 +++++------------- > Koha/Filter/MARC/EmbedItems.pm | 8 ++------ > opac/opac-ISBDdetail.pl | 8 +------- > opac/opac-search.pl | 16 ++-------------- > 4 files changed, 10 insertions(+), 40 deletions(-) > >diff --git a/C4/Items.pm b/C4/Items.pm >index aecf96af1f..726c7e4cd8 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -49,7 +49,6 @@ BEGIN { > > use Carp; > use Try::Tiny; >-use Encode; > use C4::Context; > use C4::Koha; > use C4::Biblio; >@@ -58,7 +57,6 @@ use MARC::Record; > use C4::ClassSource; > use C4::Log; > use List::MoreUtils qw(any); >-use YAML::XS; > use DateTime::Format::MySQL; > use Data::Dumper; # used as part of logging item record changes, not just for > # debugging; so please don't remove this >@@ -988,17 +986,11 @@ sub GetHiddenItemnumbers { > } > my @resultitems; > >- my $yaml = C4::Context->preference('OpacHiddenItems'); >- return () if (! $yaml =~ /\S/ ); >- $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt >- my $hidingrules; >- eval { >- $hidingrules = YAML::XS::Load(Encode::encode_utf8($yaml)); >- }; >- if ($@) { >- warn "Unable to parse OpacHiddenItems syspref : $@"; >- return (); >- } >+ my $hidingrules = C4::Context->yaml_preference('OpacHiddenItems'); >+ >+ return >+ unless $hidingrules; >+ > my $dbh = C4::Context->dbh; > > # For each item >diff --git a/Koha/Filter/MARC/EmbedItems.pm b/Koha/Filter/MARC/EmbedItems.pm >index 337a4dbbae..ae8ec34a26 100644 >--- a/Koha/Filter/MARC/EmbedItems.pm >+++ b/Koha/Filter/MARC/EmbedItems.pm >@@ -28,13 +28,9 @@ my $biblio = Koha::Biblios->find( > { prefetch => [ items, metadata ] } > ); > >-my $opachiddenitems_rules; >-eval { >- my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n"; >- $opachiddenitems_rules = YAML::XS::Load(Encode::encode_utf8($yaml)); >-}; >+my $rules = C4::Context->yaml_preference('OpacHiddenItems'); > >-my @items = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items}; >+my @items = grep { !$_->hidden_in_opac({ rules => $rules }) @{$biblio->items}; > my $record = $biblio->metadata->record; > > my $processor = Koha::RecordProcessor->new( >diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl >index 6278177e10..d1076e76ef 100755 >--- a/opac/opac-ISBDdetail.pl >+++ b/opac/opac-ISBDdetail.pl >@@ -40,8 +40,6 @@ the items attached to the biblio > =cut > > use Modern::Perl; >-use YAML::XS; >-use Encode; > > use C4::Auth; > use C4::Context; >@@ -81,11 +79,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > > my $patron = Koha::Patrons->find($loggedinuser); > >-my $opachiddenitems_rules; >-eval { >- my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n"; >- $opachiddenitems_rules = YAML::XS::Load(Encode::encode_utf8($yaml)); >-}; >+my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems'); > > unless ( $patron and $patron->category->override_hidden_items ) { > # only skip this check if there's a logged in user >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index dd0d4884dc..a93bc19723 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -30,7 +30,6 @@ use Modern::Perl; > use C4::Context; > use List::MoreUtils q/any/; > use Try::Tiny; >-use YAML::XS; > use Encode; > > use Data::Dumper; # TODO remove >@@ -242,17 +241,7 @@ my $cnt; > my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; > my @advanced_search_types = split(/\|/, $advanced_search_types); > >-my $hidingrules = {}; >-my $yaml = C4::Context->preference('OpacHiddenItems'); >-if ( $yaml =~ /\S/ ) { >- $yaml = "$yaml\n\n"; # YAML expects trailing newline. Surplus does not hurt. >- eval { >- $hidingrules = YAML::XS::Load(Encode::encode_utf8($yaml)); >- }; >- if ($@) { >- warn "Unable to parse OpacHiddenItems syspref : $@"; >- } >-} >+my $hidingrules = C4::Context->yaml_preference('OpacHiddenItems') // {}; > > my @sorted_itemtypes = sort { $itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } keys %$itemtypes; > foreach my $advanced_srch_type (@advanced_search_types) { >@@ -811,8 +800,7 @@ for (my $i=0;$i<@servers;$i++) { > $template->param(searchdesc => 1); > } > $template->param(results_per_page => $results_per_page); >- my $hide = C4::Context->preference('OpacHiddenItems'); >- $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines >+ my $hide = ($hidingrules) ? 1 : 0; > my $branch = ''; > if (C4::Context->userenv){ > $branch = C4::Context->userenv->{branch}; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23583
:
119222
|
119246
|
119804