From 3e3a658754e184b87630dc490c4f6c102c364b7e Mon Sep 17 00:00:00 2001 From: Victor Grousset Date: Fri, 15 Dec 2017 15:22:24 +0100 Subject: [PATCH] Fix opac-detail being broken by a review from a deleted patron And other display issues when the patron was NULL. Which allows to keep the review even if it has no patron. Because it might be useful. For example when disconnected, the borrowernumber is null. So the comments from deleted patrons were displayed as if the disconnected user wrote them. So it had the edit button... And fix borrowernumber not being passed to the template when OpacStarRatings was false. Test plan 1. Log in as a patron 2. Leave a comment/review on a record 3. Librarian: approve this comment 4. Delete the borrower 5. See the record (opac:/cgi-bin/koha/opac-detail.pl?biblionumber=RELEVANT_BIB_NUMBER) 6. Then you should see an error 7. Apply this patch 8. Refresh the page 9. Then you should see the record page with the comment https://bugs.koha-community.org/show_bug.cgi?id=19808 --- .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 20 +++++++++++--------- opac/opac-detail.pl | 14 +++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index eb857ec..9eaccdb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -905,7 +905,7 @@
[% IF ( reviews ) %] [% FOREACH review IN reviews %] - [% IF review.borrowernumber == borrowernumber %] + [% IF borrowernumber && review.borrowernumber == borrowernumber %]
[% IF ( review.avatarurl ) %] @@ -925,26 +925,28 @@
[% ELSE %]
- [% IF ( ShowReviewer != "none" ) %] + [% IF ( ShowReviewer != "none" && review.patron) %] + [% IF ( review.avatarurl ) %] [% END %] [% SWITCH ShowReviewer %] [% CASE 'full' %] -
Comment by [% review.title %] [% review.firstname %] [% review.surname %]
+
Comment by [% review.patron.title %] [% review.patron.firstname %] [% review.patron.surname %]
[% CASE 'first' %] -
Comment by [% review.firstname %]
+
Comment by [% review.patron.firstname %]
[% CASE 'surname' %] -
Comment by [% review.surname %]
+
Comment by [% review.patron.surname %]
[% CASE 'firstandinitial' %] -
Comment by [% review.firstname %] [% review.surname|truncate(2,'.') %]
+
Comment by [% review.patron.firstname %] [% review.patron.surname|truncate(2,'.') %]
[% CASE 'username' %] -
Comment by [% review.userid %]
+
Comment by [% review.patron.userid %]
[% END %] + [% review.datereviewed | $KohaDates %] - [% ELSIF ( ShowReviewer == "none") %] + [% ELSE %]
Patron comment on [% review.datereviewed | $KohaDates %]
- [% END # / IF ShowReviewer != "none"%] + [% END # / IF ShowReviewer != "none" && review.patron %]

[% FILTER html_break %] [% review.review |html %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 819e426..745c49c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -844,17 +844,12 @@ if ( C4::Context->preference('reviewson') ) { my $patron = Koha::Patrons->find( $review->{borrowernumber} ); # setting some borrower info into this hash - $review->{title} = $patron->title; - $review->{surname} = $patron->surname; - $review->{firstname} = $patron->firstname; - if ( $libravatar_enabled and $patron->email ) { + $review->{patron} = $patron; + if ( $libravatar_enabled and $patron and $patron->email ) { $review->{avatarurl} = libravatar_url( email => $patron->email, https => $ENV{HTTPS} ); } - $review->{userid} = $patron->userid; - $review->{cardnumber} = $patron->cardnumber; - if ( $patron->borrowernumber eq $borrowernumber ) { - $review->{your_comment} = 1; + if ( $patron and $patron->borrowernumber eq $borrowernumber ) { $loggedincommenter = 1; } } @@ -1102,13 +1097,14 @@ if (C4::Context->preference("OPACURLOpenInNewWindow")) { $template->param(covernewwindow => 'false'); } +$template->param(borrowernumber => $borrowernumber); + if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) { my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef; $template->param( ratings => $ratings, my_rating => $my_rating, - borrowernumber => $borrowernumber ); } -- 2.7.4