1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the Zoom plugin for 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 |
/**
|
|
|
18 |
* The task for deleting recordings in Moodle if removed from Zoom.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_zoom
|
|
|
21 |
* @author Jwalit Shah <jwalitshah@catalyst-au.net>
|
|
|
22 |
* @copyright 2021 Jwalit Shah <jwalitshah@catalyst-au.net>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_zoom\task;
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die();
|
|
|
29 |
|
|
|
30 |
require_once($CFG->dirroot . '/mod/zoom/locallib.php');
|
|
|
31 |
|
|
|
32 |
use core\task\scheduled_task;
|
|
|
33 |
use moodle_exception;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Scheduled task to delete meeting recordings from Moodle.
|
|
|
37 |
*/
|
|
|
38 |
class delete_meeting_recordings extends scheduled_task {
|
|
|
39 |
/**
|
|
|
40 |
* Returns name of task.
|
|
|
41 |
*
|
|
|
42 |
* @return string
|
|
|
43 |
*/
|
|
|
44 |
public function get_name() {
|
|
|
45 |
return get_string('deletemeetingrecordings', 'mod_zoom');
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Delete any recordings that have been removed from zoom.
|
|
|
50 |
*
|
|
|
51 |
* @return void
|
|
|
52 |
*/
|
|
|
53 |
public function execute() {
|
|
|
54 |
global $DB;
|
|
|
55 |
|
|
|
56 |
try {
|
|
|
57 |
$service = zoom_webservice();
|
|
|
58 |
} catch (moodle_exception $exception) {
|
|
|
59 |
mtrace('Skipping task - ', $exception->getMessage());
|
|
|
60 |
return;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// See if we cannot make anymore API calls.
|
|
|
64 |
$retryafter = get_config('zoom', 'retry-after');
|
|
|
65 |
if (!empty($retryafter) && time() < $retryafter) {
|
|
|
66 |
mtrace('Out of API calls, retry after ' . userdate($retryafter, get_string('strftimedaydatetime', 'core_langconfig')));
|
|
|
67 |
return;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
mtrace('Checking if any meeting recordings in Moodle have been removed from Zoom...');
|
|
|
71 |
|
|
|
72 |
// Get all recordings stored in Moodle, grouped by meetinguuid.
|
|
|
73 |
$zoomrecordings = zoom_get_meeting_recordings_grouped();
|
|
|
74 |
foreach ($zoomrecordings as $meetinguuid => $recordings) {
|
|
|
75 |
// Now check which recordings still exist on Zoom.
|
|
|
76 |
$recordinglist = $service->get_recording_url_list($meetinguuid);
|
|
|
77 |
foreach ($recordinglist as $recordinginfo) {
|
|
|
78 |
$zoomrecordingid = trim($recordinginfo->recordingid);
|
|
|
79 |
if (isset($recordings[$zoomrecordingid])) {
|
|
|
80 |
mtrace('Recording id: ' . $zoomrecordingid . ' exist(s)...skipping');
|
|
|
81 |
unset($recordings[$zoomrecordingid]);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
// If recordings are in Moodle but not in Zoom, we need to remove them from Moodle as well.
|
|
|
86 |
foreach ($recordings as $zoomrecordingid => $recording) {
|
|
|
87 |
mtrace('Deleting recording with id: ' . $zoomrecordingid . ' as corresponding record on zoom has been removed.');
|
|
|
88 |
$DB->delete_records('zoom_meeting_recordings', ['zoomrecordingid' => $zoomrecordingid]);
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|