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

(-)a/C4/Letters.pm (-2 / +6 lines)
Lines 1023-1029 ENDSQL Link Here
1023
1023
1024
=head2 SendQueuedMessages ([$hashref]) 
1024
=head2 SendQueuedMessages ([$hashref]) 
1025
1025
1026
    my $sent = SendQueuedMessages({ verbose => 1, limit => 50 });
1026
    my $sent = SendQueuedMessages({ verbose => 1, limit => 50, type => 'sms' });
1027
1027
1028
Sends all of the 'pending' items in the message queue, unless the optional
1028
Sends all of the 'pending' items in the message queue, unless the optional
1029
limit parameter is passed too. The verbose parameter is also optional.
1029
limit parameter is passed too. The verbose parameter is also optional.
Lines 1035-1041 Returns number of messages sent. Link Here
1035
sub SendQueuedMessages {
1035
sub SendQueuedMessages {
1036
    my $params = shift;
1036
    my $params = shift;
1037
1037
1038
    my $unsent_messages = _get_unsent_messages( { limit => $params->{limit} } );
1038
    my $unsent_messages = _get_unsent_messages( { limit => $params->{limit}, type => $params->{type} } );
1039
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1039
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1040
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1040
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1041
        warn sprintf( 'sending %s message to patron: %s',
1041
        warn sprintf( 'sending %s message to patron: %s',
Lines 1286-1291 sub _get_unsent_messages { Link Here
1286
            $statement .= ' AND borrowernumber = ? ';
1286
            $statement .= ' AND borrowernumber = ? ';
1287
            push @query_params, $params->{'borrowernumber'};
1287
            push @query_params, $params->{'borrowernumber'};
1288
        }
1288
        }
1289
        if ( $params->{'type'} ) {
1290
            $statement .= ' AND message_transport_type = ? ';
1291
            push @query_params, $params->{'type'};
1292
        }
1289
        if ( $params->{'limit'} ) {
1293
        if ( $params->{'limit'} ) {
1290
            $statement .= ' limit ? ';
1294
            $statement .= ' limit ? ';
1291
            push @query_params, $params->{'limit'};
1295
            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 => 77;
21
use Test::More tests => 78;
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