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 |
/**
|
|
|
18 |
* Recordings CLI Migration script.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_bigbluebuttonbn
|
|
|
21 |
* @copyright 2022 onwards, Blindside Networks Inc
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
* @author Laurent David (laurent [at] call-learning [dt] fr)
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
use mod_bigbluebuttonbn\instance;
|
|
|
27 |
use mod_bigbluebuttonbn\recording;
|
|
|
28 |
|
|
|
29 |
define('CLI_SCRIPT', true);
|
|
|
30 |
|
|
|
31 |
require(__DIR__ . '/../../../config.php');
|
|
|
32 |
global $CFG;
|
|
|
33 |
require_once($CFG->libdir . '/clilib.php');
|
|
|
34 |
|
|
|
35 |
// Now get cli options.
|
|
|
36 |
list($options, $unrecognized) = cli_get_params(
|
|
|
37 |
[
|
|
|
38 |
'help' => false,
|
|
|
39 |
'courseid' => 0,
|
|
|
40 |
'bigbluebuttonid' => 0,
|
|
|
41 |
'run' => false
|
|
|
42 |
],
|
|
|
43 |
[
|
|
|
44 |
'h' => 'help',
|
|
|
45 |
'c' => 'courseid',
|
|
|
46 |
'b' => 'bigbluebuttoncmid',
|
|
|
47 |
'r' => 'run'
|
|
|
48 |
]
|
|
|
49 |
);
|
|
|
50 |
|
|
|
51 |
if ($unrecognized) {
|
|
|
52 |
$unrecognized = implode("\n ", $unrecognized);
|
|
|
53 |
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
if ($options['help']) {
|
|
|
57 |
$help =
|
|
|
58 |
"Check for dismissed recording and see if they appear on the server.
|
|
|
59 |
Sometimes when the remote BigBlueButton server is temporarily not accessible it has been seen that the recordings
|
|
|
60 |
are set to 'dismissed' status. For now this is a workaround until we refactor slightly the recording API.
|
|
|
61 |
|
|
|
62 |
Options:
|
|
|
63 |
-h, --help Print out this help
|
|
|
64 |
-c, --courseid Course identifier (id) in which we look for BigBlueButton activities and recordings. If not specified
|
|
|
65 |
we check every single BigBlueButton activity.
|
|
|
66 |
-b, --bigbluebuttoncmid Identifier for the BigBlueButton activity we would like to specifically retrieve recordings for. If not
|
|
|
67 |
specified we check every single BigBlueButton activity
|
|
|
68 |
(scoped or not to a course depending on -c option).
|
|
|
69 |
-r,--run If false (default, just display information. By default we just display the information.
|
|
|
70 |
Example:
|
|
|
71 |
\$ sudo -u www-data /usr/bin/php mod/bigbluebuttonbn/cli/update_dismissed_recordings.php -c=4 -r=1
|
|
|
72 |
";
|
|
|
73 |
|
|
|
74 |
echo $help;
|
|
|
75 |
die;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
$bbcms = [];
|
|
|
79 |
if (!empty($options['courseid'])) {
|
|
|
80 |
$courseid = $options['courseid'];
|
|
|
81 |
$modinfos = get_fast_modinfo($courseid)->get_instances_of('bigbluebuttonbn');
|
|
|
82 |
$bbcms = array_values($modinfos);
|
|
|
83 |
} else if (!empty($options['bigbluebuttoncmid'])) {
|
|
|
84 |
[$course, $bbcm] = get_course_and_cm_from_cmid($options['bigbluebuttoncmid']);
|
|
|
85 |
$bbcms = [$bbcm];
|
|
|
86 |
} else {
|
|
|
87 |
// All bigbluebutton activities.
|
|
|
88 |
foreach ($DB->get_fieldset_select('bigbluebuttonbn', 'id', '') as $bbid) {
|
|
|
89 |
[$course, $bbcm] = get_course_and_cm_from_instance($bbid, 'bigbluebuttonbn');
|
|
|
90 |
array_push($bbcms, $bbcm);
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
foreach ($bbcms as $bbcm) {
|
|
|
94 |
$instance = instance::get_from_cmid($bbcm->id);
|
|
|
95 |
cli_writeln("Processing BigBlueButton {$instance->get_meeting_name()}(id:{$instance->get_instance_id()}),"
|
|
|
96 |
. " in course {$bbcm->get_course()->fullname}(id:{$bbcm->get_course()->id})....");
|
|
|
97 |
$recordings = recording::get_records(['status' => recording::RECORDING_STATUS_DISMISSED,
|
|
|
98 |
'bigbluebuttonbnid' => $instance->get_instance_id()]);
|
|
|
99 |
$recordingkeys = array_map(function($rec) {
|
|
|
100 |
return $rec->get('recordingid');
|
|
|
101 |
}, $recordings);
|
|
|
102 |
$recordingmeta = \mod_bigbluebuttonbn\local\proxy\recording_proxy::fetch_recordings($recordingkeys);
|
|
|
103 |
if (empty($recordings)) {
|
|
|
104 |
cli_writeln("\t->No recordings found ...");
|
|
|
105 |
} else {
|
|
|
106 |
foreach ($recordings as $recording) {
|
|
|
107 |
if (!empty($recordingmeta[$recording->get('recordingid')])) {
|
|
|
108 |
$recordingwithmeta = new recording(0, $recording->to_record(), $recordingmeta[$recording->get('recordingid')]);
|
|
|
109 |
cli_writeln("\t-> Recording data found for " . $recordingwithmeta->get('name') . ' ID:' .
|
|
|
110 |
$recordingwithmeta->get('recordingid'));
|
|
|
111 |
if ($options['run']) {
|
|
|
112 |
$recordingwithmeta->set('status', recording::RECORDING_STATUS_PROCESSED);
|
|
|
113 |
$recordingwithmeta->save();
|
|
|
114 |
cli_writeln("\t\t-> Metadata and status updated...");
|
|
|
115 |
}
|
|
|
116 |
} else {
|
|
|
117 |
cli_writeln("\t-> No recording data found for " . $recording->get('recordingid'));
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}
|