From 159e99f3bc90f0e9463a6e8a96ae477d762625ee Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Nov 2013 14:56:35 +0100 Subject: [PATCH] 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: Chris Cormack Signed-off-by: Marcel de Rooy Signed-off-by: Galen Charlton --- C4/Letters.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index cefe7bd37e..aa823f420d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -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'}, } ); -- 2.39.5