Bug 19955: Add ability to process only one 'type' of message ( sms, email, etc ) for a given run of process_message_queue.pl
It would be nice to allow emails to be sent overnight, but limit the sending of SMS messages to hours when people are awake. Adding a type limit to process_message_queue.pl would allow this to be accomplished easily. Signed-off-by: Charles Farmer <charles.farmer@inLibro.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
b02528d8bb
commit
379ffd043e
|
|
@ -1027,7 +1027,8 @@ ENDSQL
|
|||
letter_code => $letter_code,
|
||||
borrowernumber => $who_letter_is_for,
|
||||
limit => 50,
|
||||
verbose => 1
|
||||
verbose => 1,
|
||||
type => 'sms',
|
||||
});
|
||||
|
||||
Sends all of the 'pending' items in the message queue, unless
|
||||
|
|
@ -1051,6 +1052,7 @@ sub SendQueuedMessages {
|
|||
'limit' => $params->{'limit'} // 0,
|
||||
'borrowernumber' => $params->{'borrowernumber'} // q{},
|
||||
'letter_code' => $params->{'letter_code'} // q{},
|
||||
'type' => $params->{'type'} // q{},
|
||||
};
|
||||
my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
|
||||
MESSAGE: foreach my $message ( @$unsent_messages ) {
|
||||
|
|
@ -1321,6 +1323,10 @@ sub _get_unsent_messages {
|
|||
$statement .= ' AND mq.letter_code = ? ';
|
||||
push @query_params, $params->{'letter_code'};
|
||||
}
|
||||
if ( $params->{'type'} ) {
|
||||
$statement .= ' AND message_transport_type = ? ';
|
||||
push @query_params, $params->{'type'};
|
||||
}
|
||||
if ( $params->{'limit'} ) {
|
||||
$statement .= ' limit ? ';
|
||||
push @query_params, $params->{'limit'};
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ my $limit = undef;
|
|||
my $method = 'LOGIN';
|
||||
my $help = 0;
|
||||
my $verbose = 0;
|
||||
my $type = q{};
|
||||
|
||||
GetOptions(
|
||||
'u|username:s' => \$username,
|
||||
|
|
@ -43,6 +44,7 @@ GetOptions(
|
|||
'm|method:s' => \$method,
|
||||
'h|help|?' => \$help,
|
||||
'v|verbose' => \$verbose,
|
||||
't|type' => \$type,
|
||||
);
|
||||
my $usage = << 'ENDUSAGE';
|
||||
|
||||
|
|
@ -55,11 +57,11 @@ advance_notices.pl script.
|
|||
This script has the following parameters :
|
||||
-u --username: username of mail account
|
||||
-p --password: password of mail account
|
||||
-t --type: If supplied, only processes this type of message ( email, sms )
|
||||
-l --limit: The maximum number of messages to process for this run
|
||||
-m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
|
||||
-h --help: this message
|
||||
-v --verbose: provides verbose output to STDOUT
|
||||
|
||||
ENDUSAGE
|
||||
|
||||
die $usage if $help;
|
||||
|
|
@ -73,6 +75,7 @@ C4::Letters::SendQueuedMessages(
|
|||
password => $password,
|
||||
method => $method,
|
||||
limit => $limit,
|
||||
type => $type,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -133,8 +133,10 @@ is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin
|
|||
|
||||
|
||||
# SendQueuedMessages
|
||||
my $messages_processed = C4::Letters::SendQueuedMessages();
|
||||
is($messages_processed, 1, 'all queued messages processed');
|
||||
my $messages_processed = C4::Letters::SendQueuedMessages( { type => 'email' });
|
||||
is($messages_processed, 0, 'No queued messaged process if type limit passed with unused type');
|
||||
$messages_processed = C4::Letters::SendQueuedMessages( { type => 'sms' });
|
||||
is($messages_processed, 1, 'all queued messages processed, found correct number of messages with type limit');
|
||||
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
|
||||
is(
|
||||
$messages->[0]->{status},
|
||||
|
|
|
|||
Loading…
Reference in New Issue