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

(-)a/C4/Letters.pm (-7 / +7 lines)
Lines 1034-1040 returns number of messages sent. Link Here
1034
sub SendQueuedMessages {
1034
sub SendQueuedMessages {
1035
    my $params = shift;
1035
    my $params = shift;
1036
1036
1037
    my $unsent_messages = _get_unsent_messages();
1037
    my $unsent_messages = _get_unsent_messages( { limit => $params->{limit} } );
1038
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1038
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1039
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1039
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1040
        warn sprintf( 'sending %s message to patron: %s',
1040
        warn sprintf( 'sending %s message to patron: %s',
Lines 1268-1279 sub _get_unsent_messages { Link Here
1268
    my $params = shift;
1268
    my $params = shift;
1269
1269
1270
    my $dbh = C4::Context->dbh();
1270
    my $dbh = C4::Context->dbh();
1271
    my $statement = << 'ENDSQL';
1271
    my $statement = qq{
1272
SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code
1272
        SELECT mq.message_id, mq.borrowernumber, mq.subject, mq.content, mq.message_transport_type, mq.status, mq.time_queued, mq.from_address, mq.to_address, mq.content_type, b.branchcode, mq.letter_code
1273
  FROM message_queue mq
1273
        FROM message_queue mq
1274
  LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
1274
        LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
1275
 WHERE status = ?
1275
        WHERE status = ?
1276
ENDSQL
1276
    };
1277
1277
1278
    my @query_params = ('pending');
1278
    my @query_params = ('pending');
1279
    if ( ref $params ) {
1279
    if ( ref $params ) {
(-)a/misc/cronjobs/process_message_queue.pl (-1 / +12 lines)
Lines 31-36 use Getopt::Long; Link Here
31
31
32
my $username = undef;
32
my $username = undef;
33
my $password = undef;
33
my $password = undef;
34
my $limit    = undef;
34
my $method = 'LOGIN';
35
my $method = 'LOGIN';
35
my $help = 0;
36
my $help = 0;
36
my $verbose = 0;
37
my $verbose = 0;
Lines 38-43 my $verbose = 0; Link Here
38
GetOptions(
39
GetOptions(
39
    'u|username:s'      => \$username,
40
    'u|username:s'      => \$username,
40
    'p|password:s'      => \$password,
41
    'p|password:s'      => \$password,
42
    'l|limit:s'         => \$limit,
41
    'm|method:s'        => \$method,
43
    'm|method:s'        => \$method,
42
    'h|help|?'          => \$help,
44
    'h|help|?'          => \$help,
43
    'v|verbose'         => \$verbose,
45
    'v|verbose'         => \$verbose,
Lines 53-58 advance_notices.pl script. Link Here
53
This script has the following parameters :
55
This script has the following parameters :
54
    -u --username: username of mail account
56
    -u --username: username of mail account
55
    -p --password: password of mail account
57
    -p --password: password of mail account
58
    -l --limit: The maximum number of messages to process for this run
56
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
59
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
57
    -h --help: this message
60
    -h --help: this message
58
    -v --verbose: provides verbose output to STDOUT
61
    -v --verbose: provides verbose output to STDOUT
Lines 63-67 die $usage if $help; Link Here
63
66
64
cronlogaction();
67
cronlogaction();
65
68
66
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } );
69
C4::Letters::SendQueuedMessages(
70
    {
71
        verbose  => $verbose,
72
        username => $username,
73
        password => $password,
74
        method   => $method,
75
        limit    => $limit,
76
    }
77
);
67
78
(-)a/t/db_dependent/Letters.t (-2 / +46 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 => 82;
21
use Test::More tests => 83;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 109-114 $my_message->{letter} = { Link Here
109
    code         => 'TEST_MESSAGE',
109
    code         => 'TEST_MESSAGE',
110
    content_type => 'text/plain',
110
    content_type => 'text/plain',
111
};
111
};
112
112
$message_id = C4::Letters::EnqueueLetter($my_message);
113
$message_id = C4::Letters::EnqueueLetter($my_message);
113
is( $message_id, undef, 'EnqueueLetter without the message type argument argument returns undef' );
114
is( $message_id, undef, 'EnqueueLetter without the message type argument argument returns undef' );
114
115
Lines 628-630 subtest 'SendQueuedMessages' => sub { Link Here
628
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
629
    is( $sms_message_address, '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email' );
629
630
630
};
631
};
631
- 
632
633
subtest 'Test limit parameter for SendQueuedMessages' => sub {
634
    plan tests => 3;
635
636
    my $dbh = C4::Context->dbh;
637
638
    my $borrowernumber = AddMember(
639
        firstname    => 'Jane',
640
        surname      => 'Smith',
641
        categorycode => $patron_category,
642
        branchcode   => $library->{branchcode},
643
        dateofbirth  => $date,
644
        smsalertnumber => undef,
645
    );
646
647
    $dbh->do(q|DELETE FROM message_queue|);
648
    $my_message = {
649
        'letter' => {
650
            'content'      => 'a message',
651
            'metadata'     => 'metadata',
652
            'code'         => 'TEST_MESSAGE',
653
            'content_type' => 'text/plain',
654
            'title'        => 'message title'
655
        },
656
        'borrowernumber'         => $borrowernumber,
657
        'to_address'             => undef,
658
        'message_transport_type' => 'sms',
659
        'from_address'           => 'from@example.com'
660
    };
661
    C4::Letters::EnqueueLetter($my_message);
662
    C4::Letters::EnqueueLetter($my_message);
663
    C4::Letters::EnqueueLetter($my_message);
664
    C4::Letters::EnqueueLetter($my_message);
665
    C4::Letters::EnqueueLetter($my_message);
666
    my $messages_processed = C4::Letters::SendQueuedMessages( { limit => 1 } );
667
    is( $messages_processed, 1,
668
        'Processed 1 message with limit of 1 and 5 unprocessed messages' );
669
    $messages_processed = C4::Letters::SendQueuedMessages( { limit => 2 } );
670
    is( $messages_processed, 2,
671
        'Processed 2 message with limit of 2 and 4 unprocessed messages' );
672
    $messages_processed = C4::Letters::SendQueuedMessages( { limit => 3 } );
673
    is( $messages_processed, 2,
674
        'Processed 2 message with limit of 3 and 2 unprocessed messages' );
675
};

Return to bug 18894