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

(-)a/Koha/Patron.pm (-5 / +5 lines)
Lines 1773-1783 sub to_api_mapping { Link Here
1773
    };
1773
    };
1774
}
1774
}
1775
1775
1776
=head3 send_notice
1776
=head3 queue_notice
1777
1777
1778
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_name => 'DUE'});
1778
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_name => 'DUE'});
1779
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1779
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
1780
    Koha::Patrons->send_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1780
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
1781
1781
1782
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1782
    Queue messages to a patron. Can pass a message that is part of the message_attributes
1783
    table or supply the transport to use.
1783
    table or supply the transport to use.
Lines 1792-1798 sub to_api_mapping { Link Here
1792
1792
1793
=cut
1793
=cut
1794
1794
1795
sub send_notice {
1795
sub queue_notice {
1796
    my ( $self, $params ) = @_;
1796
    my ( $self, $params ) = @_;
1797
    my $letter_params = $params->{letter_params};
1797
    my $letter_params = $params->{letter_params};
1798
    my $test_mode = $params->{test_mode};
1798
    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 1947-1953 subtest 'anonymize' => sub { Link Here
1947
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1947
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
1948
};
1948
};
1949
1949
1950
subtest 'send_notice' => sub {
1950
subtest 'queue_notice' => sub {
1951
    plan tests => 11;
1951
    plan tests => 11;
1952
1952
1953
    my $dbh = C4::Context->dbh;
1953
    my $dbh = C4::Context->dbh;
Lines 1994-2019 subtest 'send_notice' => sub { Link Here
1994
    };
1994
    };
1995
    my @mtts = ('email');
1995
    my @mtts = ('email');
1996
1996
1997
    is( $patron->send_notice(), undef, "Nothing is done if no params passed");
1997
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
1998
    is( $patron->send_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
1998
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
1999
    is_deeply(
1999
    is_deeply(
2000
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2000
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2001
        {sent => ['email'] }, "Email sent"
2001
        {sent => ['email'] }, "Email sent"
2002
    );
2002
    );
2003
    $patron->email("")->store;
2003
    $patron->email("")->store;
2004
    is_deeply(
2004
    is_deeply(
2005
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2005
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2006
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2006
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2007
    );
2007
    );
2008
    push @mtts, 'sms';
2008
    push @mtts, 'sms';
2009
    is_deeply(
2009
    is_deeply(
2010
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2010
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2011
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2011
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2012
    );
2012
    );
2013
    $patron->smsalertnumber("")->store;
2013
    $patron->smsalertnumber("")->store;
2014
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2014
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2015
    is_deeply(
2015
    is_deeply(
2016
        $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2016
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2017
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2017
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2018
    );
2018
    );
2019
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2019
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
Lines 2023-2038 subtest 'send_notice' => sub { Link Here
2023
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2023
    my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
2024
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2024
    $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
2025
2025
2026
    is( $patron->send_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2026
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2027
2027
2028
    $patron->email(q|awesome@ismymiddle.name|)->store;
2028
    $patron->email(q|awesome@ismymiddle.name|)->store;
2029
    is_deeply(
2029
    is_deeply(
2030
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2030
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2031
        {sent => ['email'] }, "Email sent when using borrower preferences"
2031
        {sent => ['email'] }, "Email sent when using borrower preferences"
2032
    );
2032
    );
2033
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2033
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2034
    is_deeply(
2034
    is_deeply(
2035
        $patron->send_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2035
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled', test_mode => 1 }),
2036
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2036
        {sent => ['email'] }, "Report that email sent when using borrower preferences in test_mode"
2037
    );
2037
    );
2038
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2038
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter,"Count of queued notices not increased in test mode");
2039
- 

Return to bug 15986