From 66a8429db419975f880bd73c1dda9f2a9a096fcf Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Thu, 11 May 2023 20:29:18 +0000 Subject: [PATCH] Bug 17385: (Fix) Add custum export format option to the cart and the lists and fix tests for CustomXSLTExportList This patch adds 'XSL-Simple Export' to the cart and the lists and correct the fail test in t/XSLT.t it contains Add custum export format option when saving a record TO TEST: Before applying: 1) Search for a record in the intranet. 2) Click on the 'Save' button and observe the dropdown menu. --> There is no 'XSL- Simple Export' in the dropdown menu. 3) Apply the patch. 4) In System preferences search for OpacExportOptions and enable XSL 5) Repeat the steps 1 and 2. ---> There is now 'XSL- Simple Export' option in the dropdown menu 6) Click on 'XSL - Simple Export'. a .html file should be downloaded. 7) Open the .html file. You should see the record's informations. 8) Add some items to your Cart 9) Open the Cart 10) Click on the 'Download' and 'XSL - Simple Export'. ----> a .html file should be downloaded. ----> you should see the record's informations in the downloaded file. 11) Add some items to a List 12) Open the List 13) Click on the 'Download' and 'XSL - Simple Export'. ----> a .html file should be downloaded. ----> you should see the record's informations in the downloaded file. 14) Do the same steps in OPAC ----> a .html file should be downloaded. ----> you should see the record's informations in the downloaded file. 15) In System preferences search for OpacExportOptions and disable XSL 16) Repeat all steps 17) Notice that 'XSL - Simple Export' is no more in the menus. 18) Run prove -l t/XSLT.t --- C4/XSLT.pm | 11 ++-- basket/basket.pl | 3 +- basket/downloadcart.pl | 12 ++++- catalogue/detail.pl | 2 +- catalogue/export.pl | 18 +++++-- .../en/includes/virtualshelves-toolbar.inc | 2 +- .../prog/en/modules/basket/basket.tt | 2 +- .../en/includes/opac-detail-sidebar.inc | 52 +++++++++---------- .../bootstrap/en/modules/opac-basket.tt | 8 +++ .../bootstrap/en/modules/opac-shelves.tt | 8 +++ opac/opac-basket.pl | 2 + opac/opac-detail.pl | 3 +- opac/opac-downloadcart.pl | 12 ++++- opac/opac-downloadshelf.pl | 16 ++++-- opac/opac-export.pl | 17 ++++-- opac/opac-shelves.pl | 3 +- t/XSLT.t | 1 + t/db_dependent/XSLT.t | 24 ++++----- virtualshelves/downloadshelf.pl | 14 ++++- virtualshelves/shelves.pl | 2 +- 20 files changed, 141 insertions(+), 71 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index cfcf39549b..c35ddcbb99 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -127,24 +127,24 @@ sub get_xslt_sysprefs { } sub get_xsl_filename { - my ( $xslsyspref ) = @_; + my ( $xslsyspref, $xslfilename ) = @_; my $lang = C4::Languages::getlanguage(); - my $xslfilename = C4::Context->preference($xslsyspref) || "default"; + $xslfilename ||= C4::Context->preference($xslsyspref) || "default"; if ($xslsyspref eq "XSLTCustomExport") { my $dir; $dir = C4::Context->config('intrahtdocs') . '/' . C4::Context->preference("template") . - '/' . C4::Languages::getlanguage() . + '/' . $lang . '/xslt/biblioexport'; $xslfilename = $dir . "/" . $xslfilename; } elsif ($xslsyspref eq "OPACXSLTCustomExport") { my $dir; $dir = C4::Context->config('opachtdocs') . '/' . C4::Context->preference("opacthemes") . - '/' . C4::Languages::getlanguage() . + '/' . $lang . '/xslt/biblioexport'; $xslfilename = $dir . "/" . $xslfilename; } elsif ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { @@ -205,11 +205,12 @@ sub XSLTParse4Display { my $variables = $params->{xslt_variables}; my $items_rs = $params->{items_rs}; my $interface = C4::Context->interface; + my $xslfilename = $params->{xslfilename}; die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" if not defined $params->{xsl_syspref}; - my $xslfilename = get_xsl_filename( $xslsyspref); + $xslfilename = get_xsl_filename( $xslsyspref, $xslfilename); my $frameworkcode = GetFrameworkCode($biblionumber) || ''; my $record_processor = Koha::RecordProcessor->new( diff --git a/basket/basket.pl b/basket/basket.pl index a560a4359a..56feed12f6 100755 --- a/basket/basket.pl +++ b/basket/basket.pl @@ -27,8 +27,7 @@ use C4::Biblio qw( ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); -use C4::XSLT; - +use C4::XSLT qw( CustomXSLTExportList ); use Koha::AuthorisedValues; use Koha::Biblios; diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl index 07527e897a..c60a868780 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -26,7 +26,7 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); use Koha::CsvProfiles; use Koha::Biblios; @@ -66,6 +66,7 @@ if ($bib_list && $format) { my $biblio = Koha::Biblios->find($biblionumber); my $record = $biblio->metadata->record({ embed_items => 1 }); + my $xslFile = $query->param("file"); next unless $record; if ($format eq 'iso2709') { @@ -80,7 +81,14 @@ if ($bib_list && $format) { $output .= marc2bibtex($record, $biblionumber); } elsif ($format =~ /^xsl\.(.*)$/) { - $output .= XSLTParse4Display($biblio, $record, 'XSLTCustomExport', 1, undef, , '', $1, ''); + $output .= XSLTParse4Display({ + biblionumber => $biblio, + record => $record, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + xslfilename => $xslFile, + }); } } } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index d774e79cb3..513ab1a479 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -40,7 +40,7 @@ use C4::XISBN qw( get_xisbns ); use C4::External::Amazon qw( get_amazon_tld ); use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra ); use C4::Tags qw( get_tags ); -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use Koha::DateUtils qw( format_sqldatetime ); use C4::HTML5Media; use C4::CourseReserves qw( GetItemCourseReservesInfo ); diff --git a/catalogue/export.pl b/catalogue/export.pl index e023a55e71..42a7fe663f 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -7,8 +7,8 @@ use C4::Output; use C4::Biblio qw( GetMarcControlnumber ); use CGI qw ( -utf8 ); use C4::Ris qw( marc2ris ); -use C4::XSLT; - +use C4::XSLT qw( XSLTParse4Display ); +use Koha::Biblios; @@ -92,11 +92,21 @@ if ($op eq "export") { my $biblionumber = $query->param("bib"); if ($biblionumber){ my $xslFile = $query->param("file"); - my $marc = GetMarcBiblio( { biblionumber => $biblionumber, embed_items => 1 } ); + my $biblio = Koha::Biblios->find($biblionumber); + my $marc = $biblio->metadata->record( { embed_items => 1 } ); my $format=$query->param("format")||'txt'; my @hiddenitems; - $marc = XSLTParse4Display($biblionumber, $marc, 'XSLTCustomExport', 1, \@hiddenitems, '', $xslFile,''); + $marc = XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $marc, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => \@hiddenitems, + xslfilename => $xslFile, + } + ); print $query->header( -type => 'application/octet-stream', -attachment=>"bib-$biblionumber.$format"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc index c241f343f3..acfecbb3b7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc @@ -32,7 +32,7 @@
  • CSV - [% csv_profile.profile | html %]
  • [% END %] [% FOREACH xsl_export IN xsl_exports %] -
  • XSL - [% xsl_export.filename | html %]
  • +
  • XSL - [% xsl_export.filename | html %]
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt index ec8a2178a0..1e4a878a95 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tt @@ -59,7 +59,7 @@
  • CSV - [% csv_profile.profile | html %]
  • [% END %] [% FOREACH xsl_export IN xsl_exports %] -
  • XSL - [% xsl_export.filename | html %]
  • +
  • XSL - [% xsl_export.filename | html %]
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc index 65403749b0..a0b690c288 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -66,36 +66,34 @@
  • + [% END %] + + +
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt index 87ceda18c7..95c6472820 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-basket.tt @@ -30,6 +30,7 @@ Send [% END %] + [% SET export_options = Koha.Preference('OpacExportOptions').split(',') %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 542683f615..b195b91936 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -222,6 +222,7 @@
    New list | + [% SET export_options = Koha.Preference('OpacExportOptions').split(',') %] diff --git a/opac/opac-basket.pl b/opac/opac-basket.pl index e4ed044a85..7d010f76db 100755 --- a/opac/opac-basket.pl +++ b/opac/opac-basket.pl @@ -28,6 +28,7 @@ use C4::Biblio qw( ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); +use C4::XSLT qw( CustomXSLTExportList ); use Koha::RecordProcessor; use Koha::CsvProfiles; use Koha::AuthorisedValues; @@ -134,6 +135,7 @@ $template->param( { type => 'marc', used_for => 'export_records', staff_only => 0 } ), bib_list => $bib_list, BIBLIO_RESULTS => $resultsarray, + xsl_exports => CustomXSLTExportList(), ); output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index c39929aaf4..6726feb953 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -58,7 +58,7 @@ use C4::External::Syndetics qw( get_syndetics_toc ); use C4::Members; -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use C4::ShelfBrowser qw( GetNearbyItems ); use C4::Reserves qw( GetReserveStatus ); use C4::Charset qw( SetUTF8Flag ); @@ -103,7 +103,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -#### ADD CUSTOM XSLT $template->param(filesOptions => CustomXSLTExportList(1)); my $patron = Koha::Patrons->find( $borrowernumber ); diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index e16204c53b..ad3ddd1bad 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -28,7 +28,7 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); use Koha::Biblios; -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); use Koha::CsvProfiles; use Koha::RecordProcessor; @@ -86,6 +86,7 @@ if ($bib_list && $format) { patron => $patron, } ); + my $xslFile = $query->param("file"); my $framework = &GetFrameworkCode( $biblio ); $record_processor->options({ interface => 'opac', @@ -117,7 +118,14 @@ if ($bib_list && $format) { $type = "text/plain"; } elsif ($format =~ /^xsl\.(.*)$/) { - $output .= XSLTParse4Display($biblio, $record, 'OPACXSLTCustomExport', 1, undef, undef, $1, ''); + $output .= XSLTParse4Display({ + biblionumber => $biblio, + record => $record, + xsl_syspref => "OPACXSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + xslfilename => $xslFile, + }); } } } diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index eb7e739c04..615517901d 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -27,7 +27,7 @@ use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); use Koha::Biblios; -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); use Koha::CsvProfiles; use Koha::RecordProcessor; @@ -99,6 +99,7 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { patron => $patron, } ); + my $xslFile = $query->param("file"); my $framework = $biblio->frameworkcode; $record_processor->options({ interface => 'opac', @@ -125,8 +126,17 @@ if ( $shelf and $shelf->can_be_viewed( $borrowernumber ) ) { $extension = "txt"; $type = "text/plain"; }elsif ($format =~ /^xsl\.(.*)$/){ - $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, undef, $1, '', 1); - } + $output .= XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => "XSLTCustomExport", + fix_amps => 1, + hidden_items => undef, + xslfilename => $xslFile, + } + ); + } } } diff --git a/opac/opac-export.pl b/opac/opac-export.pl index 610d5d27e5..845a6fe656 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -31,8 +31,7 @@ use CGI qw ( -utf8 ); use C4::Auth; use C4::Ris qw( marc2ris ); use Koha::Biblios; -use C4::XSLT; - +use C4::XSLT qw( XSLTParse4Display ); use Koha::RecordProcessor; my $query = CGI->new; @@ -142,10 +141,20 @@ elsif ( $format =~ /isbd/ ) { elsif ($format =~ /html/ ) { if ($biblionumber){ my $xslFile = $query->param("file"); - $marc = C4::Biblio::GetMarcBiblio({biblionumber => $biblionumber}); + my $biblio = Koha::Biblios->find($biblionumber); + $marc = $biblio->metadata->record; my @hiddenitems; - $marc = XSLTParse4Display($biblionumber, $marc, 'OPACXSLTCustomExport', 1, \@hiddenitems, undef, $xslFile, undef); + $marc = XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $marc, + xsl_syspref => "OPACXSLTCustomExport", + fix_amps => 1, + hidden_items => \@hiddenitems, + xslfilename => $xslFile, + } + ); } } else { diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index a7be90ba58..8335e0b2ec 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -32,7 +32,7 @@ use C4::Koha qw( use C4::Members; use C4::Output qw( pagination_bar output_with_http_headers ); use C4::Tags qw( get_tags ); -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use Koha::Biblios; use Koha::Biblioitems; @@ -498,6 +498,7 @@ $template->param( print => scalar $query->param('print') || 0, listsview => 1, staffuser => $staffuser, + xsl_exports => CustomXSLTExportList() ); my $content_type = $query->param('rss')? 'rss' : 'html'; diff --git a/t/XSLT.t b/t/XSLT.t index d80397e6ed..fa462c6b99 100755 --- a/t/XSLT.t +++ b/t/XSLT.t @@ -103,6 +103,7 @@ open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_03.xsl"; print $fh qq||; close $fh; +t::lib::Mocks::mock_preference( 'OpacExportOptions', 'custom'); my @custom_xslts = @{C4::XSLT::CustomXSLTExportList(1)}; ok((scalar @custom_xslts) == 2, "CustomXSLTExportList finds custom XSLTs"); ok($custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node"); diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 4758eb53af..a402f15333 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -18,7 +18,7 @@ use Modern::Perl; use MARC::Record; -use Test::More tests => 3; +use Test::More tests => 6; use Test::Warn; use t::lib::TestBuilder; use t::lib::Mocks; @@ -50,6 +50,16 @@ subtest 'CustomXSLTExportList: Caching' => sub { is( @$list, $n, 'This list comes from the cache and that is fine' ); $cache->clear_from_cache('CustomXSLTExportListOPAC'); }; +subtest 'CustomXSLTExportList: Check export options' => sub { + plan tests => 2; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + my $list = C4::XSLT::CustomXSLTExportList(1); + is( $list>0, 1, 'We expect at least one result: simple export' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, 0, 'We expect an empty list now' ); +}; subtest 'buildKohaItemsNamespace status tests' => sub { plan tests => 17; @@ -165,18 +175,6 @@ subtest 'buildKohaItemsNamespace status tests' => sub { t::lib::Mocks::mock_preference('UseRecalls', 0); }; -subtest 'CustomXSLTExportList: Caching' => sub { - plan tests => 1; - t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); - $cache->clear_from_cache('CustomXSLTExportListOPAC'); - my $list = C4::XSLT::CustomXSLTExportList(1); - push @$list, { nonsense => 1 }; - $cache->set_in_cache('CustomXSLTExportListOPAC', $list ); - my $n = @$list; - $list = C4::XSLT::CustomXSLTExportList(1); - is( @$list, $n, 'This list comes from the cache and that is fine' ); - $cache->clear_from_cache('CustomXSLTExportListOPAC'); -}; subtest 'CustomXSLTExportList: Check export options' => sub { plan tests => 2; t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl index d9939c5cb0..08ab34b185 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -25,7 +25,7 @@ use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Record; use C4::Ris qw( marc2ris ); -use C4::XSLT; +use C4::XSLT qw( XSLTParse4Display ); use Koha::Biblios; @@ -72,6 +72,7 @@ if ($shelfid && $format) { my $biblionumber = $content->biblionumber; my $biblio = Koha::Biblios->find($biblionumber); my $record = $biblio->metadata->record({ embed_items => 1 }); + my $xslFile = $query->param("file"); if ($format eq 'iso2709') { $output .= $record->as_usmarc(); } @@ -82,7 +83,16 @@ if ($shelfid && $format) { $output .= marc2bibtex($record, $biblionumber); } elsif ($format =~ /^xsl\.(.*)$/){ - $output .= XSLTParse4Display($biblionumber, $record, 'XSLTCustomExport', 1, undef, ,'',$1,''); + $output .= XSLTParse4Display( + { + biblionumber => $biblionumber, + record => $record, + xsl_syspref => 'XSLTCustomExport', + fix_amps => 1, + hidden_items => undef, + xslfilename => $xslFile, + } + ); } } } diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index aad027b485..f061970f7c 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -30,7 +30,7 @@ use C4::Koha qw( ); use C4::Members; use C4::Output qw( pagination_bar output_html_with_http_headers ); -use C4::XSLT qw( XSLTParse4Display ); +use C4::XSLT qw( XSLTParse4Display CustomXSLTExportList ); use Koha::Biblios; use Koha::Biblioitems; -- 2.34.1