From dfce3d3c0ce53ba3c40adaf69bc924bdfafed051 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sun, 24 Oct 2021 12:11:02 +0000 Subject: [PATCH] Bug 11175: (QA follow-up) Do not fetch twice We were fetching components in the first call of XSLTParse4Display (opac-detail around L220). And again (opac-detail around L660). Same for catalogue/detail.pl. Moving the XSLT block in both scripts and removing the code from XSLT.pm which again makes the tests obsolete. Not hiding the link when there are components. Might be helpful too. Also fixing biblionumber in the XSLTParse4Display call for parts. Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/XSLT.pm | 18 ------------- catalogue/detail.pl | 36 +++++++++++++------------ opac/opac-detail.pl | 65 +++++++++++++++++++++------------------------ 3 files changed, 50 insertions(+), 69 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index d133cdf675..125f887cb0 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -281,24 +281,6 @@ sub XSLTParse4Display { } } - # possibly show analytics link in Detail views - if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" ) { - $biblio //= Koha::Biblios->find( $biblionumber ); - my $components = $biblio->get_marc_components(); - $variables->{show_analytics_link} = ( scalar @{$components} == 0 ) ? 0 : 1; - - my $showcomp = C4::Context->preference('ShowComponentRecords'); - if ( - $variables->{show_analytics_link} - && ( $showcomp eq 'both' - || ( $showcomp eq 'staff' && $xslsyspref !~ m/OPAC/ ) - || ( $showcomp eq 'opac' && $xslsyspref =~ m/OPAC/ ) ) - ) - { - $variables->{show_analytics_link} = 0; - } - } - my $varxml = "\n"; while (my ($key, $value) = each %$variables) { $varxml .= "$value\n"; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 8eae1832b0..3846777ebe 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -123,22 +123,6 @@ my $fw = GetFrameworkCode($biblionumber); my $showallitems = $query->param('showallitems'); my $marcflavour = C4::Context->preference("marcflavour"); -{ - # XSLT processing of some stuff - - $template->param( - XSLTDetailsDisplay => '1', - XSLTBloc => XSLTParse4Display( - { - biblionumber => $biblionumber, - record => $record, - xsl_syspref => "XSLTDetailsDisplay", - fix_amps => 1, - } - ), - ); -} - $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") ); # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid @@ -213,16 +197,19 @@ foreach my $subscription (@subscriptions) { # Get component parts details my $showcomp = C4::Context->preference('ShowComponentRecords'); +my $show_analytics; if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) { + $show_analytics = 1; # just show link when having results my $parts; for my $part ( @{$components} ) { $part = C4::Search::new_record_from_zebra( 'biblioserver', $part ); + my $id = Koha::SearchEngine::Search::extract_biblionumber( $part ); push @{$parts}, XSLTParse4Display( { - biblionumber => $biblionumber, + biblionumber => $id, record => $part, xsl_syspref => "XSLTResultsDisplay", fix_amps => 1, @@ -232,8 +219,23 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { $template->param( ComponentParts => $parts ); $template->param( ComponentPartsQuery => $biblio->get_components_query ); } +} else { # check if we should show analytics anyway + $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not } +# XSLT processing of some stuff +my $xslt_variables = { show_analytics_link => $show_analytics }; +$template->param( + XSLTDetailsDisplay => '1', + XSLTBloc => XSLTParse4Display({ + biblionumber => $biblionumber, + record => $record, + xsl_syspref => "XSLTDetailsDisplay", + fix_amps => 1, + xslt_variables => $xslt_variables, + }), +); + # Get acquisition details if ( C4::Context->preference('AcquisitionDetails') ) { my $orders = Koha::Acquisition::Orders->search( diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index eb3124a06d..aed49fde16 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -195,38 +195,6 @@ SetUTF8Flag($record); my $marcflavour = C4::Context->preference("marcflavour"); my $ean = GetNormalizedEAN( $record, $marcflavour ); -{ - my $variables = { - anonymous_session => ($borrowernumber) ? 0 : 1, - }; - - my $lang = C4::Languages::getlanguage(); - my @plugin_responses = Koha::Plugins->call( - 'opac_detail_xslt_variables', - { - biblio_id => $biblionumber, - lang => $lang, - patron_id => $borrowernumber - - } - ); - for my $plugin_variables ( @plugin_responses ) { - $variables = { %$variables, %$plugin_variables }; - } - - $template->param( - XSLTBloc => XSLTParse4Display( - { - biblionumber => $biblionumber, - record => $record, - xsl_syspref => 'OPACXSLTDetailsDisplay', - fix_amps => 1, - xslt_variables => $variables - } - ), - ); -} - my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults"); # We look for the busc param to build the simple paging from the search @@ -659,16 +627,18 @@ my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 5 # Get component parts details my $showcomp = C4::Context->preference('ShowComponentRecords'); -my $parts; +my ( $parts, $show_analytics ); if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) { + $show_analytics = 1; # just show link when having results for my $part ( @{$components} ) { $part = C4::Search::new_record_from_zebra( 'biblioserver', $part ); + my $id = Koha::SearchEngine::Search::extract_biblionumber( $part ); push @{$parts}, XSLTParse4Display( { - biblionumber => $biblionumber, + biblionumber => $id, record => $part, xsl_syspref => 'OPACXSLTResultsDisplay', fix_amps => 1, @@ -678,8 +648,35 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { $template->param( ComponentParts => $parts ); $template->param( ComponentPartsQuery => $biblio->get_components_query ); } +} else { # check if we should show analytics anyway + $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not } +# XSLT processing of some stuff +my $variables = {}; +my @plugin_responses = Koha::Plugins->call( + 'opac_detail_xslt_variables', + { + biblio_id => $biblionumber, + lang => C4::Languages::getlanguage(), + patron_id => $borrowernumber, + }, +); +for my $plugin_variables ( @plugin_responses ) { + $variables = { %$variables, %$plugin_variables }; +} +$variables->{anonymous_session} = $borrowernumber ? 0 : 1; +$variables->{show_analytics_link} = $show_analytics; +$template->param( + XSLTBloc => XSLTParse4Display({ + biblionumber => $biblionumber, + record => $record, + xsl_syspref => 'OPACXSLTDetailsDisplay', + fix_amps => 1, + xslt_variables => $variables, + }), +); + # Get items on order my ( @itemnumbers_on_order ); if ( C4::Context->preference('OPACAcquisitionDetails' ) ) { -- 2.39.5