Bug 15758: [QA Follow-up] Some corrections related to GetBranchName
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 26 Aug 2016 07:02:04 +0000 (09:02 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 8 Sep 2016 14:36:05 +0000 (14:36 +0000)
[1] Acquisition.pm
The lines filling $row in GetBasketGroupAsCSV may have side-effects when
the library name is not found. This change restores former behavior. Just
theoretically more safe.
Note that it also contained a typo: $row->{deliveryplace} should have been
$row->{$place}.

[2] Auth.pm
checkauth: $branchname = Koha::Libraries->find($branchcode)->branchname;
Should normally be fine, but I rather have an empty string here than
crashing on "Can't call method branchname on undefined value".
Same for sub check_api_auth.
Note that this holds for a larger number of calls, but I am adding a check
here because it is checkauth.
Also removed a duplicate use Koha::Libraries-statement.

[3] Search.pm
Also removed a duplicate use statement for Libraries.

[4] svc/holds
Added an (explicit) use statement for Koha::Libraries.

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Acquisition.pm
C4/Auth.pm
C4/Search.pm
svc/holds

index f9c12d7..6a2ed3e 100644 (file)
@@ -377,13 +377,15 @@ sub GetBasketGroupAsCSV {
                 booksellerpostal => $bookseller->{postal},
                 contractnumber => $contract->{contractnumber},
                 contractname => $contract->{contractname},
+            };
+            my $temp = {
                 basketgroupdeliveryplace => $basketgroup->{deliveryplace},
                 basketgroupbillingplace  => $basketgroup->{billingplace},
                 basketdeliveryplace      => $basket->{deliveryplace},
                 basketbillingplace       => $basket->{billingplace},
             };
             for my $place (qw( basketgroupdeliveryplace basketgroupbillingplace basketdeliveryplace basketbillingplace )) {
-                if ( my $library = Koha::Libraries->find( $row->{deliveryplace} ) ) {
+                if ( my $library = Koha::Libraries->find( $temp->{$place} ) ) {
                     $row->{$place} = $library->branchname;
                 }
             }
index cb6ecda..fcf7c48 100644 (file)
@@ -35,7 +35,6 @@ use Koha::Caches;
 use Koha::AuthUtils qw(get_script_name hash_password);
 use Koha::Libraries;
 use Koha::LibraryCategories;
-use Koha::Libraries;
 use POSIX qw/strftime/;
 use List::MoreUtils qw/ any /;
 use Encode qw( encode is_utf8);
@@ -1076,7 +1075,8 @@ sub checkauth {
                     # if they specify at login, use that
                     if ( $query->param('branch') ) {
                         $branchcode = $query->param('branch');
-                        $branchname = Koha::Libraries->find($branchcode)->branchname;
+                        my $library = Koha::Libraries->find($branchcode);
+                        $branchname = $library? $library->branchname: '';
                     }
                     my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
                     if ( C4::Context->boolean_preference('IndependentBranches') && C4::Context->boolean_preference('Autolocation') ) {
@@ -1526,7 +1526,8 @@ sub check_api_auth {
                 # if they specify at login, use that
                 if ( $query->param('branch') ) {
                     $branchcode = $query->param('branch');
-                    $branchname = Koha::Libraries->find($branchcode)->branchname;
+                    my $library = Koha::Libraries->find($branchcode);
+                    $branchname = $library? $library->branchname: '';
                 }
                 my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search };
                 foreach my $br ( keys %$branches ) {
index 4446349..7e71469 100644 (file)
@@ -31,7 +31,6 @@ use C4::XSLT;
 use C4::Reserves;    # GetReserveStatus
 use C4::Debug;
 use C4::Charset;
-use Koha::Libraries;
 use YAML;
 use URI::Escape;
 use Business::ISBN;
index 5aefb6b..0a6f51d 100755 (executable)
--- a/svc/holds
+++ b/svc/holds
@@ -30,6 +30,7 @@ use C4::Context;
 
 use Koha::DateUtils;
 use Koha::Holds;
+use Koha::Libraries;
 
 my $input = new CGI;