From 320f9bf3d29b145eb2c6948ae517d0fe2e704f5f Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Sat, 17 Nov 2018 11:58:02 +0100 Subject: [PATCH] Bug 21853: Fix PDF export of basketgroups In recent versions of Perl, '.' is not included by default in @INC. This breaks PDF export of basketgroups. This patch moves acqui/pdfformat/*.pm files in Koha namespace so that they can be 'require'd without manipulating @INC Test plan: 1. Turn off Plack/Starman and test PDF export for every value of OrderPdfFormat system preference 2. Turn on Plack/Starman and test PDF export for every value of OrderPdfFormat system preference 3. Test on a dev install and a standard/package install Signed-off-by: Mark Tompsett Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens (cherry picked from commit 3c18d4c18fad5a0d470c7bdf1ac746a640f25099) Signed-off-by: Jesse Maseto --- {acqui => Koha}/pdfformat/layout2pages.pm | 3 +- {acqui => Koha}/pdfformat/layout2pagesde.pm | 3 +- {acqui => Koha}/pdfformat/layout3pages.pm | 3 +- {acqui => Koha}/pdfformat/layout3pagesfr.pm | 2 +- acqui/basketgroup.pl | 31 ++++++++++----------- 5 files changed, 19 insertions(+), 23 deletions(-) rename {acqui => Koha}/pdfformat/layout2pages.pm (99%) rename {acqui => Koha}/pdfformat/layout2pagesde.pm (99%) rename {acqui => Koha}/pdfformat/layout3pages.pm (99%) rename {acqui => Koha}/pdfformat/layout3pagesfr.pm (99%) diff --git a/acqui/pdfformat/layout2pages.pm b/Koha/pdfformat/layout2pages.pm similarity index 99% rename from acqui/pdfformat/layout2pages.pm rename to Koha/pdfformat/layout2pages.pm index 0d2a6e7a6d..90537c37ea 100644 --- a/acqui/pdfformat/layout2pages.pm +++ b/Koha/pdfformat/layout2pages.pm @@ -1,4 +1,4 @@ -#!/usr/bin/perl +package Koha::pdfformat::layout2pages; #example script to print a basketgroup #written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com @@ -21,7 +21,6 @@ # along with Koha; if not, see . #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout2pages; use vars qw(@ISA @EXPORT); use MIME::Base64; use Modern::Perl; diff --git a/acqui/pdfformat/layout2pagesde.pm b/Koha/pdfformat/layout2pagesde.pm similarity index 99% rename from acqui/pdfformat/layout2pagesde.pm rename to Koha/pdfformat/layout2pagesde.pm index 63269df32f..aeee17bd4a 100644 --- a/acqui/pdfformat/layout2pagesde.pm +++ b/Koha/pdfformat/layout2pagesde.pm @@ -1,4 +1,4 @@ -#!/usr/bin/perl +package Koha::pdfformat::layout2pagesde; #example script to print a basketgroup #written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com @@ -21,7 +21,6 @@ # along with Koha; if not, see . #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout2pagesde; use vars qw(@ISA @EXPORT); use MIME::Base64; use Modern::Perl; diff --git a/acqui/pdfformat/layout3pages.pm b/Koha/pdfformat/layout3pages.pm similarity index 99% rename from acqui/pdfformat/layout3pages.pm rename to Koha/pdfformat/layout3pages.pm index 8f80fe26a6..d02160ebcd 100644 --- a/acqui/pdfformat/layout3pages.pm +++ b/Koha/pdfformat/layout3pages.pm @@ -1,4 +1,4 @@ -#!/usr/bin/perl +package Koha::pdfformat::layout3pages; #example script to print a basketgroup #written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com @@ -21,7 +21,6 @@ # along with Koha; if not, see . #you can use any PDF::API2 module, all you need to do is return the stringifyed pdf object from the printpdf sub. -package pdfformat::layout3pages; use vars qw(@ISA @EXPORT); use MIME::Base64; use List::MoreUtils qw/uniq/; diff --git a/acqui/pdfformat/layout3pagesfr.pm b/Koha/pdfformat/layout3pagesfr.pm similarity index 99% rename from acqui/pdfformat/layout3pagesfr.pm rename to Koha/pdfformat/layout3pagesfr.pm index 5568e0157b..b4bdf7874d 100644 --- a/acqui/pdfformat/layout3pagesfr.pm +++ b/Koha/pdfformat/layout3pagesfr.pm @@ -1,4 +1,4 @@ -#!/usr/bin/perl +package Koha::pdfformat::layout3pagesfr; #example script to print a basketgroup #written 07/11/08 by john.soros@biblibre.com and paul.poulain@biblibre.com diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index 05c505ad54..e1cba8495b 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -49,6 +49,7 @@ use Carp; use C4::Auth; use C4::Output; use CGI qw ( -utf8 ); +use File::Spec; use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/; use Koha::EDI qw/create_edi_order get_edifact_ean/; @@ -123,29 +124,27 @@ sub displaybasketgroups { sub printbasketgrouppdf{ my ($basketgroupid) = @_; - + my $pdfformat = C4::Context->preference("OrderPdfFormat"); - if ($pdfformat eq 'pdfformat::layout3pages' || $pdfformat eq 'pdfformat::layout2pages' || $pdfformat eq 'pdfformat::layout3pagesfr' - || $pdfformat eq 'pdfformat::layout2pagesde'){ - eval { - eval "require $pdfformat"; - import $pdfformat; - }; - if ($@){ - } + my @valid_pdfformats = qw(pdfformat::layout3pages pdfformat::layout2pages pdfformat::layout3pagesfr pdfformat::layout2pagesde); + if (grep {$_ eq $pdfformat} @valid_pdfformats) { + $pdfformat = "Koha::$pdfformat"; + my $pdfformat_filepath = File::Spec->catfile(split /::/, $pdfformat) . '.pm'; + require $pdfformat_filepath; + import $pdfformat; } else { - print $input->header; - print $input->start_html; # FIXME Should do a nicer page - print "

Invalid PDF Format set

"; - print "Please go to the systempreferences and set a valid pdfformat"; - exit; + print $input->header; + print $input->start_html; # FIXME Should do a nicer page + print "

Invalid PDF Format set

"; + print "Please go to the systempreferences and set a valid pdfformat"; + exit; } - + my $basketgroup = GetBasketgroup($basketgroupid); my $bookseller = Koha::Acquisition::Booksellers->find( $basketgroup->{booksellerid} ); my $baskets = GetBasketsByBasketgroup($basketgroupid); - + my %orders; for my $basket (@$baskets) { my @ba_orders; -- 2.39.5