From dd73cb4ce956cec068d819269f0c038427a9d55a Mon Sep 17 00:00:00 2001 From: Mirko Tietgen Date: Sun, 29 Nov 2015 20:35:19 +0100 Subject: [PATCH] Bug 15263: XSLT display fetches sysprefs for every result processed On search, every single result goes through some XSLT processing. This includes fetching the relevant sysprefs every single time. We should do it only once per search. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall --- C4/Search.pm | 13 ++++++++++--- C4/XSLT.pm | 53 ++++++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index edf58479a9..017d172ad8 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1882,6 +1882,13 @@ sub searchResults { # We get the biblionumber position in MARC my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber',''); + # set stuff for XSLT processing here once, not later again for every record we retrieved + my $interface = $search_context eq 'opac' ? 'OPAC' : ''; + my $xslsyspref = $interface . "XSLTResultsDisplay"; + my $xslfile = C4::Context->preference($xslsyspref); + my $lang = C4::Languages::getlanguage(); + my ($sysxml) = C4::XSLT::_get_xslt_sysprefs(); + # loop through all of the records we've retrieved for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) { @@ -2209,9 +2216,9 @@ sub searchResults { } # XSLT processing of some stuff - my $interface = $search_context eq 'opac' ? 'OPAC' : ''; - if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) { - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems); + # we fetched the sysprefs already before the loop through all retrieved record! + if (!$scan && $xslfile) { + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile); # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 7ca4f0db74..e74a742701 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -160,13 +160,39 @@ sub _get_best_default_xslt_filename { return $xslfilename; } +sub _get_xslt_sysprefs { + my $sysxml = "\n"; + foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow + DisplayOPACiconsXSLT URLLinkText viewISBD + OPACBaseURL TraceCompleteSubfields UseICU + UseAuthoritiesForTracings TraceSubjectSubdivisions + Display856uAsImage OPACDisplay856uAsImage + UseControlNumber IntranetBiblioDefaultView BiblioDefaultView + OPACItemLocation DisplayIconsXSLT + AlternateHoldingsField AlternateHoldingsSeparator + TrackClicks opacthemes IdRef OpacSuppression / ) + { + my $sp = C4::Context->preference( $syspref ); + next unless defined($sp); + $sysxml .= "$sp\n"; + } + + # singleBranchMode was a system preference, but no longer is + # we can retain it here for compatibility + my $singleBranchMode = Koha::Libraries->search->count == 1; + $sysxml .= "$singleBranchMode\n"; + + $sysxml .= "\n"; + return $sysxml; +} + sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; - my $xslfilename = C4::Context->preference($xslsyspref); + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_; + #my $xslfilename = C4::Context->preference($xslsyspref); if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; my $theme; - my $lang = C4::Languages::getlanguage(); + # my $lang = C4::Languages::getlanguage(); my $xslfile; if ($xslsyspref eq "XSLTDetailsDisplay") { $htdocs = C4::Context->config('intrahtdocs'); @@ -201,28 +227,7 @@ sub XSLTParse4Display { my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); - my $sysxml = "\n"; - foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow - DisplayOPACiconsXSLT URLLinkText viewISBD - OPACBaseURL TraceCompleteSubfields UseICU - UseAuthoritiesForTracings TraceSubjectSubdivisions - Display856uAsImage OPACDisplay856uAsImage - UseControlNumber IntranetBiblioDefaultView BiblioDefaultView - OPACItemLocation DisplayIconsXSLT - AlternateHoldingsField AlternateHoldingsSeparator - TrackClicks opacthemes IdRef OpacSuppression / ) - { - my $sp = C4::Context->preference( $syspref ); - next unless defined($sp); - $sysxml .= "$sp\n"; - } - # singleBranchMode was a system preference, but no longer is - # we can retain it here for compatibility - my $singleBranchMode = Koha::Libraries->search->count == 1; - $sysxml .= "$singleBranchMode\n"; - - $sysxml .= "\n"; $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; if ($fixamps) { # We need to correct the HTML entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; -- 2.39.5