From b0d6af20e4174ea799cc8a522df9bea235031b8a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Aug 2017 09:54:27 -0300 Subject: [PATCH] Bug 19048: (bug 17829 follow-up) Fix regression in self checkout $patronid is not necessarily set or does not match a valid cardnumber. These cases must be taken into account to avoid the script to crash and raise the following error: Can't call method "unblessed" on an undefined value at (...)/koha/opac/sco/sco-main.pl line 117 Test plan: Hit sco/sco-main.pl and confirm that the error is gone with this patch applied Signed-off-by: Owen Leonard Signed-off-by: Tomas Cohen Arazi --- opac/sco/sco-main.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index 80ac47d..4020e27 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -114,7 +114,12 @@ if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { my $resval; ($resval, $patronid) = checkpw($dbh, $patronlogin, $patronpw); } -my $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed; + +my $borrower; +if ( $patronid ) { + $borrower = Koha::Patrons->find( { cardnumber => $patronid } ); + $borrower = $borrower->unblessed if $borrower; +} my $currencySymbol = ""; if ( my $active_currency = Koha::Acquisition::Currencies->get_active ) { @@ -131,10 +136,8 @@ if ($op eq "logout") { } elsif ( $op eq "returnbook" && $allowselfcheckreturns ) { my ($doreturn) = AddReturn( $barcode, $branch ); - #warn "returnbook: " . $doreturn; - $borrower = Koha::Patrons->find( { cardnumber => $patronid } )->unblessed; } -elsif ( $op eq "checkout" ) { +elsif ( $borrower and $op eq "checkout" ) { my $impossible = {}; my $needconfirm = {}; ( $impossible, $needconfirm ) = CanBookBeIssued( @@ -250,7 +253,7 @@ elsif ( $op eq "checkout" ) { } } # $op -if ($borrower->{cardnumber}) { +if ($borrower) { # warn "issuer's branchcode: " . $issuer->{branchcode}; # warn "user's branchcode: " . $borrower->{branchcode}; my $borrowername = sprintf "%s %s", ($borrower->{firstname} || ''), ($borrower->{surname} || ''); -- 2.7.4