From eb950f4cc4d0ea759673deb8f272e0e043248b8f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Feb 2016 16:06:27 +0000 Subject: [PATCH] Bug 15839: Koha::Reviews - Remove approvereview & unapprovereview This patch adds 2 new methods to Koha::Review: approve and unapprove. Signed-off-by: Marc Veron Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- C4/Review.pm | 38 +---------------------------------- Koha/Review.pm | 26 ++++++++++++++++++++++++ reviews/reviewswaiting.pl | 6 ++++-- t/db_dependent/Koha/Reviews.t | 9 ++++++++- 4 files changed, 39 insertions(+), 40 deletions(-) diff --git a/C4/Review.pm b/C4/Review.pm index 9b27c440a0..a5aa07da1f 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -28,7 +28,7 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber - approvereview unapprovereview deletereview); + deletereview); } =head1 NAME @@ -138,42 +138,6 @@ sub numberofreviewsbybiblionumber { return $sth->fetchrow; } -=head2 approvereview - - approvereview($reviewid); - -Takes a reviewid and marks that review approved - -=cut - -sub approvereview { - my ($reviewid) = @_; - my $dbh = C4::Context->dbh(); - my $query = "UPDATE reviews - SET approved=? - WHERE reviewid=?"; - my $sth = $dbh->prepare($query); - $sth->execute( 1, $reviewid ); -} - -=head2 unapprovereview - - unapprovereview($reviewid); - -Takes a reviewid and marks that review as not approved - -=cut - -sub unapprovereview { - my ($reviewid) = @_; - my $dbh = C4::Context->dbh(); - my $query = "UPDATE reviews - SET approved=? - WHERE reviewid=?"; - my $sth = $dbh->prepare($query); - $sth->execute( 0, $reviewid ); -} - =head2 deletereview deletereview($reviewid); diff --git a/Koha/Review.pm b/Koha/Review.pm index 082f71fc4a..72e3e2fb3b 100644 --- a/Koha/Review.pm +++ b/Koha/Review.pm @@ -33,6 +33,32 @@ Koha::Review - Koha Review Object class =cut +=head3 approve + + $review->approve + +Approve a review + +=cut + +sub approve { + my ( $self ) = @_; + $self->approved(1)->store; +} + +=head3 unapprove + + $review->unapprove + +Unapprove a review + +=cut + +sub unapprove { + my ( $self ) = @_; + $self->approved(0)->store; +} + =head3 type =cut diff --git a/reviews/reviewswaiting.pl b/reviews/reviewswaiting.pl index b534391764..b1b8234fa7 100755 --- a/reviews/reviewswaiting.pl +++ b/reviews/reviewswaiting.pl @@ -46,10 +46,12 @@ my $count = C4::Context->preference('numSearchResults') || 20; my $total = numberofreviews($status); if ( $op eq 'approve' ) { - approvereview($reviewid); + my $review = Koha::Reviews->find( $reviewid ); + $review->approve if $review; } elsif ( $op eq 'unapprove' ) { - unapprovereview($reviewid); + my $review = Koha::Reviews->find( $reviewid ); + $review->unapprove if $review; } elsif ( $op eq 'delete' ) { deletereview($reviewid); diff --git a/t/db_dependent/Koha/Reviews.t b/t/db_dependent/Koha/Reviews.t index 321a536057..da164f782b 100644 --- a/t/db_dependent/Koha/Reviews.t +++ b/t/db_dependent/Koha/Reviews.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 7; use Koha::Review; use Koha::Reviews; @@ -36,6 +36,7 @@ my $patron_2 = $builder->build({ source => 'Borrower' }); my $biblio_1 = $builder->build({ source => 'Biblio' }); my $biblio_2 = $builder->build({ source => 'Biblio' }); my $nb_of_reviews = Koha::Reviews->search->count; +my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count; my $new_review_1_1 = Koha::Review->new({ borrowernumber => $patron_1->{borrowernumber}, biblionumber => $biblio_1->{biblionumber}, @@ -55,6 +56,12 @@ my $new_review_2_1 = Koha::Review->new({ like( $new_review_1_1->reviewid, qr|^\d+$|, 'Adding a new review should have set the reviewid'); is( Koha::Reviews->search->count, $nb_of_reviews + 3, 'The 3 reviews should have been added' ); +is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be new approved reviews' ); +$new_review_1_1->approve; +is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews + 1, 'There should be 1 new approved review' ); +$new_review_1_1->unapprove; +is( Koha::Reviews->search({approved => 1})->count, $nb_of_approved_reviews, 'There should not be any new approved review anymore' ); + my $retrieved_review_1_1 = Koha::Reviews->find( $new_review_1_1->reviewid ); is( $retrieved_review_1_1->review, $new_review_1_1->review, 'Find a review by id should return the correct review' ); -- 2.39.5