From cde547c694c6b760825c6d837cec1d049fbf84d9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 1 Jul 2019 15:34:26 -0300 Subject: [PATCH] Bug 23247: Simplify visibility logic used in opac-MARCdetail.pl This patch uses the OO code, with prefetching and all, to make decisions on visibility. It shouldn't change any behaviour, unless you are counting DB queries, execution time, etc. To test: - Find a known record, go to the OPAC MARC page of it. - Play with several options in OpacHiddenItems, refreshing it - Play with OpacHiddenItemsExceptions as well => SUCCESS: Things work as expected - Apply this patch - Repeate the tests above => SUCCESS: Things work as expected! - Sign off :-D Signed-off-by: Jesse Maseto --- opac/opac-MARCdetail.pl | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index b835f1bdea..c4c300181a 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -59,7 +59,6 @@ use C4::Koha; use List::MoreUtils qw( any uniq ); use Koha::Biblios; use Koha::CirculationRules; -use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use Koha::RecordProcessor; @@ -85,39 +84,34 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $patron = Koha::Patrons->find( $loggedinuser ); -my $borcat = q{}; -if ( C4::Context->preference('OpacHiddenItemsExceptions') ) { - # we need to fetch the borrower info here, so we can pass the category - $borcat = $patron ? $patron->categorycode : $borcat; -} +my $biblio = Koha::Biblios->find( $biblionumber, { prefetch => [ 'metadata', 'items' ] } ); -my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1, - opac => 1, - borcat => $borcat }); -if ( ! $record ) { +unless ( $biblio ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); exit; } -my @all_items = GetItemsInfo($biblionumber); -my $biblio = Koha::Biblios->find( $biblionumber ); -my $framework = $biblio ? $biblio->frameworkcode : q{}; -my $tagslib = &GetMarcStructure( 0, $framework ); -my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField( 'items.itemnumber' ); -my @nonhiddenitems = $record->field($tag_itemnumber); -if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) { - print $query->redirect("/cgi-bin/koha/errors/404.pl"); - exit; +my $patron = Koha::Patrons->find( $loggedinuser ); + +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 + # and its category overrides OpacHiddenItems + if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) { + print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early + exit; + } } +my $record = $biblio->metadata->record; +my $marcflavour = C4::Context->preference("marcflavour"); + my $record_processor = Koha::RecordProcessor->new({ filters => 'ViewPolicy', options => { interface => 'opac', - frameworkcode => $framework + frameworkcode => $biblio->frameworkcode } }); $record_processor->process($record); @@ -130,6 +124,7 @@ if(my $cart_list = $query->cookie("bib_list")){ } } +my $tagslib = &GetMarcStructure( 0, $biblio->frameworkcode ); my ($bt_tag,$bt_subtag) = GetMarcFromKohaField( 'biblio.title' ); $template->param( bibliotitle => $biblio->title, @@ -137,8 +132,8 @@ $template->param( $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8; # except -8; my $allow_onshelf_holds; -for my $itm (@all_items) { - my $item = Koha::Items->find( $itm->{itemnumber} ); +my $items = $biblio->items; +while ( my $item = $items->next ) { $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); last if $allow_onshelf_holds; } @@ -341,7 +336,6 @@ if ( C4::Context->preference("OPACISBD") ) { } #Search for title in links -my $marcflavour = C4::Context->preference("marcflavour"); my $dat = TransformMarcToKoha( $record ); my $isbn = GetNormalizedISBN(undef,$record,$marcflavour); my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour); -- 2.26.0