From 51499393be49668e210d41f72b6f9e138bd805d3 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 22 Mar 2019 08:03:16 +0000 Subject: [PATCH] Bug 17385: (QA follow-up) Do not needlessly scan biblioexport folder Performance: We need to return an empty list if OpacExportOptions does not contain Custom. No need to scan the directory for custom files, if we are not using them at all. Note: The test only pertains to OPAC now, since the pref should not control intranet behavior. We have no intranet counterpart. See further next follow-up. Test plan: Run t/db_dependent/XSLT.t Signed-off-by: David Nind --- C4/XSLT.pm | 48 +++++++++++++++++++++++++++++++++++++++++++ t/db_dependent/XSLT.t | 1 + 2 files changed, 49 insertions(+) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 2ad0cdbff8..07c4991499 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -413,6 +413,54 @@ sub engine { return $engine; } +=head2 CustomXSLTExportList + + Returns list of file for custom xslt conversion + +=cut + +sub CustomXSLTExportList { + my $opac = shift; # opac (1) vs intranet (0) + return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/; + + my @tabFiles; + + my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') . + '/' . C4::Context->preference( $opac ? "opacthemes" : "template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + my @files = glob qq("$dir/*.xsl"); + foreach my $file (@files) { + if ( -f "$file" ) { + (my $text = $file) =~ s/.*\///g; + + ## Get title of the option + my $dom; + eval { $dom = XML::LibXML->load_xml( location => $file ); }; + next unless $dom; + + my $node = $dom->documentElement(); + my $title = $node->{"title"}; + ($title = $text) =~ s/\.xsl// unless defined $title; + + # Get output format + # There should only be one xsl:output node, so taking the first one only is OK + $node = @{$node->findnodes("xsl:output")}[0]; + my $outputformat= ""; + $outputformat = $node->{"method"} if $node; + $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text"); + + my %row = ( + value => $text, + filename => $title, + format => $outputformat, + ); + + push @tabFiles, \%row; + } + } + return \@tabFiles; +} 1; __END__ diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 5f79b35b13..3c7b312075 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -1,3 +1,4 @@ +original #!/usr/bin/perl # This file is part of Koha. -- 2.34.1