Bug 19808: Handle deleted reviewers gracefully - opac-showreview
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 18 Dec 2017 16:32:14 +0000 (13:32 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Dec 2017 14:07:37 +0000 (11:07 -0300)
Test plan:
- Create reviews
- Delete some reviewers
- Enable OpacShowRecentComments
- Go to opac/opac-showreviews.pl
- Go to opac-showreviews.pl?format=rss

Signed-off-by: Jon Knight <J.P.Knight@lboro.ac.uk>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
opac/opac-showreviews.pl

index b844167..a711b7f 100755 (executable)
@@ -93,7 +93,6 @@ for my $result (@$reviews){
     my $biblioitem = $biblio->biblioitem;
     my $record = GetMarcBiblio({ biblionumber => $biblionumber });
     my $frameworkcode = GetFrameworkCode($biblionumber);
-    my $borr = Koha::Patrons->find( $result->{borrowernumber} )->unblessed;
        $result->{normalized_upc} = GetNormalizedUPC($record,$marcflavour);
        $result->{normalized_ean} = GetNormalizedEAN($record,$marcflavour);
        $result->{normalized_oclc} = GetNormalizedOCLCNumber($record,$marcflavour);
@@ -108,17 +107,21 @@ for my $result (@$reviews){
     $result->{size} = $biblioitem->size;
     $result->{notes} = $biblioitem->notes;
     $result->{timestamp} = $biblioitem->timestamp;
-    $result->{borrtitle} = $borr->{'title'};
-       $result->{firstname} = $borr->{'firstname'};
-       $result->{surname} = $borr->{'surname'};
-    $result->{userid} = $borr->{'userid'};
-        if ($libravatar_enabled and $borr->{'email'}) {
-            $result->{avatarurl} = libravatar_url(email => $borr->{'email'}, size => 40, https => $ENV{HTTPS});
-        }
 
-    if ($result->{borrowernumber} eq $borrowernumber) {
-               $result->{your_comment} = 1;
-       }
+    my $patron = Koha::Patrons->find( $result->{borrowernumber} );
+    if ( $patron ) {
+        $result->{borrtitle} = $patron->title;
+        $result->{firstname} = $patron->firstname;
+        $result->{surname} = $patron->surname;
+        $result->{userid} = $patron->userid;
+            if ($libravatar_enabled and $patron->email) {
+                $result->{avatarurl} = libravatar_url(email => $patron->email, size => 40, https => $ENV{HTTPS});
+            }
+
+        if ($result->{borrowernumber} eq $borrowernumber) {
+            $result->{your_comment} = 1;
+        }
+    }
 
     if($format eq "rss"){
         my $rsstimestamp = eval { dt_from_string( $result->{datereviewed} ); };