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_communication\task;
|
|
|
18 |
|
|
|
19 |
use core\task\adhoc_task;
|
|
|
20 |
use core_communication\processor;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Class synchronise_provider_task to add a task to synchronise the provider and execute the task to action the synchronisation.
|
|
|
24 |
*
|
|
|
25 |
* @package core_communication
|
|
|
26 |
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class synchronise_provider_task extends adhoc_task {
|
|
|
30 |
|
|
|
31 |
public function execute() {
|
|
|
32 |
$data = $this->get_custom_data();
|
|
|
33 |
|
|
|
34 |
$communication = processor::load_by_id($data->id);
|
|
|
35 |
|
|
|
36 |
if ($communication === null) {
|
|
|
37 |
mtrace("Skipping provider sync because the instance does not exist");
|
|
|
38 |
return;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
// Sync room members for the instance.
|
|
|
42 |
$communication->get_sync_provider()->synchronise_room_members();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Queue the task for the next run.
|
|
|
47 |
*
|
|
|
48 |
* @param processor $communication The communication processor to perform the action on
|
|
|
49 |
*/
|
|
|
50 |
public static function queue(
|
|
|
51 |
processor $communication
|
|
|
52 |
): void {
|
|
|
53 |
|
|
|
54 |
// Add ad-hoc task to update the provider room.
|
|
|
55 |
$task = new self();
|
|
|
56 |
$task->set_custom_data([
|
|
|
57 |
'id' => $communication->get_id(),
|
|
|
58 |
]);
|
|
|
59 |
|
|
|
60 |
// Queue the task for the next run.
|
|
|
61 |
\core\task\manager::queue_adhoc_task($task);
|
|
|
62 |
}
|
|
|
63 |
}
|