From 9a1c17509fa32bad2c03c1da8b3d2c0aff8f52b4 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 30 Mar 2023 08:58:10 +0200 Subject: [PATCH] Bug 33360: Incorporate Koha::Notice::Util in Letters:SendQueuedMessages Minimal adjustment to get the feature working. Will still be improved in follow-up. Test plan: [1] Add a domain limit to your koha-conf: gmail.com1 1h Replace gmail.com by the domain you want to send to. Restart all. [2] Disable cron job for message queue. [3] Generate two pending notices in the queue. [4] Run process_message_queue.pl [5] Check that one is sent, one is still pending. [6] Run again. [7] Check: nothing is sent, last one still pending. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Letters.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/C4/Letters.pm b/C4/Letters.pm index 36d3f5d77e..f45771c932 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -34,6 +34,7 @@ use Koha::SMS::Providers; use Koha::Email; use Koha::Notice::Messages; use Koha::Notice::Templates; +use Koha::Notice::Util; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Auth::TwoFactorAuth; use Koha::Patrons; @@ -65,6 +66,8 @@ BEGIN { ); } +our $domain_limits = {}; + =head1 NAME C4::Letters - Give functions for Letters management @@ -984,6 +987,7 @@ sub SendQueuedMessages { 'where' => $params->{'where'} // q{}, }; my $unsent_messages = _get_unsent_messages( $which_unsent_messages ); + $domain_limits = Koha::Notice::Util->load_domain_limits; # (re)initialize per run MESSAGE: foreach my $message ( @$unsent_messages ) { my $message_object = Koha::Notice::Messages->find( $message->{message_id} ); # If this fails the database is unwritable and we won't manage to send a message that continues to be marked 'pending' @@ -1332,6 +1336,9 @@ sub _send_message_by_email { } } + # Skip this message if we exceed domain limits in this run + return if Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }); + my $subject = $message->{'subject'}; my $content = $message->{'content'}; -- 2.39.5