Bug 17602: Koha::ExternalContent->koha_patron() will retutn undef rather than die...
authorSrdjan <srdjan@catalyst.net.nz>
Tue, 18 Apr 2017 02:33:38 +0000 (14:33 +1200)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 1 Oct 2018 13:56:38 +0000 (13:56 +0000)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Koha/ExternalContent.pm
Koha/ExternalContent/OverDrive.pm

index 7f5d8ed..567d589 100644 (file)
@@ -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);
index 4cde086..da84a4d 100644 (file)
@@ -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};