From 2f1cba8b31063ea81862abd37aae009072b1fb15 Mon Sep 17 00:00:00 2001 From: Srdjan Date: Tue, 18 Apr 2017 14:33:38 +1200 Subject: [PATCH] Bug 17602: Koha::ExternalContent->koha_patron() will retutn undef rather than die if user not logged in Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- Koha/ExternalContent.pm | 2 +- Koha/ExternalContent/OverDrive.pm | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Koha/ExternalContent.pm b/Koha/ExternalContent.pm index 7f5d8ed222..567d589bc6 100644 --- a/Koha/ExternalContent.pm +++ b/Koha/ExternalContent.pm @@ -86,7 +86,7 @@ sub koha_patron { } my $id = $self->get_from_koha_session('number') - or die "No patron number in session"; + or return; my $patron = Koha::Patrons->find($id) or die "Invalid patron number in session"; return $self->_koha_patron_accessor($patron); diff --git a/Koha/ExternalContent/OverDrive.pm b/Koha/ExternalContent/OverDrive.pm index 4cde086417..da84a4d19e 100644 --- a/Koha/ExternalContent/OverDrive.pm +++ b/Koha/ExternalContent/OverDrive.pm @@ -135,7 +135,9 @@ sub auth_by_code { $access_token or die "Invalid OverDrive code returned"; $self->set_token_in_koha_session($access_token, $access_token_type); - $self->koha_patron->set({overdrive_auth_token => $auth_token})->store; + if (my $koha_patron = $self->koha_patron) { + $koha_patron->set({overdrive_auth_token => $auth_token})->store; + } return $self->get_return_page_from_koha_session; } @@ -202,7 +204,8 @@ sub is_logged_in { sub auth_by_saved_token { my $self = shift; - my $koha_patron = $self->koha_patron; + my $koha_patron = $self->koha_patron or return; + if (my $auth_token = $koha_patron->overdrive_auth_token) { my ($access_token, $access_token_type, $new_auth_token) = $self->client->auth_by_token($auth_token); @@ -224,7 +227,9 @@ sub forget { my $self = shift; $self->set_token_in_koha_session("", ""); - $self->koha_patron->set({overdrive_auth_token => undef})->store; + if (my $koha_patron = $self->koha_patron) { + $koha_patron->set({overdrive_auth_token => undef})->store; + } } use vars qw{$AUTOLOAD}; -- 2.39.5