From 09d00bf04002988169fa43b84ea52fa5e7d30415 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 Aug 2016 17:06:56 +0100 Subject: [PATCH] Bug 17089: Improve errors handling Signed-off-by: Owen Leonard Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- opac/opac-ratings-ajax.pl | 8 +++++--- opac/opac-ratings.pl | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/opac/opac-ratings-ajax.pl b/opac/opac-ratings-ajax.pl index 672e7f35d5..25675add0d 100755 --- a/opac/opac-ratings-ajax.pl +++ b/opac/opac-ratings-ajax.pl @@ -72,7 +72,8 @@ my $rating; $rating_value //= ''; if ( $rating_value eq '' ) { - Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } )->delete; + my $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser } ); + $rating->delete if $rating; } elsif ( $rating_value and !$rating_old_value ) { @@ -80,7 +81,8 @@ elsif ( $rating_value and !$rating_old_value ) { } elsif ( $rating_value ne $rating_old_value ) { - Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store; + my $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser }); + $rating->rating_value($rating_value)->store if $rating } my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber }); @@ -91,7 +93,7 @@ my %js_reply = ( rating_total => $ratings->count, rating_avg => $avg, rating_avg_int => sprintf("%.0f", $avg), - rating_value => $my_rating->rating_value, + rating_value => $my_rating ? $my_rating->rating_value : undef, auth_status => $auth_status, ); diff --git a/opac/opac-ratings.pl b/opac/opac-ratings.pl index d936b13b65..1951a2daee 100755 --- a/opac/opac-ratings.pl +++ b/opac/opac-ratings.pl @@ -53,10 +53,12 @@ unless ( $biblionumber and $rating_value ) { } if ( !$rating_old_value ) { - Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, })->store; + my $rating = Koha::Rating->new( { biblionumber => $biblionumber, borrowernumber => $loggedinuser, rating_value => $rating_value, }); + $rating->store if $rating; } else { - Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser })->rating_value($rating_value)->store; + my $rating = Koha::Ratings->find( { biblionumber => $biblionumber, borrowernumber => $loggedinuser }); + $rating->rating_value($rating_value)->store if $rating; } print $query->redirect( "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber"); -- 2.39.5