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

(-)a/C4/Letters.pm (-6 / +10 lines)
Lines 972-983 Returns number of messages sent. Link Here
972
sub SendQueuedMessages {
972
sub SendQueuedMessages {
973
    my $params = shift;
973
    my $params = shift;
974
974
975
    my $which_unsent_messages  = {
975
    my $which_unsent_messages = {
976
        'message_id'     => $params->{'message_id'},
976
        'message_id'             => $params->{'message_id'},
977
        'limit'          => $params->{'limit'} // 0,
977
        'limit'                  => $params->{'limit'} // 0,
978
        'borrowernumber' => $params->{'borrowernumber'} // q{},
978
        'borrowernumber'         => $params->{'borrowernumber'} // q{},
979
        'letter_code'    => $params->{'letter_code'} // q{},
979
        'letter_code'            => $params->{'letter_code'} // q{},
980
        'message_transport_type'           => $params->{'type'} // q{},
980
        'message_transport_type' => $params->{'type'} // q{},
981
        'where'                  => $params->{'where'} // q{},
981
    };
982
    };
982
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
983
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
983
    MESSAGE: foreach my $message ( @$unsent_messages ) {
984
    MESSAGE: foreach my $message ( @$unsent_messages ) {
Lines 1281-1286 sub _get_unsent_messages { Link Here
1281
            $statement .= ' AND message_id = ?';
1282
            $statement .= ' AND message_id = ?';
1282
            push @query_params, $params->{message_id};
1283
            push @query_params, $params->{message_id};
1283
        }
1284
        }
1285
        if ( $params->{where} ) {
1286
            $statement .= " AND $params->{where} ";
1287
        }
1284
        if ( $params->{'limit'} ) {
1288
        if ( $params->{'limit'} ) {
1285
            $statement .= ' limit ? ';
1289
            $statement .= ' limit ? ';
1286
            push @query_params, $params->{'limit'};
1290
            push @query_params, $params->{'limit'};
(-)a/misc/cronjobs/process_message_queue.pl (+4 lines)
Lines 32-37 my $limit = undef; Link Here
32
my $method = 'LOGIN';
32
my $method = 'LOGIN';
33
my $help = 0;
33
my $help = 0;
34
my $verbose = 0;
34
my $verbose = 0;
35
my $where;
35
my @type;
36
my @type;
36
my @letter_code;
37
my @letter_code;
37
38
Lines 46-51 GetOptions( Link Here
46
    'v|verbose'         => \$verbose,
47
    'v|verbose'         => \$verbose,
47
    't|type:s'          => \@type,
48
    't|type:s'          => \@type,
48
    'c|code:s'          => \@letter_code,
49
    'c|code:s'          => \@letter_code,
50
    'w|where:s'         => \$where,
49
);
51
);
50
my $usage = << 'ENDUSAGE';
52
my $usage = << 'ENDUSAGE';
51
53
Lines 64-69 This script has the following parameters : Link Here
64
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
66
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
65
    -h --help: this message
67
    -h --help: this message
66
    -v --verbose: provides verbose output to STDOUT
68
    -v --verbose: provides verbose output to STDOUT
69
    -w --where: filter messages to send with additional conditions in the where clause
67
ENDUSAGE
70
ENDUSAGE
68
71
69
die $usage if $help;
72
die $usage if $help;
Lines 116-121 C4::Letters::SendQueuedMessages( Link Here
116
        limit       => $limit,
119
        limit       => $limit,
117
        type        => \@type,
120
        type        => \@type,
118
        letter_code => \@letter_code,
121
        letter_code => \@letter_code,
122
        where       => $where,
119
    }
123
    }
120
);
124
);
121
125
(-)a/t/db_dependent/Letters.t (-2 / +62 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 85;
21
use Test::More tests => 86;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
Lines 906-911 EOF Link Here
906
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
906
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
907
};
907
};
908
908
909
subtest 'Test where parameter for SendQueuedMessages' => sub {
910
    plan tests => 1;
911
912
    my $dbh = C4::Context->dbh;
913
914
    my $borrowernumber = Koha::Patron->new({
915
        firstname    => 'Jane',
916
        surname      => 'Smith',
917
        categorycode => $patron_category,
918
        branchcode   => $library->{branchcode},
919
        dateofbirth  => $date,
920
        smsalertnumber => undef,
921
    })->store->borrowernumber;
922
923
    $dbh->do(q|DELETE FROM message_queue|);
924
    $my_message = {
925
        'letter' => {
926
            'content'      => 'a message',
927
            'metadata'     => 'metadata',
928
            'code'         => 'TEST_MESSAGE',
929
            'content_type' => 'text/plain',
930
            'title'        => 'message title'
931
        },
932
        'borrowernumber'         => $borrowernumber,
933
        'to_address'             => undef,
934
        'message_transport_type' => 'sms',
935
        'from_address'           => 'from@example.com'
936
    };
937
    my $my_message2 = {
938
        'letter' => {
939
            'content'      => 'another message',
940
            'metadata'     => 'metadata',
941
            'code'         => 'TEST_MESSAGE',
942
            'content_type' => 'text/plain',
943
            'title'        => 'message title'
944
        },
945
        'borrowernumber'         => $borrowernumber,
946
        'to_address'             => undef,
947
        'message_transport_type' => 'sms',
948
        'from_address'           => 'from@example.com'
949
    };
950
    my $my_message3 = {
951
        'letter' => {
952
            'content'      => 'a skipped message',
953
            'metadata'     => 'metadata',
954
            'code'         => 'TEST_MESSAGE',
955
            'content_type' => 'text/plain',
956
            'title'        => 'message title'
957
        },
958
        'borrowernumber'         => $borrowernumber,
959
        'to_address'             => undef,
960
        'message_transport_type' => 'sms',
961
        'from_address'           => 'from@example.com'
962
    };
963
    C4::Letters::EnqueueLetter($my_message);
964
    C4::Letters::EnqueueLetter($my_message2);
965
    C4::Letters::EnqueueLetter($my_message3);
966
    my $messages_processed = C4::Letters::SendQueuedMessages( { where => q{content NOT LIKE '%skipped%'} } );
967
    is( $messages_processed, 2, "Correctly skipped processing one message containing the work 'skipped' in contents" );
968
};
969
909
subtest 'Test limit parameter for SendQueuedMessages' => sub {
970
subtest 'Test limit parameter for SendQueuedMessages' => sub {
910
    plan tests => 3;
971
    plan tests => 3;
911
972
912
- 

Return to bug 31453