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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Kyle M Hall 2024-09-09 14:18:07 +00:00 committed by Katrin Fischer
parent cac4a50817
commit 4a7c732f1f
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 19 additions and 26 deletions

View File

@ -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;

View File

@ -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,
}
);