View | Details | Raw Unified | Return to bug 1985
Collapse All | Expand All

(-)a/C4/Letters.pm (-1 / +5 lines)
Lines 625-633 sub GetPreparedLetter { Link Here
625
       }
625
       }
626
    }
626
    }
627
627
628
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
628
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // '';
629
    $letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go;
629
    $letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go;
630
630
631
    my $staffClientBaseURL = C4::Context->preference('staffClientBaseURL') // '';
632
    $letter->{content} =~ s/<<staffClientBaseURL>>/$staffClientBaseURL/go;
633
631
    if ($want_librarian) {
634
    if ($want_librarian) {
632
        # parsing librarian name
635
        # parsing librarian name
633
        my $userenv = C4::Context->userenv;
636
        my $userenv = C4::Context->userenv;
Lines 740-745 sub _parseletter_sth { Link Here
740
    ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                                  :
743
    ($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE             id = ?"                                  :
741
    ($table eq 'aqorders'     ) ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
744
    ($table eq 'aqorders'     ) ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
742
    ($table eq 'opac_news'    ) ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
745
    ($table eq 'opac_news'    ) ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
746
    ($table eq 'reviews'      ) ? "SELECT * FROM $table WHERE       reviewid = ?"                                  :
743
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
747
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
744
    undef ;
748
    undef ;
745
    unless ($query) {
749
    unless ($query) {
(-)a/C4/Review.pm (-20 / +47 lines)
Lines 4-26 package C4::Review; Link Here
4
#
4
#
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
7
# Koha is free software; you can redistribute it and/or modify it
8
# terms of the GNU General Public License as published by the Free Software
8
# under the terms of the GNU General Public License as published by
9
# Foundation; either version 2 of the License, or (at your option) any later
9
# the Free Software Foundation; either version 3 of the License, or
10
# version.
10
# (at your option) any later version.
11
#
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# Koha is distributed in the hope that it will be useful, but
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
15
#
16
#
16
# You should have received a copy of the GNU General Public License along
17
# You should have received a copy of the GNU General Public License
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use C4::Context;
22
use C4::Context;
23
require C4::Letters;
24
24
25
use vars qw($VERSION @ISA @EXPORT);
25
use vars qw($VERSION @ISA @EXPORT);
26
26
Lines 29-36 BEGIN { Link Here
29
    $VERSION = 3.07.00.049;
29
    $VERSION = 3.07.00.049;
30
	require Exporter;
30
	require Exporter;
31
	@ISA    = qw(Exporter);
31
	@ISA    = qw(Exporter);
32
	@EXPORT = qw(getreview savereview updatereview numberofreviews numberofreviewsbybiblionumber
32
    @EXPORT = qw(getreview savereview updatereview numberofreviews
33
		getreviews getallreviews approvereview unapprovereview deletereview);
33
                 numberofreviewsbybiblionumber getreviews
34
                 getallreviews approvereview unapprovereview
35
                 deletereview SendReviewAlert);
34
}
36
}
35
37
36
=head1 NAME
38
=head1 NAME
Lines 79-89 sub savereview { Link Here
79
    my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
81
    my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
80
	review,approved,datereviewed) VALUES 
82
	review,approved,datereviewed) VALUES 
81
  (?,?,?,0,now())";
83
  (?,?,?,0,now())";
84
    my $GetReviewID = q{
85
SELECT reviewid FROM reviews WHERE borrowernumber=? AND biblionumber=?;
86
                      };
82
    my $sth = $dbh->prepare($query);
87
    my $sth = $dbh->prepare($query);
83
    $sth->execute( $borrowernumber, $biblionumber, $review);
88
    $sth->execute( $borrowernumber, $biblionumber, $review);
89
    $sth = $dbh->prepare($GetReviewID);
90
    $sth->execute( $borrowernumber, $biblionumber );
91
    my $reviewid = $sth->fetchrow();
84
92
85
    unless ($sth->err()) {
93
    unless ($sth->err()) {
86
        SendReviewAlert( $review, $borrowernumber );
94
        SendReviewAlert( {
95
                           'reviewid'       => $reviewid,
96
                           'borrowernumber' => $borrowernumber,
97
                           'biblionumber'   => $biblionumber } );
87
    }
98
    }
88
}
99
}
89
100
Lines 91-101 sub updatereview { Link Here
91
    my ( $biblionumber, $borrowernumber, $review ) = @_;
102
    my ( $biblionumber, $borrowernumber, $review ) = @_;
92
    my $dbh   = C4::Context->dbh;
103
    my $dbh   = C4::Context->dbh;
93
    my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
104
    my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
105
    my $GetReviewID = q{
106
SELECT reviewid FROM reviews WHERE borrowernumber=? AND biblionumber=?;
107
                      };
94
    my $sth = $dbh->prepare($query);
108
    my $sth = $dbh->prepare($query);
95
    $sth->execute( $review, $borrowernumber, $biblionumber );
109
    $sth->execute( $review, $borrowernumber, $biblionumber );
110
    $sth = $dbh->prepare($GetReviewID);
111
    $sth->execute( $borrowernumber, $biblionumber );
112
    my $reviewid = $sth->fetchrow();
96
113
97
    unless ($sth->err()) {
114
    unless ($sth->err()) {
98
        SendReviewAlert( $review, $borrowernumber );
115
        SendReviewAlert( {
116
                           'reviewid'       => $reviewid,
117
                           'borrowernumber' => $borrowernumber,
118
                           'biblionumber'   => $biblionumber } );
99
    }
119
    }
100
}
120
}
101
121
Lines 196-218 sub deletereview { Link Here
196
216
197
=head2 SendReviewAlert
217
=head2 SendReviewAlert
198
218
199
  SendReviewAlert( $review, $borrowernumber );
219
  SendReviewAlert( { 'reviewid'       => $reviewid,
220
                     'borrowernumber' => $borrowernumber,
221
                     'biblionumber'   => $biblionumber } );
200
222
201
=cut
223
=cut
202
224
203
sub SendReviewAlert {
225
sub SendReviewAlert {
204
    my $review = shift;
226
    my $params = shift;
205
    my $borrowernumber = shift;
206
227
207
    my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail');
228
    my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail');
208
209
    return unless $moderatorEmail;
229
    return unless $moderatorEmail;
210
230
231
    my $reviewid       = $params->{'reviewid'};
232
    my $borrowernumber = $params->{'borrowernumber'};
233
    my $biblionumber   = $params->{'biblionumber'};
234
211
    my $letter =  C4::Letters::GetPreparedLetter (
235
    my $letter =  C4::Letters::GetPreparedLetter (
212
        module => 'members',
236
        module => 'members',
213
        letter_code => 'COMMENT_CREATED',
237
        letter_code => 'COMMENT_CREATED',
214
        tables => {
238
        tables => {
239
            'reviews'     => $reviewid,
215
            'borrowers'   => $borrowernumber,
240
            'borrowers'   => $borrowernumber,
241
            'biblio'      => $biblionumber,
242
            'biblioitems' => $biblionumber,
216
        }
243
        }
217
    ) or return;
244
    ) or return;
218
245
(-)a/installer/data/mysql/en/mandatory/sample_notices.sql (-2 / +16 lines)
Lines 119-127 If you did not initiate this request, you may safely ignore this one-time messag Link Here
119
);
119
);
120
120
121
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
121
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
122
VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation', 'Dear moderator,
122
VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation',
123
'Dear moderator,
123
124
124
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment.
125
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>.
126
127
--- BEGIN COMMENT ---
128
<<reviews.review>>
129
--- END COMMENT ---
130
131
To approve:
132
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>>
133
134
To delete:
135
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>>
136
137
Or to review all comments:
138
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl
125
139
126
Check it out!
140
Check it out!
127
141
(-)a/installer/data/mysql/updatedatabase.pl (-24 / +38 lines)
Lines 8314-8343 if ( CheckVersion($DBversion) ) { Link Here
8314
    SetVersion($DBversion);
8314
    SetVersion($DBversion);
8315
}
8315
}
8316
8316
8317
$DBversion = "3.17.00.XXX";
8318
if ( CheckVersion($DBversion) ) {
8319
    $dbh->do(q|
8320
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
8321
VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation', 'Dear moderator,
8322
8323
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment.
8324
8325
Check it out!
8326
8327
Your library.',
8328
'email'
8329
);
8330
    |);
8331
    $dbh->do(q|
8332
        INSERT INTO systempreferences
8333
            (variable,value,explanation,options,type)
8334
        VALUES
8335
        ('CommentModeratorsEmail','','','The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.','Textarea')
8336
    |);
8337
    print "Upgrade to $DBversion done (Bug 1985 - Email notification of new OPAC comments)\n";
8338
    SetVersion($DBversion);
8339
}
8340
8341
$DBversion = "3.15.00.041";
8317
$DBversion = "3.15.00.041";
8342
if ( CheckVersion($DBversion) ) {
8318
if ( CheckVersion($DBversion) ) {
8343
    my $name = $dbh->selectcol_arrayref(q|
8319
    my $name = $dbh->selectcol_arrayref(q|
Lines 9828-9833 if ( CheckVersion($DBversion) ) { Link Here
9828
    SetVersion($DBversion);
9804
    SetVersion($DBversion);
9829
}
9805
}
9830
9806
9807
$DBversion = "3.19.00.XXX";
9808
if ( CheckVersion($DBversion) ) {
9809
    $dbh->do(q|
9810
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
9811
VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation',
9812
'Dear moderator,
9813
9814
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>.
9815
9816
--- BEGIN COMMENT ---
9817
<<reviews.review>>
9818
--- END COMMENT ---
9819
9820
To approve:
9821
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>>
9822
9823
To delete:
9824
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>>
9825
9826
Or to review all comments:
9827
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl
9828
9829
Check it out!
9830
9831
Your library.',
9832
'email'
9833
);
9834
    |);
9835
    $dbh->do(q|
9836
        INSERT INTO systempreferences
9837
            (variable,value,explanation,options,type)
9838
        VALUES
9839
        ('CommentModeratorsEmail','','','The email address where to send a notification (template code COMMENT_CREATED) when a Borrower adds/modifies a review/comment for a Biblio. Set to empty to disable sending email notifications.','Textarea')
9840
    |);
9841
    print "Upgrade to $DBversion done (Bug 1985 - Email notification of new OPAC comments)\n";
9842
    SetVersion($DBversion);
9843
}
9844
9831
=head1 FUNCTIONS
9845
=head1 FUNCTIONS
9832
9846
9833
=head2 TableExists($table)
9847
=head2 TableExists($table)
(-)a/t/db_dependent/Review.t (-1 / +97 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::More tests => 14;
5
6
use_ok('C4::Review');
7
8
my $dbh = C4::Context->dbh;
9
$dbh->{RaiseError} = 1;
10
$dbh->{AutoCommit} = 0;
11
12
my $sth = $dbh->prepare("SELECT * FROM borrowers;");
13
$sth->execute();
14
my $row = $sth->fetchrow_hashref();
15
my $borrowernumber;
16
$borrowernumber = $row->{'borrowernumber'} if $row;
17
$sth = $dbh->prepare("SELECT * FROM biblio;");
18
$sth->execute();
19
$row = $sth->fetchrow_hashref();
20
my $biblionumber;
21
$biblionumber = $row->{'biblionumber'} if $row;
22
23
SKIP: {
24
    skip "Missing borrowers or biblios",13
25
      unless $biblionumber and $borrowernumber;
26
27
    # Make sure there are no reviews
28
    $sth = $dbh->prepare("DELETE FROM reviews;");
29
    $sth->execute();
30
31
    # Clear out the message_queue to make counting easier.
32
    $sth = $dbh->prepare("DELETE FROM message_queue;");
33
    $sth->execute();
34
35
    # Add a review
36
    savereview($biblionumber,$borrowernumber,'A sample review.');
37
38
    # Retrieve review
39
    my $reviews = getallreviews(0);
40
    my $reviewid = $reviews->[0]->{'reviewid'};
41
    my $ReviewText = $reviews->[0]->{'review'};
42
    ok($ReviewText eq 'A sample review.','Saved and retrieved a sample review.');
43
44
    # Update the review
45
    updatereview($biblionumber,$borrowernumber,'A revised review.');
46
47
    # Retrieve it differently.
48
    my $review = getreview($biblionumber,$borrowernumber);
49
    $ReviewText = $review->{'review'};
50
    ok($ReviewText eq 'A revised review.','Updated and retrieved a revised review.');
51
52
    # Confirm 1 unapproved comment.
53
    my $UnapprovedReviewsCount = numberofreviews(0);
54
    ok($UnapprovedReviewsCount==1,'There is one unapproved comment.');
55
56
    # Approve the comment.
57
    approvereview($reviewid);
58
    $UnapprovedReviewsCount = numberofreviews(0);
59
    ok($UnapprovedReviewsCount==0,'There are no unapproved comments.');
60
    my $ApprovedReviewsCount = numberofreviews(1);
61
    ok($ApprovedReviewsCount==1,'There is one approved comment.');
62
63
    # Check how many reviews for this biblionumber.
64
    my $ReviewsCount = numberofreviewsbybiblionumber($biblionumber);
65
    ok($ReviewsCount==1,'There is one approved comment for this biblio.');
66
67
    # Unapprove the comment.
68
    unapprovereview($reviewid);
69
    $UnapprovedReviewsCount = numberofreviews(0);
70
    ok($UnapprovedReviewsCount==1,'There is one unapproved comment.');
71
    $ApprovedReviewsCount = numberofreviews(1);
72
    ok($ApprovedReviewsCount==0,'There are no approved comments.');
73
74
    # Delete the review.
75
    deletereview($reviewid);
76
    $UnapprovedReviewsCount = numberofreviews(0);
77
    ok($UnapprovedReviewsCount==0,'There are no unapproved comments.');
78
    $ApprovedReviewsCount = numberofreviews(1);
79
    ok($ApprovedReviewsCount==0,'There are no approved comments.');
80
81
    my $ApprovedReviews   = getreviews($biblionumber,1);
82
    my $UnapprovedReviews = getreviews($biblionumber,0);
83
    ok(scalar @$ApprovedReviews==0,'No approved comment records.');
84
    ok(scalar @$UnapprovedReviews==0,'No unapproved comment records.');
85
86
    # Only save, update, and SendReviewAlert should trigger letters.
87
    SendReviewAlert( { 'review' => 'A sample review unused.',
88
                       'biblionumber' => $biblionumber,
89
                       'borrowernumber' => $borrowernumber });
90
91
    $sth = $dbh->prepare("SELECT COUNT(*) FROM message_queue;");
92
    $sth->execute();
93
    my $LetterCount = $sth->fetchrow();
94
    ok($LetterCount==3,'There are three triggered reminders as expected.');
95
}
96
97
$dbh->rollback();

Return to bug 1985