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