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\logger;
|
|
|
28 |
use mod_bigbluebuttonbn\task\upgrade_recordings_task;
|
|
|
29 |
|
|
|
30 |
define('CLI_SCRIPT', true);
|
|
|
31 |
|
|
|
32 |
require(__DIR__ . '/../../../config.php');
|
|
|
33 |
global $CFG;
|
|
|
34 |
require_once($CFG->libdir . '/clilib.php');
|
|
|
35 |
|
|
|
36 |
// Now get cli options.
|
|
|
37 |
list($options, $unrecognized) = cli_get_params(
|
|
|
38 |
[
|
|
|
39 |
'help' => false,
|
|
|
40 |
'courseid' => 0,
|
|
|
41 |
'bigbluebuttonid' => 0,
|
|
|
42 |
'forcemigrate' => false
|
|
|
43 |
],
|
|
|
44 |
[
|
|
|
45 |
'h' => 'help',
|
|
|
46 |
'c' => 'courseid',
|
|
|
47 |
'b' => 'bigbluebuttoncmid',
|
|
|
48 |
'f' => 'forcemigrate'
|
|
|
49 |
]
|
|
|
50 |
);
|
|
|
51 |
|
|
|
52 |
if ($unrecognized) {
|
|
|
53 |
$unrecognized = implode("\n ", $unrecognized);
|
|
|
54 |
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if ($options['help']) {
|
|
|
58 |
$help =
|
|
|
59 |
"Execute / Rexecute migration for recordings.
|
|
|
60 |
Sometimes when the remote BigBlueButton server is temporarily not accessible and we upgrade to the new way of storing recordings
|
|
|
61 |
some activities end up without recordings. This script will allow to go through each meeting and fetch all recordings
|
|
|
62 |
that have not yet been fetched from the remote BigblueButton server.
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
Options:
|
|
|
66 |
-h, --help Print out this help
|
|
|
67 |
-c, --courseid Course identifier (id) in which we look for BigblueButton activities and recordings. If not specified
|
|
|
68 |
we check every single BigblueButton activity.
|
|
|
69 |
-b, --bigbluebuttoncmid Identifier for the bigbluebutton activity we would like to specifically retrieve recordings for. If not
|
|
|
70 |
specified we check every single BigblueButton activity
|
|
|
71 |
(scoped or not to a course depending on -c option).
|
|
|
72 |
-f,--forcemigrate Force the 'remigration' of recordings, so even if a recording has been marked as migrated in the logs
|
|
|
73 |
we still fetch the data from the Bigbluebutton server.
|
|
|
74 |
Example:
|
|
|
75 |
\$ sudo -u www-data /usr/bin/php mod/bigbluebuttonbn/cli/migrate_recordings.php -c=4 -f=1
|
|
|
76 |
";
|
|
|
77 |
|
|
|
78 |
echo $help;
|
|
|
79 |
die;
|
|
|
80 |
}
|
|
|
81 |
global $DB;
|
|
|
82 |
|
|
|
83 |
$bbcms = [];
|
|
|
84 |
if (!empty($options['courseid'])) {
|
|
|
85 |
$courseid = $options['courseid'];
|
|
|
86 |
$modinfos = get_fast_modinfo($courseid)->get_instances_of('bigbluebuttonbn');
|
|
|
87 |
$bbcms = array_values($modinfos);
|
|
|
88 |
} else if (!empty($options['bigbluebuttoncmid'])) {
|
|
|
89 |
[$course, $bbcm] = get_course_and_cm_from_cmid($options['bigbluebuttoncmid']);
|
|
|
90 |
$bbcms = [$bbcm];
|
|
|
91 |
} else {
|
|
|
92 |
// All bigbluebutton activities.
|
|
|
93 |
foreach ($DB->get_fieldset_select('bigbluebuttonbn', 'id', '') as $bbid) {
|
|
|
94 |
[$course, $bbcm] = get_course_and_cm_from_instance($bbid, 'bigbluebuttonbn');
|
|
|
95 |
array_push($bbcms, $bbcm);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
foreach ($bbcms as $bbcm) {
|
|
|
99 |
$instance = instance::get_from_cmid($bbcm->id);
|
|
|
100 |
$adhoctask = new upgrade_recordings_task();
|
|
|
101 |
cli_writeln("Processing BigbluebButton {$instance->get_meeting_name()}(id:{$instance->get_instance_id()}),"
|
|
|
102 |
. " in course {$bbcm->get_course()->fullname}(id:{$bbcm->get_course()->id})....");
|
|
|
103 |
if ($options['forcemigrate']) {
|
|
|
104 |
// We set the value of the log back to the original value so it get evalated once again.
|
|
|
105 |
$DB->set_field('bigbluebuttonbn_logs', 'log', logger::EVENT_IMPORT,
|
|
|
106 |
[
|
|
|
107 |
'courseid' => $instance->get_course_id(),
|
|
|
108 |
'bigbluebuttonbnid' => $instance->get_instance_id(),
|
|
|
109 |
'log' => logger::EVENT_IMPORT_MIGRATED
|
|
|
110 |
]);
|
|
|
111 |
$DB->set_field('bigbluebuttonbn_logs', 'log', logger::EVENT_CREATE,
|
|
|
112 |
[
|
|
|
113 |
'courseid' => $instance->get_course_id(),
|
|
|
114 |
'bigbluebuttonbnid' => $instance->get_instance_id(),
|
|
|
115 |
'log' => logger::EVENT_CREATE_MIGRATED
|
|
|
116 |
]);
|
|
|
117 |
}
|
|
|
118 |
$meetingids = $DB->get_fieldset_sql(
|
|
|
119 |
'SELECT DISTINCT meetingid FROM {bigbluebuttonbn_logs} WHERE log = :createlog OR log = :importlog',
|
|
|
120 |
[
|
|
|
121 |
'importlog' => logger::EVENT_IMPORT,
|
|
|
122 |
'createlog' => logger::EVENT_CREATE
|
|
|
123 |
]
|
|
|
124 |
);
|
|
|
125 |
if (empty($meetingids)) {
|
|
|
126 |
cli_writeln("\t->No meetings logs found...");
|
|
|
127 |
}
|
|
|
128 |
foreach ($meetingids as $mid) {
|
|
|
129 |
cli_write("\t->Processing meeting ID {$mid} ...recordings");
|
|
|
130 |
$adhoctask->set_custom_data((object)
|
|
|
131 |
[
|
|
|
132 |
'meetingid' => $mid,
|
|
|
133 |
'isimported' => false
|
|
|
134 |
]);
|
|
|
135 |
$adhoctask->execute();
|
|
|
136 |
cli_writeln("...imported recordings....");
|
|
|
137 |
$adhoctask->set_custom_data((object)
|
|
|
138 |
[
|
|
|
139 |
'meetingid' => $mid,
|
|
|
140 |
'isimported' => true
|
|
|
141 |
]);
|
|
|
142 |
$adhoctask->execute();
|
|
|
143 |
}
|
|
|
144 |
}
|