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

(-)a/Koha/Patron.pm (-5 / +5 lines)
Lines 1713-1723 sub to_api_mapping { Link Here
1713
    };
1713
    };
1714
}
1714
}
1715
1715
1716
=head3 send_notice
1716
=head3 queue_notice
1717
1717
1718
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_name => 'DUE'});
1718
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_name => 'DUE'});
1719
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1719
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1720
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1720
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1721
1721
1722
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1722
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1723
    table or supply the transport to use.
1723
    table or supply the transport to use.
Lines 1732-1738 sub to_api_mapping { Link Here
1732
1732
1733
=cut
1733
=cut
1734
1734
1735
sub send_notice {
1735
sub queue_notice {
1736
    my ( $self, $params ) = @_;
1736
    my ( $self, $params ) = @_;
1737
    my $letter_params = $params->{letter_params};
1737
    my $letter_params = $params->{letter_params};
1738
    my $test_mode = $params->{test_mode};
1738
    my $test_mode = $params->{test_mode};
(-)a/misc/cronjobs/holds_reminder.pl (-2 / +2 lines)
Lines 282-289 foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP Link Here
282
        $sending_params->{letter_params} = $letter_params;
282
        $sending_params->{letter_params} = $letter_params;
283
        $sending_params->{test_mode} = $nomail;
283
        $sending_params->{test_mode} = $nomail;
284
        my $result_text = $nomail ? "would have been sent" : "was sent";
284
        my $result_text = $nomail ? "would have been sent" : "was sent";
285
        # send_notice queues the notices, falling back to print for email or SMS, and ignores phone (they are handled by Itiva)
285
        # queue_notice queues the notices, falling back to print for email or SMS, and ignores phone (they are handled by Itiva)
286
        my $result = $patron->send_notice( $sending_params );
286
        my $result = $patron->queue_notice( $sending_params );
287
        $verbose and print "   borrower " . $patron->surname . ", " . $patron->firstname . " $result_text notices via: @{$result->{sent}}\n" if defined $result->{sent};
287
        $verbose and print "   borrower " . $patron->surname . ", " . $patron->firstname . " $result_text notices via: @{$result->{sent}}\n" if defined $result->{sent};
288
        $verbose and print "   borrower " . $patron->surname . ", " . $patron->firstname . " $result_text print fallback for: @{$result->{fallback}}\n" if defined $result->{fallback};
288
        $verbose and print "   borrower " . $patron->surname . ", " . $patron->firstname . " $result_text print fallback for: @{$result->{fallback}}\n" if defined $result->{fallback};
289
        # Mark this borrower as completed
289
        # Mark this borrower as completed
(-)a/t/db_dependent/Koha/Patrons.t (-12 / +11 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 41;
22
use Test::More tests => 42;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 2032-2038 subtest 'anonymize' => sub { Link Here
2032
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
2032
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
2033
};
2033
};
2034
2034
2035
subtest 'send_notice' => sub {
2035
subtest 'queue_notice' => sub {
2036
    plan tests => 11;
2036
    plan tests => 11;
2037
2037
2038
    my $dbh = C4::Context->dbh;
2038
    my $dbh = C4::Context->dbh;
Lines 2079-2104 subtest 'send_notice' => sub { Link Here
2079
    };
2079
    };
2080
    my @mtts = ('email');
2080
    my @mtts = ('email');
2081
2081
2082
    is( $patron->send_notice(), undef, "Nothing is done if no params passed");
2082
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2083
    is( $patron->send_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2083
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2084
    is_deeply(
2084
    is_deeply(
2085
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2085
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2086
        {sent => ['email'] }, "Email sent"
2086
        {sent => ['email'] }, "Email sent"
2087
    );
2087
    );
2088
    $patron->email("")->store;
2088
    $patron->email("")->store;
2089
    is_deeply(
2089
    is_deeply(
2090
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2090
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2091
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2091
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2092
    );
2092
    );
2093
    push @mtts, 'sms';
2093
    push @mtts, 'sms';
2094
    is_deeply(
2094
    is_deeply(
2095
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2095
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2096
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2096
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2097
    );
2097
    );
2098
    $patron->smsalertnumber("")->store;
2098
    $patron->smsalertnumber("")->store;
2099
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2099
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2100
    is_deeply(
2100
    is_deeply(
2101
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2101
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2102
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2102
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2103
    );
2103
    );
2104
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2104
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
Lines 2108-2123 subtest 'send_notice' => sub { Link Here
2108
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2108
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2109
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2109
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2110
2110
2111
    is( $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2111
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2112
2112
2113
    $patron->email(q|awesome@ismymiddle.name|)->store;
2113
    $patron->email(q|awesome@ismymiddle.name|)->store;
2114
    is_deeply(
2114
    is_deeply(
2115
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2115
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2116
        {sent => ['email'] }, "Email sent when using borrower preferences"
2116
        {sent => ['email'] }, "Email sent when using borrower preferences"
2117
    );
2117
    );
2118
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2118
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2119
    is_deeply(
2119
    is_deeply(
2120
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2120
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2121
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2121
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2122
    );
2122
    );
2123
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2123
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2124
- 

Return to bug 15986