Commit 159e99f3 authored by joubu's avatar joubu Committed by Galen Charlton

Bug 11209: Don't sent the same SMS message for the same user the same day

For PREDUE messages, one message is sent to the message_queue table for
each items in advance, meaning that the patron could receive duplicate
notices.

The SMS part for DUE and PREDUE often do not contain dynamic parts, only
a standard message.

Note that this patch *only* affects the SMS transport.
Signed-off-by: default avatarChris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: default avatarMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton's avatarGalen Charlton <gmc@esilibrary.com>
parent 0423b43b
......@@ -916,7 +916,7 @@ sub _get_unsent_messages {
my $dbh = C4::Context->dbh();
my $statement = << 'ENDSQL';
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
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
FROM message_queue mq
LEFT JOIN borrowers b ON b.borrowernumber = mq.borrowernumber
WHERE status = ?
......@@ -1024,6 +1024,21 @@ $content
EOS
}
sub _is_duplicate {
my ( $message ) = @_;
my $dbh = C4::Context->dbh;
my $count = $dbh->selectrow_array(q|
SELECT COUNT(*)
FROM message_queue
WHERE message_transport_type = ?
AND borrowernumber = ?
AND letter_code = ?
AND CAST(time_queued AS date) = CAST(? AS date)
AND status="sent"
|, {}, $message->{message_transport_type}, $message->{borrowernumber}, $message->{letter_code}, $message->{time_queued} );
return $count;
}
sub _send_message_by_sms {
my $message = shift or return;
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
......@@ -1034,6 +1049,12 @@ sub _send_message_by_sms {
return;
}
if ( _is_duplicate( $message ) ) {
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
return;
}
my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
message => $message->{'content'},
} );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment