Bug 21853: Fix PDF export of basketgroups
authorJulian Maurice <julian.maurice@biblibre.com>
Sat, 17 Nov 2018 10:58:02 +0000 (11:58 +0100)
committerJesse Maseto <jesse@bywatersolution.com>
Fri, 7 Dec 2018 18:30:57 +0000 (18:30 +0000)
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 <mtompset@hotmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 3c18d4c18fad5a0d470c7bdf1ac746a640f25099)

Signed-off-by: Jesse Maseto <jesse@bywatersolution.com>

Koha/pdfformat/layout2pages.pm [moved from acqui/pdfformat/layout2pages.pm with 99% similarity]
Koha/pdfformat/layout2pagesde.pm [moved from acqui/pdfformat/layout2pagesde.pm with 99% similarity]
Koha/pdfformat/layout3pages.pm [moved from acqui/pdfformat/layout3pages.pm with 99% similarity]
Koha/pdfformat/layout3pagesfr.pm [moved from acqui/pdfformat/layout3pagesfr.pm with 99% similarity]
acqui/basketgroup.pl

similarity index 99%
rename from acqui/pdfformat/layout2pages.pm
rename to Koha/pdfformat/layout2pages.pm
index 0d2a6e7..90537c3 100644 (file)
@@ -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 <http://www.gnu.org/licenses>.
 
 #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;
similarity index 99%
rename from acqui/pdfformat/layout2pagesde.pm
rename to Koha/pdfformat/layout2pagesde.pm
index 63269df..aeee17b 100644 (file)
@@ -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 <http://www.gnu.org/licenses>.
 
 #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;
similarity index 99%
rename from acqui/pdfformat/layout3pages.pm
rename to Koha/pdfformat/layout3pages.pm
index 8f80fe2..d02160e 100644 (file)
@@ -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 <http://www.gnu.org/licenses>.
 
 #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/;
similarity index 99%
rename from acqui/pdfformat/layout3pagesfr.pm
rename to Koha/pdfformat/layout3pagesfr.pm
index 5568e01..b4bdf78 100644 (file)
@@ -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
index 05c505a..e1cba84 100755 (executable)
@@ -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 "<h1>Invalid PDF Format set</h1>";
-       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 "<h1>Invalid PDF Format set</h1>";
+        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;