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

(-)a/C4/Letters.pm (-1 / +4 lines)
Lines 727-734 sub GetPreparedLetter { Link Here
727
       }
727
       }
728
    }
728
    }
729
729
730
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
730
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // q{};
731
    $letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go;
731
    $letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go;
732
    my $staff_client_base_url = C4::Context->preference('staffClientBaseURL') // q{};
733
    $letter->{content} =~ s/<<staffClientBaseURL>>/$staff_client_base_url/go;
732
734
733
    if ($want_librarian) {
735
    if ($want_librarian) {
734
        # parsing librarian name
736
        # parsing librarian name
Lines 850-855 sub _parseletter_sth { Link Here
850
    ($table eq 'aqbooksellers')    ? "SELECT * FROM $table WHERE             id = ?"                                  :
852
    ($table eq 'aqbooksellers')    ? "SELECT * FROM $table WHERE             id = ?"                                  :
851
    ($table eq 'aqorders'     )    ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
853
    ($table eq 'aqorders'     )    ? "SELECT * FROM $table WHERE    ordernumber = ?"                                  :
852
    ($table eq 'opac_news'    )    ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
854
    ($table eq 'opac_news'    )    ? "SELECT * FROM $table WHERE          idnew = ?"                                  :
855
    ($table eq 'reviews'      )    ? "SELECT * FROM $table WHERE    reviewid = ?"                                  :
853
    ($table eq 'article_requests') ? "SELECT * FROM $table WHERE             id = ?"                                  :
856
    ($table eq 'article_requests') ? "SELECT * FROM $table WHERE             id = ?"                                  :
854
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
857
    ($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
855
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
858
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
(-)a/Koha/Review.pm (-1 / +50 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
# Koha::Database is used in the nested mess of C4::Letters;
23
# As is C4::Context.
24
use C4::Letters;
23
25
24
use base qw(Koha::Object);
26
use base qw(Koha::Object);
25
27
Lines 67-70 sub _type { Link Here
67
    return 'Review';
69
    return 'Review';
68
}
70
}
69
71
72
=head3 SendReviewAlert
73
74
    $review->SendReviewAlert($parameters);
75
76
Queue an outgoing email alert when a borrower posts a review,
77
using the passed parameters in a hash reference.
78
79
=cut
80
81
sub SendReviewAlert {
82
    my ( $self, $params ) = @_;
83
84
    my $borrowernumber = $params->{borrowernumber};
85
    my $reviewid = $params->{reviewid};
86
    my $biblionumber = $params->{biblionumber};
87
88
    my $moderatorEmail = C4::Context->preference('CommentModeratorsEmail');
89
    unless ($moderatorEmail) {
90
        carp 'CommentModeratorsEmail is not set!';
91
        return;
92
    }
93
94
    my $letter =  C4::Letters::GetPreparedLetter (
95
        module => 'members',
96
        letter_code => 'COMMENT_CREATED',
97
        tables => {
98
            'reviews'     => $reviewid,
99
            'borrowers'   => $borrowernumber,
100
            'biblio'      => $biblionumber,
101
            'biblioitems' => $biblionumber,
102
        }
103
    );
104
    unless ($letter) {
105
        carp 'COMMENT_CREATED member letter not found!';
106
        return;
107
    }
108
109
    C4::Letters::EnqueueLetter({
110
        letter                 => $letter,
111
        borrowernumber         => $borrowernumber,
112
        message_transport_type => 'email',
113
        to_address             => $moderatorEmail,
114
    });
115
116
    return 1;
117
}
118
70
1;
119
1;
(-)a/installer/data/mysql/atomicupdate/bug_1985.sql (+38 lines)
Line 0 Link Here
1
INSERT IGNORE INTO letter
2
    (module,    code,              branchcode, name,                           is_html,
3
     title,
4
     content, message_transport_type)
5
VALUES
6
    ('members', 'COMMENT_CREATED', '',         'Comment created notification', '0',
7
     'Comment from <<borrowers.cardnumber>> is waiting for moderation',
8
'Dear moderator,
9
10
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>.
11
12
--- BEGIN COMMENT ---
13
<<reviews.review>>
14
--- END COMMENT ---
15
16
To approve:
17
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>>
18
19
To delete:
20
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>>
21
22
Or to review all comments:
23
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl
24
25
Check it out!
26
27
Your library.',
28
'email'
29
    );
30
31
INSERT IGNORE INTO systempreferences
32
    (variable,                value,options,
33
     explanation,
34
     type)
35
VALUES
36
    ('CommentModeratorsEmail','',   '',
37
     '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.',
38
     'Textarea');
(-)a/installer/data/mysql/en/mandatory/sample_notices.sql (+25 lines)
Lines 129-134 Your library account has been created. Please verify your email address by click Link Here
129
If you did not initiate this request, you may safely ignore this one-time message. The request will expire shortly.'
129
If you did not initiate this request, you may safely ignore this one-time message. The request will expire shortly.'
130
);
130
);
131
131
132
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content, message_transport_type)
133
VALUES ( 'members', 'COMMENT_CREATED', '', 'Comment created notification', '0', 'Comment from <<borrowers.cardnumber>> is waiting for moderation',
134
'Dear moderator,
135
136
We want to inform you that borrower <<borrowers.cardnumber>> has just created a new comment on <<biblio.title>>, which is biblionumber <<biblio.biblionumber>>.
137
138
--- BEGIN COMMENT ---
139
<<reviews.review>>
140
--- END COMMENT ---
141
142
To approve:
143
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=approve&reviewid=<<reviews.reviewid>>
144
145
To delete:
146
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl?op=delete&reviewid=<<reviews.reviewid>>
147
148
Or to review all comments:
149
http://<<staffClientBaseURL>>/cgi-bin/koha/reviews/reviewswaiting.pl
150
151
Check it out!
152
153
Your library.',
154
'email'
155
);
156
132
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content)
157
INSERT INTO  letter (module, code, branchcode, name, is_html, title, content)
133
VALUES ('members', 'SHARE_INVITE', '', 'Invitation for sharing a list', '0', 'Share list <<listname>>', 'Dear patron,
158
VALUES ('members', 'SHARE_INVITE', '', 'Invitation for sharing a list', '0', 'Share list <<listname>>', 'Dear patron,
134
159
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 113-118 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
113
('CoceHost', '', NULL, 'Coce server URL', 'Free'),
113
('CoceHost', '', NULL, 'Coce server URL', 'Free'),
114
('CoceProviders', '', 'aws,gb,ol', 'Coce providers', 'multiple'),
114
('CoceProviders', '', 'aws,gb,ol', 'Coce providers', 'multiple'),
115
('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page.  NOTE: this can slow down search response time significantly','YesNo'),
115
('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page.  NOTE: this can slow down search response time significantly','YesNo'),
116
('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'),
116
('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'),
117
('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'),
117
('ConsiderOnSiteCheckoutsAsNormalCheckouts','1',NULL,'Consider on-site checkouts as normal checkouts','YesNo'),
118
('ConsiderOnSiteCheckoutsAsNormalCheckouts','1',NULL,'Consider on-site checkouts as normal checkouts','YesNo'),
118
('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'),
119
('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+4 lines)
Lines 451-456 OPAC: Link Here
451
                  no: Hide
451
                  no: Hide
452
            - reviewer's avatar beside comments in OPAC. The avatar will be searched on www.libravatar.org using the patron's e-mail address.
452
            - reviewer's avatar beside comments in OPAC. The avatar will be searched on www.libravatar.org using the patron's e-mail address.
453
        -
453
        -
454
            - 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.
455
            - pref: CommentModeratorsEmail
456
              class: textarea
457
        -
454
            - pref: RequestOnOpac
458
            - pref: RequestOnOpac
455
              choices:
459
              choices:
456
                  yes: Allow
460
                  yes: Allow
(-)a/opac/opac-review.pl (-8 / +23 lines)
Lines 33-40 use Koha::Reviews; Link Here
33
33
34
my $query        = new CGI;
34
my $query        = new CGI;
35
my $biblionumber = $query->param('biblionumber');
35
my $biblionumber = $query->param('biblionumber');
36
my $review       = $query->param('review');
36
my $review       = $query->param('review');   # if defined submit
37
my $reviewid     = $query->param('reviewid');
37
my $reviewid     = $query->param('reviewid'); # if defined edit
38
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39
    {
39
    {
40
        template_name   => "opac-review.tt",
40
        template_name   => "opac-review.tt",
Lines 46-52 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
46
46
47
# FIXME: need to allow user to delete their own comment(s)
47
# FIXME: need to allow user to delete their own comment(s)
48
48
49
my ( $clean, @errors, $savedreview );
49
my ( $clean, @errors, $savedreview, $affectedreview );
50
51
my $submitting = ( defined $review && $review ne q{} ) ? 1 : 0;
52
my $editing    = ( defined $reviewid ) ? 1 : 0;
53
50
my $biblio = Koha::Biblios->find( $biblionumber );
54
my $biblio = Koha::Biblios->find( $biblionumber );
51
55
52
if( !$biblio ) {
56
if( !$biblio ) {
Lines 60-66 if( !$biblio ) { Link Here
60
    $review = $savedreview? $savedreview->review: $review;
64
    $review = $savedreview? $savedreview->review: $review;
61
}
65
}
62
66
63
if( !@errors && defined $review ) {
67
if( !@errors && $submitting ) {
64
    if ($review !~ /\S/) {
68
    if ($review !~ /\S/) {
65
        push @errors, {empty=>1};
69
        push @errors, {empty=>1};
66
    } else {
70
    } else {
Lines 74-96 if( !@errors && defined $review ) { Link Here
74
            my $js_ok_review = $clean;
78
            my $js_ok_review = $clean;
75
            $js_ok_review =~ s/"/&quot;/g;    # probably redundant w/ TMPL ESCAPE=JS
79
            $js_ok_review =~ s/"/&quot;/g;    # probably redundant w/ TMPL ESCAPE=JS
76
            $template->param(clean_review=>$js_ok_review);
80
            $template->param(clean_review=>$js_ok_review);
77
            if ($savedreview) {
81
            if ($editing) {
78
                $savedreview->set(
82
                my $updatedreview = $savedreview->set(
79
                    {
83
                    {
80
                        review        => $clean,
84
                        review        => $clean,
81
                        approved      => 0,
85
                        approved      => 0,
82
                        datereviewed  => dt_from_string
86
                        datereviewed  => dt_from_string
83
                    }
87
                    }
84
                )->store;
88
                )->store;
89
                $affectedreview = $updatedreview;
85
            } else {
90
            } else {
86
                $reviewid = Koha::Review->new(
91
                my $newreview = Koha::Review->new(
87
                    {   biblionumber   => $biblionumber,
92
                    {   biblionumber   => $biblionumber,
88
                        borrowernumber => $borrowernumber,
93
                        borrowernumber => $borrowernumber,
89
                        review         => $clean,
94
                        review         => $clean,
90
                        datereviewed   => dt_from_string
95
                        datereviewed   => dt_from_string
91
                    }
96
                    }
92
                )->store->reviewid;
97
                )->store;
98
                $reviewid = $newreview ? $newreview->reviewid : 0;
99
                $affectedreview = $newreview;
93
            }
100
            }
101
            if ($reviewid) {
102
                $affectedreview->SendReviewAlert({
103
                    'borrowernumber' => $borrowernumber,
104
                    'reviewid'       => $reviewid,
105
                    'biblionumber'   => $biblionumber
106
                });
107
            }
108
94
            unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
109
            unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
95
        }
110
        }
96
    }
111
    }
(-)a/t/db_dependent/Koha/Reviews.t (-2 / +43 lines)
Lines 19-31 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 14;
23
use Test::Warn;
23
24
24
use Koha::Patrons;
25
use Koha::Patrons;
25
use Koha::Reviews;
26
use Koha::Reviews;
27
use Koha::Notice::Messages;
28
use Koha::Notice::Templates;
26
use Koha::Database;
29
use Koha::Database;
27
30
28
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
32
use t::lib::Mocks;
29
33
30
my $schema = Koha::Database->new->schema;
34
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
35
$schema->storage->txn_begin;
Lines 37-42 $patron_1 = Koha::Patrons->find( $patron_1->{borrowernumber} ); Link Here
37
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
41
$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} );
38
my $biblio_1 = $builder->build({ source => 'Biblio' });
42
my $biblio_1 = $builder->build({ source => 'Biblio' });
39
my $biblio_2 = $builder->build({ source => 'Biblio' });
43
my $biblio_2 = $builder->build({ source => 'Biblio' });
44
my $nb_of_messages = Koha::Notice::Messages->search->count;
40
my $nb_of_reviews = Koha::Reviews->search->count;
45
my $nb_of_reviews = Koha::Reviews->search->count;
41
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
46
my $nb_of_approved_reviews = Koha::Reviews->search({ approved => 1 })->count;
42
my $new_review_1_1 = Koha::Review->new({
47
my $new_review_1_1 = Koha::Review->new({
Lines 82-87 subtest 'search_limited' => sub { Link Here
82
$retrieved_review_1_1->delete;
87
$retrieved_review_1_1->delete;
83
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' );
88
is( Koha::Reviews->search->count, $nb_of_reviews + 2, 'Delete should have deleted the review' );
84
89
90
# Test SendReview Alert
91
92
# empty CommentModeratorsEmail
93
t::lib::Mocks::mock_preference('CommentModeratorsEmail',undef);
94
warning_like {
95
$new_review_1_2->SendReviewAlert({
96
    borrowernumber => $patron_1->{borrowernumber},
97
    biblionumber   => $biblio_2->{biblionumber},
98
    reviewid       => $new_review_1_2->reviewid
99
}) } qr/CommentModeratorsEmail is not set!/, 'SendReviewAlert triggered expected CommentModeratorsEmail warning.';
100
is( Koha::Notice::Messages->search->count, $nb_of_messages, 'SendReviewAlert lacking CommentModeratorsEmail triggered nothing.' );
101
102
# set CommentModeratorsEmail
103
t::lib::Mocks::mock_preference('CommentModeratorsEmail','test@test.test');
104
warning_is {
105
$new_review_1_2->SendReviewAlert({
106
    borrowernumber => $patron_1->{borrowernumber},
107
    biblionumber   => $biblio_2->{biblionumber},
108
    reviewid       => $new_review_1_2->reviewid
109
}) } '', 'SendReviewAlert triggered no warnings as expected.';
110
is( Koha::Notice::Messages->search->count, $nb_of_messages+1, 'SendReviewAlert triggered notice.' );
111
112
# letter missing
113
Koha::Notice::Templates->search({
114
    module => 'members',
115
    code => 'COMMENT_CREATED'
116
})->delete;
117
warnings_like {
118
$new_review_1_2->SendReviewAlert({
119
    borrowernumber => $patron_1->{borrowernumber},
120
    biblionumber   => $biblio_2->{biblionumber},
121
    reviewid       => $new_review_1_2->reviewid
122
}) }
123
[ qr/No members COMMENT_CREATED letter transported by email/,
124
  qr/COMMENT_CREATED member letter not found!/ ] , 'SendReviewAlert triggered expected COMMENT_CREATED warnings.';
125
is( Koha::Notice::Messages->search->count, $nb_of_messages+1, 'SendReviewAlert lacking letter triggered nothing new.' );
126
85
$schema->storage->txn_rollback;
127
$schema->storage->txn_rollback;
86
128
87
sub set_logged_in_user {
129
sub set_logged_in_user {
88
- 

Return to bug 1985