Proyectos de Subversion Moodle

Rev

| 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_communication\task;
18
 
19
use core\task\scheduled_task;
20
use core_communication\api;
21
use core_communication\processor;
22
 
23
/**
24
 * Class synchronise_providers to add a task to synchronise the providers and execute the task to action the synchronisation.
25
 *
26
 * @package    core_communication
27
 * @copyright  2023 Safat Shahin <safat.shahin@moodle.com>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class synchronise_providers_task extends scheduled_task {
31
 
32
    public function get_name() {
33
        return get_string('synchroniseproviders', 'core_communication');
34
    }
35
 
36
    public function execute() {
37
        // Communication is not enabled? nothing to do.
38
        if (!api::is_available()) {
39
            return;
40
        }
41
 
42
        global $DB;
43
        $communicationinstances = $DB->get_records(
44
            table: 'communication',
45
            conditions: ['active' => processor::PROVIDER_ACTIVE],
46
        );
47
 
48
        foreach ($communicationinstances as $communicationinstance) {
49
            $communication = \core_communication\api::load_by_instance(
50
                context: \context::instance_by_id($communicationinstance->contextid),
51
                component: $communicationinstance->component,
52
                instancetype: $communicationinstance->instancetype,
53
                instanceid: $communicationinstance->instanceid,
54
            );
55
            $processor = $communication->get_processor();
56
            if ($processor->supports_sync_provider_features()) {
57
                $communication->sync_provider();
58
            }
59
        }
60
    }
61
}