-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.1.13, 4.4.3
-
MOODLE_401_STABLE, MOODLE_404_STABLE
I was wondering, why my Moodle instance's cron task (core\task\send_login_notifications) is logging the message: Failed to send notification
Execute adhoc task: core\task\send_login_notifications
|
... started 10:16:04. Current memory use 35.0 MB. |
Sending login notification to user@example.org |
Failed to send notification
|
... used 5 dbqueries |
... used 0.031110048294067 seconds |
Adhoc task complete: core\task\send_login_notifications
|
Ran 1 adhoc tasks found at Thu, 19 Sep 2024 10:16:04 +0200 |
Cron script completed correctly
|
…although, sending new login notification is disabled.
Being curious I took a look into the code and realized, that the current code does not distinguish a failure upon sending and the notification being disable. The only options are:
- Notification successfully sent
- Failed to send notification
So I patched it to suit my purposes (however I wanted to make as little changes as possible):
diff --git a/lib/classes/task/send_login_notifications.php b/lib/classes/task/send_login_notifications.php
|
index 245a518fb5a..11cb00b642a 100644 |
--- a/lib/classes/task/send_login_notifications.php
|
+++ b/lib/classes/task/send_login_notifications.php
|
@@ -87,7 +87,10 @@ class send_login_notifications extends adhoc_task { |
$userpicture->includetoken = $USER->id; // Generate an out-of-session token for the user receiving the message. |
$eventdata->customdata = ['notificationiconurl' => $userpicture->get_url($PAGE)->out(false)]; |
|
- if (message_send($eventdata)) { |
+ $message_sent = message_send($eventdata);
|
+ if ($message_sent === true) { |
+ $this->log_finish("Sending notification is disabled"); |
+ } else if ($message_sent > 0) { |
$this->log_finish("Notification successfully sent"); |
} else { |
$this->log_finish("Failed to send notification"); |
diff --git a/lib/messagelib.php b/lib/messagelib.php
|
index a79b78c0c95..729372c7cd7 100644 |
--- a/lib/messagelib.php
|
+++ b/lib/messagelib.php
|
@@ -53,7 +53,7 @@ require_once(__DIR__ . '/../message/lib.php'); |
*
|
* @category message |
* @param \core\message\message $eventdata information about the message (component, userfrom, userto, ...) |
- * @return mixed the integer ID of the new message or false if there was a problem (with submitted data or sending the message to the message processor) |
+ * @return mixed the integer ID of the new message or false if there was a problem (with submitted data or sending the message to the message processor) or true if notification is disabled |
*/
|
function message_send(\core\message\message $eventdata) {
|
global $CFG, $DB, $SITE;
|
@@ -67,6 +67,7 @@ function message_send(\core\message\message $eventdata) { |
|
// If the message provider is disabled via preferences, then don't send the message. |
if (!empty($defaultpreferences->{$preferencebase.'_disable'})) { |
+ $messageid = true; |
return $messageid; |
}
|
|
Now my patched code is logging one of:
- Notification successfully sent
- Failed to send notification
- Sending notification is disabled
- has a non-specific relationship to
-
MDL-72729 Disabling forum posts message provider causes related adhoc task to continually fail/requeue
- Open