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

(-)a/Koha/Patron.pm (-5 / +5 lines)
Lines 1793-1803 sub to_api_mapping { Link Here
1793
    };
1793
    };
1794
}
1794
}
1795
1795
1796
=head3 send_notice
1796
=head3 queue_notice
1797
1797
1798
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_name => 'DUE'});
1798
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_name => 'DUE'});
1799
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1799
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1800
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1800
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1801
1801
1802
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1802
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1803
    table or supply the transport to use.
1803
    table or supply the transport to use.
Lines 1812-1818 sub to_api_mapping { Link Here
1812
1812
1813
=cut
1813
=cut
1814
1814
1815
sub send_notice {
1815
sub queue_notice {
1816
    my ( $self, $params ) = @_;
1816
    my ( $self, $params ) = @_;
1817
    my $letter_params = $params->{letter_params};
1817
    my $letter_params = $params->{letter_params};
1818
    my $test_mode = $params->{test_mode};
1818
    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 1969-1975 subtest 'anonymize' => sub { Link Here
1969
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1969
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1970
};
1970
};
1971
1971
1972
subtest 'send_notice' => sub {
1972
subtest 'queue_notice' => sub {
1973
    plan tests => 11;
1973
    plan tests => 11;
1974
1974
1975
    my $dbh = C4::Context->dbh;
1975
    my $dbh = C4::Context->dbh;
Lines 2016-2041 subtest 'send_notice' => sub { Link Here
2016
    };
2016
    };
2017
    my @mtts = ('email');
2017
    my @mtts = ('email');
2018
2018
2019
    is( $patron->send_notice(), undef, "Nothing is done if no params passed");
2019
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2020
    is( $patron->send_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2020
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2021
    is_deeply(
2021
    is_deeply(
2022
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2022
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2023
        {sent => ['email'] }, "Email sent"
2023
        {sent => ['email'] }, "Email sent"
2024
    );
2024
    );
2025
    $patron->email("")->store;
2025
    $patron->email("")->store;
2026
    is_deeply(
2026
    is_deeply(
2027
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2027
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2028
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2028
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2029
    );
2029
    );
2030
    push @mtts, 'sms';
2030
    push @mtts, 'sms';
2031
    is_deeply(
2031
    is_deeply(
2032
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2032
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2033
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2033
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2034
    );
2034
    );
2035
    $patron->smsalertnumber("")->store;
2035
    $patron->smsalertnumber("")->store;
2036
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2036
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2037
    is_deeply(
2037
    is_deeply(
2038
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2038
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2039
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2039
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2040
    );
2040
    );
2041
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2041
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
Lines 2045-2060 subtest 'send_notice' => sub { Link Here
2045
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2045
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2046
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2046
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2047
2047
2048
    is( $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2048
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2049
2049
2050
    $patron->email(q|awesome@ismymiddle.name|)->store;
2050
    $patron->email(q|awesome@ismymiddle.name|)->store;
2051
    is_deeply(
2051
    is_deeply(
2052
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2052
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2053
        {sent => ['email'] }, "Email sent when using borrower preferences"
2053
        {sent => ['email'] }, "Email sent when using borrower preferences"
2054
    );
2054
    );
2055
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2055
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2056
    is_deeply(
2056
    is_deeply(
2057
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2057
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2058
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2058
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2059
    );
2059
    );
2060
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2060
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2061
- 

Return to bug 15986