Bug 17294: Make reserves_stats.pl plack safe
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 13 Sep 2016 08:44:41 +0000 (09:44 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Sun, 25 Sep 2016 13:44:58 +0000 (13:44 +0000)
Lot of errors are raised by this script under plack because of var scope
issues:

Variable "$ccodes" is not available at
/home/koha/src/reports/reserves_stats.pl line 337.
Variable "$locations" is not available at
/home/koha/src/reports/reserves_stats.pl line 338.
Variable "$itemtypes" is not available at
/home/koha/src/reports/reserves_stats.pl line 339.
Variable "$Bsort1" is not available at
/home/koha/src/reports/reserves_stats.pl line 344.
Variable "$Bsort2" is not available at
/home/koha/src/reports/reserves_stats.pl line 350.
Variable "@patron_categories" is not available at
/home/koha/src/reports/reserves_stats.pl line 356.

The lazy way to fix that is that reinit them from the subroutines they
are used.

Test plan:
Execute the report, after this patch applied you won't see the error in
the log.

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
reports/reserves_stats.pl

index a444bc5..fe1d73c 100755 (executable)
@@ -330,6 +330,12 @@ sub null_to_zzempty ($) {
 }
 sub display_value {
     my ( $crit, $value ) = @_;
+    my $ccodes    = GetKohaAuthorisedValues("items.ccode");
+    my $locations = GetKohaAuthorisedValues("items.location");
+    my $itemtypes = GetItemTypes();
+    my $authvalue = GetKohaAuthorisedValues("items.authvalue");
+    my $Bsort1 = GetAuthorisedValues("Bsort1");
+    my $Bsort2 = GetAuthorisedValues("Bsort2");
     my $display_value =
         ( $crit =~ /ccode/ )         ? $ccodes->{$value}
       : ( $crit =~ /location/ )      ? $locations->{$value}
@@ -350,6 +356,7 @@ sub display_value {
         }
     }
     elsif ( $crit =~ /category/ ) {
+        my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
         foreach my $patron_category ( @patron_categories ) {
             ( $value eq $patron_category->categorycode ) or next;
             $display_value = $patron_category->description and last;