1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core\task;
|
|
|
18 |
|
|
|
19 |
use core\hook\task\after_failed_task_max_delay;
|
|
|
20 |
use core_user;
|
|
|
21 |
use stdClass;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Hook listener callbacks for tasks in core
|
|
|
25 |
*
|
|
|
26 |
* @package core
|
|
|
27 |
* @category task
|
|
|
28 |
* @copyright 2024 Raquel Ortega <raquel.ortega@moodle.com>
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class failed_task_callbacks {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Callback to send a notification when the max fail delay of a task has been reached.
|
|
|
35 |
*
|
|
|
36 |
* @param after_failed_task_max_delay $hook
|
|
|
37 |
*/
|
|
|
38 |
public static function send_failed_task_max_delay_message(after_failed_task_max_delay $hook): void {
|
|
|
39 |
$task = $hook->get_task();
|
|
|
40 |
|
|
|
41 |
$admins = get_admins();
|
|
|
42 |
if (empty($admins)) {
|
|
|
43 |
return;
|
|
|
44 |
}
|
|
|
45 |
foreach ($admins as $admin) {
|
|
|
46 |
$a = new stdClass();
|
|
|
47 |
$a->firstname = $admin->firstname;
|
|
|
48 |
$a->taskname = $task->get_name();
|
|
|
49 |
$a->link = new \moodle_url('/report/status/index.php', ['detail' => 'tool_task_maxfaildelay']);
|
|
|
50 |
$messagetxt = get_string('failedtaskbody', 'moodle', $a);
|
|
|
51 |
// Create message.
|
|
|
52 |
$message = new \core\message\message();
|
|
|
53 |
$message->component = 'moodle';
|
|
|
54 |
$message->name = 'failedtaskmaxdelay';
|
|
|
55 |
$message->userfrom = core_user::get_noreply_user();
|
|
|
56 |
$message->userto = $admin;
|
|
|
57 |
$message->subject = get_string('failedtasksubject', 'moodle', $task->get_name());
|
|
|
58 |
$message->fullmessage = html_to_text($messagetxt);
|
|
|
59 |
$message->fullmessageformat = FORMAT_MARKDOWN;
|
|
|
60 |
$message->fullmessagehtml = text_to_html($messagetxt);
|
|
|
61 |
$message->smallmessage = get_string('failedtasksubject', 'moodle', $task->get_name());
|
|
|
62 |
$message->notification = 1;
|
|
|
63 |
$message->contexturl = (
|
|
|
64 |
new \moodle_url('/report/status/index.php', ['detail' => 'tool_task_maxfaildelay']))->out(false);
|
|
|
65 |
$message->contexturlname = get_string('failedtaskcontexturlname', 'moodle');
|
|
|
66 |
// Actually send the message.
|
|
|
67 |
message_send($message);
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
}
|