From af2a02e4606dcb2fd9c421a5f402f7ccef1e9b8b Mon Sep 17 00:00:00 2001 From: Simon Mok Date: Mon, 12 Oct 2020 19:33:18 +0800 Subject: [PATCH] MDL-68070 messaging: Fix error when personal notification is disabled --- lang/en/error.php | 1 + message/classes/api.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lang/en/error.php b/lang/en/error.php index 1c50771e6d4..749cd1000d9 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -389,6 +389,7 @@ $string['loginasonecourse'] = 'You cannot enter this course.
You have to t $string['maxbytesfile'] = 'The file {$a->file} is too large. The maximum size you can upload is {$a->size}.'; $string['maxareabytes'] = 'The file is larger than the space remaining in this area.'; $string['messagingdisable'] = 'Messaging is disabled on this site'; +$string['messageundeliveredbynotificationsettings'] = 'Message failed to deliver. Please check the notification settings.'; $string['mimetexisnotexist'] = 'Your system is not configured to run mimeTeX. You need to obtain the C source from https://www.forkosh.com/mimetex.zip, compile it and put the executable into your moodle/filter/tex/ directory.'; $string['mimetexnotexecutable'] = 'Custom mimetex is not executable!'; $string['missingfield'] = 'Field "{$a}" is missing'; diff --git a/message/classes/api.php b/message/classes/api.php index a9a6675dfe0..e3d830055e7 100644 --- a/message/classes/api.php +++ b/message/classes/api.php @@ -2010,6 +2010,10 @@ class api { $messageid = message_send($eventdata); + if (!$messageid) { + throw new \moodle_exception('messageundeliveredbynotificationsettings', 'moodle'); + } + $messagerecord = $DB->get_record('messages', ['id' => $messageid], 'id, useridfrom, fullmessage, timecreated, fullmessagetrust'); $message = (object) [ -- 2.11.4.GIT