From 4a7c732f1f200083096c154d2a5f84639cb374d7 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 9 Sep 2024 14:18:07 +0000 Subject: [PATCH] Bug 37869: Move plugin hook before_send_messages to SendQueuedMessages Most messages in Koha are handled by process_message_queue.pl. This script calls before_send_messages which calls the plugin hook before_send_messages. This works for nearly all messages, but some messages like WELCOME notices are triggered immediately and do not way to for process_message_queue.pl to run. We should move the triggering of before_send_messages into SendQueuedMessages so it is always handled. Test Plan: 1) Install version 2.5.1 of the kitchen sink plugin 2) Run process_messsage_queue.pl and also trigger a WELCOME notice 3) Note the "Plugin hook before_send_message called with the params" message in the logs for the former but not the latter 4) Apply this patch 5) Repeat step 2, note there the message also shows in the logs for the WELCOME notice! Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Letters.pm | 18 +++++++++++++++++ misc/cronjobs/process_message_queue.pl | 27 +------------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 7bdbfc9bf2..4fb28fdcce 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1021,6 +1021,24 @@ sub SendQueuedMessages { Koha::Exceptions::BadParameter->throw("Parameter message_id cannot be empty if passed.") if ( exists( $params->{message_id} ) && !$params->{message_id} ); + if ( C4::Context->config("enable_plugins") ) { + my @plugins = Koha::Plugins->new->GetPlugins({ + method => 'before_send_messages', + }); + + if (@plugins) { + foreach my $plugin ( @plugins ) { + try { + $plugin->before_send_messages($params); + } + catch { + warn "$_"; + exit 1 if $params->{exit_on_plugin_failure}; + }; + } + } + } + my $smtp_transports = {}; my $count_messages = 0; diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl index 0c4ff176f7..031b965fe4 100755 --- a/misc/cronjobs/process_message_queue.pl +++ b/misc/cronjobs/process_message_queue.pl @@ -92,32 +92,6 @@ cronlogaction({ info => $command_line_options }); # Remove empty elements, see bug 37075 @letter_code = grep { $_ ne q{} } @letter_code; -if ( C4::Context->config("enable_plugins") ) { - my @plugins = Koha::Plugins->new->GetPlugins({ - method => 'before_send_messages', - }); - - if (@plugins) { - foreach my $plugin ( @plugins ) { - try { - $plugin->before_send_messages( - { - verbose => $verbose, - limit => $limit, - type => \@type, - letter_code => \@letter_code, - where => $where, - } - ); - } - catch { - warn "$_"; - exit 1 if $exit_on_plugin_failure; - }; - } - } -} - C4::Letters::SendQueuedMessages( { verbose => $verbose, @@ -128,6 +102,7 @@ C4::Letters::SendQueuedMessages( type => \@type, letter_code => \@letter_code, where => $where, + exit_on_plugin_failure => $exit_on_plugin_failure, } ); -- 2.39.5