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

(-)a/C4/Letters.pm (-2 / +6 lines)
Lines 1026-1032 ENDSQL Link Here
1026
1026
1027
=head2 SendQueuedMessages ([$hashref]) 
1027
=head2 SendQueuedMessages ([$hashref]) 
1028
1028
1029
    my $sent = SendQueuedMessages({ verbose => 1, limit => 50 });
1029
    my $sent = SendQueuedMessages({ verbose => 1, limit => 50, type => 'sms' });
1030
1030
1031
Sends all of the 'pending' items in the message queue, unless the optional
1031
Sends all of the 'pending' items in the message queue, unless the optional
1032
limit parameter is passed too. The verbose parameter is also optional.
1032
limit parameter is passed too. The verbose parameter is also optional.
Lines 1038-1044 Returns number of messages sent. Link Here
1038
sub SendQueuedMessages {
1038
sub SendQueuedMessages {
1039
    my $params = shift;
1039
    my $params = shift;
1040
1040
1041
    my $unsent_messages = _get_unsent_messages( { limit => $params->{limit} } );
1041
    my $unsent_messages = _get_unsent_messages( { limit => $params->{limit}, type => $params->{type} } );
1042
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1042
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1043
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1043
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1044
        warn sprintf( 'sending %s message to patron: %s',
1044
        warn sprintf( 'sending %s message to patron: %s',
Lines 1289-1294 sub _get_unsent_messages { Link Here
1289
            $statement .= ' AND borrowernumber = ? ';
1289
            $statement .= ' AND borrowernumber = ? ';
1290
            push @query_params, $params->{'borrowernumber'};
1290
            push @query_params, $params->{'borrowernumber'};
1291
        }
1291
        }
1292
        if ( $params->{'type'} ) {
1293
            $statement .= ' AND message_transport_type = ? ';
1294
            push @query_params, $params->{'type'};
1295
        }
1292
        if ( $params->{'limit'} ) {
1296
        if ( $params->{'limit'} ) {
1293
            $statement .= ' limit ? ';
1297
            $statement .= ' limit ? ';
1294
            push @query_params, $params->{'limit'};
1298
            push @query_params, $params->{'limit'};
(-)a/misc/cronjobs/process_message_queue.pl (-1 / +4 lines)
Lines 35-40 my $limit = undef; Link Here
35
my $method = 'LOGIN';
35
my $method = 'LOGIN';
36
my $help = 0;
36
my $help = 0;
37
my $verbose = 0;
37
my $verbose = 0;
38
my $type = q{};
38
39
39
GetOptions(
40
GetOptions(
40
    'u|username:s'      => \$username,
41
    'u|username:s'      => \$username,
Lines 43-48 GetOptions( Link Here
43
    'm|method:s'        => \$method,
44
    'm|method:s'        => \$method,
44
    'h|help|?'          => \$help,
45
    'h|help|?'          => \$help,
45
    'v|verbose'         => \$verbose,
46
    'v|verbose'         => \$verbose,
47
    't|type'            => \$type,
46
);
48
);
47
my $usage = << 'ENDUSAGE';
49
my $usage = << 'ENDUSAGE';
48
50
Lines 55-65 advance_notices.pl script. Link Here
55
This script has the following parameters :
57
This script has the following parameters :
56
    -u --username: username of mail account
58
    -u --username: username of mail account
57
    -p --password: password of mail account
59
    -p --password: password of mail account
60
    -t --type: If supplied, only processes this type of message ( email, sms )
58
    -l --limit: The maximum number of messages to process for this run
61
    -l --limit: The maximum number of messages to process for this run
59
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
62
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
60
    -h --help: this message
63
    -h --help: this message
61
    -v --verbose: provides verbose output to STDOUT
64
    -v --verbose: provides verbose output to STDOUT
62
63
ENDUSAGE
65
ENDUSAGE
64
66
65
die $usage if $help;
67
die $usage if $help;
Lines 73-78 C4::Letters::SendQueuedMessages( Link Here
73
        password => $password,
75
        password => $password,
74
        method   => $method,
76
        method   => $method,
75
        limit    => $limit,
77
        limit    => $limit,
78
        type     => $type,
76
    }
79
    }
77
);
80
);
78
81
(-)a/t/db_dependent/Letters.t (-4 / +5 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 => 76;
21
use Test::More tests => 77;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 133-140 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
133
133
134
134
135
# SendQueuedMessages
135
# SendQueuedMessages
136
my $messages_processed = C4::Letters::SendQueuedMessages();
136
my $messages_processed = C4::Letters::SendQueuedMessages( { type => 'email' });
137
is($messages_processed, 1, 'all queued messages processed');
137
is($messages_processed, 0, 'No queued messaged process if type limit passed with unused type');
138
$messages_processed = C4::Letters::SendQueuedMessages( { type => 'sms' });
139
is($messages_processed, 1, 'all queued messages processed, found correct number of messages with type limit');
138
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
140
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
139
is(
141
is(
140
    $messages->[0]->{status},
142
    $messages->[0]->{status},
141
- 

Return to bug 19955