Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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;
1441 ariadna 20
use core\url;
1 efrain 21
use core_user;
22
use stdClass;
23
 
24
/**
25
 * Hook listener callbacks for tasks in core
26
 *
27
 * @package    core
28
 * @category   task
29
 * @copyright  2024 Raquel Ortega <raquel.ortega@moodle.com>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class failed_task_callbacks {
33
 
34
    /**
35
     * Callback to send a notification when the max fail delay of a task has been reached.
36
     *
37
     * @param after_failed_task_max_delay $hook
38
     */
39
    public static function send_failed_task_max_delay_message(after_failed_task_max_delay $hook): void {
40
        $task = $hook->get_task();
41
 
42
        $admins = get_admins();
43
        foreach ($admins as $admin) {
1441 ariadna 44
            $tasklogslink = new url('/admin/tasklogs.php', ['filter' => get_class($task)]);
45
 
1 efrain 46
            $a = new stdClass();
47
            $a->firstname = $admin->firstname;
48
            $a->taskname = $task->get_name();
1441 ariadna 49
            $a->link = $tasklogslink->out(false);
1 efrain 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;
1441 ariadna 63
            $message->contexturl = $tasklogslink->out(false);
64
            $message->contexturlname = get_string('tasklogs', 'admin');
1 efrain 65
            // Actually send the message.
66
            message_send($message);
67
        }
68
    }
69
}