Bug 15839: Koha::Reviews - Remove approvereview & unapprovereview
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 16 Feb 2016 16:06:27 +0000 (16:06 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 9 Sep 2016 10:29:57 +0000 (10:29 +0000)
This patch adds 2 new methods to Koha::Review: approve and unapprove.

Signed-off-by: Marc Veron <veron@veron.ch>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Review.pm
Koha/Review.pm
reviews/reviewswaiting.pl
t/db_dependent/Koha/Reviews.t

index 9b27c44..a5aa07d 100644 (file)
@@ -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);
index 082f71f..72e3e2f 100644 (file)
@@ -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
index b534391..b1b8234 100755 (executable)
@@ -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);
index 321a536..da164f7 100644 (file)
@@ -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' );