[Koha-patches] [PATCH] Block warning on detail.pl.

Joe Atzberger joe.atzberger at liblime.com
Wed Jan 21 02:18:20 CET 2009


If Amazon doesn't have an avg. rating number defined, then we cannot multiply it
by 20 without the following warning:

    detail.pl: Use of uninitialized value in multiplication (*)
    at /home/user/kohaclone/catalogue/detail.pl line 228.

So the important part of this patch is || 0 on the $average_rating assignment.
---
 catalogue/detail.pl |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/catalogue/detail.pl b/catalogue/detail.pl
index 393ec16..d21b8a7 100755
--- a/catalogue/detail.pl
+++ b/catalogue/detail.pl
@@ -210,8 +210,8 @@ if (C4::Context->preference("FRBRizeEditions")==1) {
 if ( C4::Context->preference("AmazonContent") == 1 ) {
     my $similar_products_exist;
     my $amazon_details = &get_amazon_details( $xisbn, $record, $marcflavour );
-    my $item_attributes = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
-    my $customer_reviews = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
+    my $item_attributes   = \%{$amazon_details->{Items}->{Item}->{ItemAttributes}};
+    my $customer_reviews  = \@{$amazon_details->{Items}->{Item}->{CustomerReviews}->{Review}};
     my @similar_products;
     for my $similar_product (@{$amazon_details->{Items}->{Item}->{SimilarProducts}->{SimilarProduct}}) {
         # do we have any of these isbns in our collection?
@@ -223,11 +223,11 @@ if ( C4::Context->preference("AmazonContent") == 1 ) {
         }
     }
     my $editorial_reviews = \@{$amazon_details->{Items}->{Item}->{EditorialReviews}->{EditorialReview}};
-    my $average_rating = $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating};
-    $template->param( AmazonSimilarItems => $similar_products_exist );
-    $template->param( amazon_average_rating => $average_rating * 20);
-    $template->param( AMAZON_CUSTOMER_REVIEWS    => $customer_reviews );
-    $template->param( AMAZON_SIMILAR_PRODUCTS => \@similar_products );
-    $template->param( AMAZON_EDITORIAL_REVIEWS    => $editorial_reviews );
+    my $average_rating    =    $amazon_details->{Items}->{Item}->{CustomerReviews}->{AverageRating} || 0;
+    $template->param( AmazonSimilarItems       => $similar_products_exist );
+    $template->param( amazon_average_rating    => $average_rating * 20    );
+    $template->param( AMAZON_CUSTOMER_REVIEWS  => $customer_reviews       );
+    $template->param( AMAZON_SIMILAR_PRODUCTS  => \@similar_products      );
+    $template->param( AMAZON_EDITORIAL_REVIEWS => $editorial_reviews      );
 }
 output_html_with_http_headers $query, $cookie, $template->output;
-- 
1.5.5.GIT



More information about the Koha-patches mailing list