From ba3fd46fbe9a9b821492ae86139dfe8577d32af5 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Wed, 4 Mar 2015 19:41:38 -0500 Subject: [PATCH] Bug 1985 - Add missing table variables, tweak License, and cleanup In comment #11, it was mentioned that title and biblionumber from the biblio table were not available as variables in the letter. This corrects this by converting the parameter list to a hashref, and adding the missing biblio number. It also cleans up the license on C4/Review.pm to be in line with the current coding guidelines license. Also strict and warning have been changed to the 'Use Modern::Perl;' now. TEST PLAN --------- 1) Create test branch and apply patch 2) run installer/data/mysql/updatedatabase.pl -- this will add the required default letter. 3) In the staff client: a) set the CommentModeratorsEmail system preference. -- not setting it will mean you won't get any queued letters. b) modify the COMMENT_CREATED default letter as desired. -- feel free to add other things. 4) In the OPAC: a) Log in b) Find something c) Click on the 'Comments' tab -- Holdings/Title notes/Comments (#) is at the bottom d) Click 'Post or edit your comments on this item' e) In the window that pops up, type your comment. f) Click 'Submit and close this window'. g) Click 'Edit' and repeat steps e and f again. 5) In a mysql client: a) Open the koha database b) SELECT * FROM message_queue WHERE letter_code='COMMENT_CREATED'; -- There should be at least two. -- They should be able to contain the borrower number, biblio title, and other borrower and biblio related things. -- Comments are at a biblio level, so items, and issues don't make sense as variables for the letter. 6) prove -v t/db_dependent/Review.t 6) Run the koha qa test tool. --- C4/Review.pm | 54 +++++++++++++++++---------- t/db_dependent/Review.t | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 20 deletions(-) create mode 100755 t/db_dependent/Review.t diff --git a/C4/Review.pm b/C4/Review.pm index dddac55..e326a11 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -4,23 +4,23 @@ package C4::Review; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use C4::Context; +require C4::Letters; use vars qw($VERSION @ISA @EXPORT); @@ -29,8 +29,10 @@ BEGIN { $VERSION = 3.07.00.049; require Exporter; @ISA = qw(Exporter); - @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber - getreviews getallreviews approvereview unapprovereview deletereview); + @EXPORT = qw(getreview savereview updatereview + numberofreviews numberofreviewsbybiblionumber + getreviews getallreviews approvereview + unapprovereview deletereview SendReviewAlert); } =head1 NAME @@ -83,7 +85,10 @@ sub savereview { $sth->execute( $borrowernumber, $biblionumber, $review); unless ($sth->err()) { - SendReviewAlert( $review, $borrowernumber ); + SendReviewAlert( { + 'review' => $review, + 'borrowernumber' => $borrowernumber, + 'biblionumber' => $biblionumber } ); } } @@ -95,7 +100,10 @@ sub updatereview { $sth->execute( $review, $borrowernumber, $biblionumber ); unless ($sth->err()) { - SendReviewAlert( $review, $borrowernumber ); + SendReviewAlert( { + 'review' => $review, + 'borrowernumber' => $borrowernumber, + 'biblionumber' => $biblionumber } ); } } @@ -196,23 +204,29 @@ sub deletereview { =head2 SendReviewAlert - SendReviewAlert( $review, $borrowernumber ); + SendReviewAlert( { 'review' => $review, + 'borrowernumber' => $borrowernumber, + 'biblionumber' => $biblionumber } ); =cut sub SendReviewAlert { - my $review = shift; - my $borrowernumber = shift; + my $params = shift; my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail'); - return unless $moderatorEmail; + my $review = $params->{'review'}; + my $borrowernumber = $params->{'borrowernumber'}; + my $biblionumber = $params->{'biblionumber'}; + my $letter = C4::Letters::GetPreparedLetter ( module => 'members', letter_code => 'COMMENT_CREATED', tables => { 'borrowers' => $borrowernumber, + 'biblio' => $biblionumber, + 'biblioitems' => $biblionumber, } ) or return; diff --git a/t/db_dependent/Review.t b/t/db_dependent/Review.t new file mode 100755 index 0000000..9c990a0 --- /dev/null +++ b/t/db_dependent/Review.t @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Test::More tests => 14; + +use_ok('C4::Review'); + +my $dbh = C4::Context->dbh; +$dbh->{RaiseError} = 1; +$dbh->{AutoCommit} = 0; + +my $sth = $dbh->prepare("SELECT * FROM borrowers;"); +$sth->execute(); +my $row = $sth->fetchrow_hashref(); +my $borrowernumber; +$borrowernumber = $row->{'borrowernumber'} if $row; +$sth = $dbh->prepare("SELECT * FROM biblio;"); +$sth->execute(); +$row = $sth->fetchrow_hashref(); +my $biblionumber; +$biblionumber = $row->{'biblionumber'} if $row; + +SKIP: { + skip "Missing borrowers or biblios",13 + unless $biblionumber and $borrowernumber; + + # Make sure there are no reviews + $sth = $dbh->prepare("DELETE FROM reviews;"); + $sth->execute(); + + # Clear out the message_queue to make counting easier. + $sth = $dbh->prepare("DELETE FROM message_queue;"); + $sth->execute(); + + # Add a review + savereview($biblionumber,$borrowernumber,'A sample review.'); + + # Retrieve review + my $reviews = getallreviews(0); + my $reviewid = $reviews->[0]->{'reviewid'}; + my $ReviewText = $reviews->[0]->{'review'}; + ok($ReviewText eq 'A sample review.','Saved and retrieved a sample review.'); + + # Update the review + updatereview($biblionumber,$borrowernumber,'A revised review.'); + + # Retrieve it differently. + my $review = getreview($biblionumber,$borrowernumber); + $ReviewText = $review->{'review'}; + ok($ReviewText eq 'A revised review.','Updated and retrieved a revised review.'); + + # Confirm 1 unapproved comment. + my $UnapprovedReviewsCount = numberofreviews(0); + ok($UnapprovedReviewsCount==1,'There is one unapproved comment.'); + + # Approve the comment. + approvereview($reviewid); + $UnapprovedReviewsCount = numberofreviews(0); + ok($UnapprovedReviewsCount==0,'There are no unapproved comments.'); + my $ApprovedReviewsCount = numberofreviews(1); + ok($ApprovedReviewsCount==1,'There is one approved comment.'); + + # Check how many reviews for this biblionumber. + my $ReviewsCount = numberofreviewsbybiblionumber($biblionumber); + ok($ReviewsCount==1,'There is one approved comment for this biblio.'); + + # Unapprove the comment. + unapprovereview($reviewid); + $UnapprovedReviewsCount = numberofreviews(0); + ok($UnapprovedReviewsCount==1,'There is one unapproved comment.'); + $ApprovedReviewsCount = numberofreviews(1); + ok($ApprovedReviewsCount==0,'There are no approved comments.'); + + # Delete the review. + deletereview($reviewid); + $UnapprovedReviewsCount = numberofreviews(0); + ok($UnapprovedReviewsCount==0,'There are no unapproved comments.'); + $ApprovedReviewsCount = numberofreviews(1); + ok($ApprovedReviewsCount==0,'There are no approved comments.'); + + my $ApprovedReviews = getreviews($biblionumber,1); + my $UnapprovedReviews = getreviews($biblionumber,0); + ok(scalar @$ApprovedReviews==0,'No approved comment records.'); + ok(scalar @$UnapprovedReviews==0,'No unapproved comment records.'); + + # Only save, update, and SendReviewAlert should trigger letters. + SendReviewAlert( { 'review' => 'A sample review unused.', + 'biblionumber' => $biblionumber, + 'borrowernumber' => $borrowernumber }); + + $sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue;"); + $sth->execute(); + my $LetterCount = $sth->fetchrow(); + ok($LetterCount==3,'There are three triggered reminders as expected.'); +} + +$dbh->rollback(); -- 1.9.1