Parcourir la source

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>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomás Cohen Arazi il y a 3 ans
commité par Jonathan Druart
Parent
révision
58c275e04b
  1. 18
      C4/Items.pm
  2. 8
      Koha/Filter/MARC/EmbedItems.pm
  3. 8
      opac/opac-ISBDdetail.pl
  4. 16
      opac/opac-search.pl

18
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

8
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(

8
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

16
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};

Chargement…
Annuler
Enregistrer