@@ -, +, @@
up anything to actually send messages on your test instance
---
C4/Letters.pm | 6 +++
.../data/mysql/atomicupdate/bug_37885.pl | 21 +++++++++
installer/data/mysql/mandatory/sysprefs.sql | 1 +
.../en/modules/admin/preferences/admin.pref | 9 ++++
t/db_dependent/Letters.t | 47 ++++++++++++++++++-
5 files changed, 83 insertions(+), 1 deletion(-)
create mode 100755 installer/data/mysql/atomicupdate/bug_37885.pl
--- a/C4/Letters.pm
+++ a/C4/Letters.pm
@@ -1021,6 +1021,10 @@ sub SendQueuedMessages {
Koha::Exceptions::BadParameter->throw("Parameter message_id cannot be empty if passed.")
if ( exists( $params->{message_id} ) && !$params->{message_id} );
+ my $MessageQueueMode = C4::Context->preference('MessageQueueMode');
+
+ return 0 unless ( $MessageQueueMode eq 'on' || $MessageQueueMode eq 'plugin' );
+
if ( C4::Context->config("enable_plugins") ) {
my @plugins = Koha::Plugins->new->GetPlugins({
method => 'before_send_messages',
@@ -1038,6 +1042,8 @@ sub SendQueuedMessages {
}
}
+ return 0 unless ( $MessageQueueMode eq 'on' );
+
my $smtp_transports = {};
my $count_messages = 0;
--- a/installer/data/mysql/atomicupdate/bug_37885.pl
+++ a/installer/data/mysql/atomicupdate/bug_37885.pl
@@ -0,0 +1,21 @@
+use Modern::Perl;
+use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
+
+return {
+ bug_number => "37885",
+ description => "Add ability to disable message queue processing",
+ up => sub {
+ my ($args) = @_;
+ my ( $dbh, $out ) = @$args{qw(dbh out)};
+
+ try {
+ $dbh->do(q{
+ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('MessageQueueMode','on','on|off|plugins','Search Engine','Choice');
+ });
+ say_success( $out, "Added new system preference 'MessageQueueMode'" );
+ } catch {
+ say_failure( $out, "Failed to add new system preference 'MessageQueueMode'" );
+ }
+ },
+};
--- a/installer/data/mysql/mandatory/sysprefs.sql
+++ a/installer/data/mysql/mandatory/sysprefs.sql
@@ -411,6 +411,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('MaxTotalSuggestions','',NULL,'Number of total suggestions used for time limit with NumberOfSuggestionDays','Free'),
('MembershipExpiryDaysNotice','',NULL,'Send an account expiration notice that a patron\'s card is about to expire after','Integer'),
('MergeReportFields','',NULL,'Displayed fields for deleted MARC records after merge','Free'),
+('MessageQueueMode','on','on|off|plugins','Search Engine','Choice'),
('minPasswordLength','8',NULL,'Specify the minimum length of a patron/staff password','free'),
('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
@@ -301,3 +301,12 @@ Administration:
"ARRAY": "Searchable array"
-
ISO2709 format is recommended as it is faster and takes less space, whereas array format makes the full MARC record searchable.
-
NOTE: Making the full record searchable may have a negative effect on relevance ranking of search results.
+ Message processing:
+ -
+ - "When running the message queue processor"
+ - pref: MessageQueueMode
+ default: on
+ choices:
+ on: process all messages and plugin hooks
+ plugins: process plugin hooks only
+ off: process nothing
--- a/t/db_dependent/Letters.t
+++ a/t/db_dependent/Letters.t
@@ -19,7 +19,7 @@
use Modern::Perl;
use File::Basename qw(dirname);
-use Test::More tests => 103;
+use Test::More tests => 104;
use Test::MockModule;
use Test::Warn;
@@ -1582,3 +1582,48 @@ subtest 'Quote user params in GetPreparedLetter' => sub {
$exec_time
);
};
+
+subtest 'Test MessageQueueMode' => sub {
+ plan tests => 3;
+
+ my $dbh = C4::Context->dbh;
+
+ my $borrowernumber = Koha::Patron->new(
+ {
+ firstname => 'Jane',
+ surname => 'Smith',
+ categorycode => $patron_category,
+ branchcode => $library->{branchcode},
+ dateofbirth => $date,
+ }
+ )->store->borrowernumber;
+
+ $dbh->do(q|DELETE FROM message_queue|);
+ $my_message = {
+ 'letter' => {
+ 'content' => 'a message',
+ 'metadata' => 'metadata',
+ 'code' => 'TEST_MESSAGE',
+ 'content_type' => 'text/plain',
+ 'title' => 'message title'
+ },
+ 'borrowernumber' => $borrowernumber,
+ 'to_address' => undef,
+ 'message_transport_type' => 'sms',
+ 'from_address' => 'from@example.com'
+ };
+
+ my $id = C4::Letters::EnqueueLetter($my_message);
+
+ t::lib::Mocks::mock_preference( 'MessageQueueMode', 'off' );
+ C4::Letters::SendQueuedMessages();
+ is( Koha::Notice::Messages->find($id)->status, 'pending', 'Message is pending for off' );
+
+ t::lib::Mocks::mock_preference( 'MessageQueueMode', 'plugin' );
+ C4::Letters::SendQueuedMessages();
+ is( Koha::Notice::Messages->find($id)->status, 'pending', 'Message is pending for plugin' );
+
+ t::lib::Mocks::mock_preference( 'MessageQueueMode', 'on' );
+ C4::Letters::SendQueuedMessages();
+ is( Koha::Notice::Messages->find($id)->status, 'failed', 'Message is failed for on' );
+};
--