MDL-76339 mod_bigbluebuttonbn: Update dismissed recordings

* When the server is not reachable (or recordings are not reacheable)
the recording is set to RECORDING_STATUS_DISMISSED and is then
not visible in the list.
* Add a CLI script to solve potential issue with DISMISSED recordings
This commit is contained in:
Laurent David 2022-11-16 21:17:14 +01:00
parent f49f934786
commit a00d72c622
7 changed files with 318 additions and 10 deletions

View File

@ -17,6 +17,7 @@
namespace mod_bigbluebuttonbn;
use cache;
use context;
use context_course;
use context_module;
use core\persistent;
@ -772,25 +773,35 @@ class recording extends persistent {
* Synchronise pending recordings from the server.
*
* This function should be called by the check_pending_recordings scheduled task.
*
* @param bool $dismissedonly fetch dismissed recording only
*/
public static function sync_pending_recordings_from_server(): void {
public static function sync_pending_recordings_from_server(bool $dismissedonly = false): void {
global $DB;
$params = [
'withindays' => time() - (self::RECORDING_TIME_LIMIT_DAYS * DAYSECS),
];
// Fetch the local data.
mtrace("=> Looking for any recording awaiting processing from the past " . self::RECORDING_TIME_LIMIT_DAYS . " days.");
$select = 'status = :status_awaiting AND timecreated > :withindays OR status = :status_reset';
$recordings = $DB->get_records_select(static::TABLE, $select, [
'status_awaiting' => self::RECORDING_STATUS_AWAITING,
'withindays' => time() - (self::RECORDING_TIME_LIMIT_DAYS * DAYSECS),
'status_reset' => self::RECORDING_STATUS_RESET,
], self::DEFAULT_RECORDING_SORT);
if ($dismissedonly) {
mtrace("=> Looking for any recording that has been 'dismissed' in the past " . self::RECORDING_TIME_LIMIT_DAYS
. " days.");
$select = 'status = :status_dismissed AND timecreated > :withindays';
$params['status_dismissed'] = self::RECORDING_STATUS_DISMISSED;
} else {
mtrace("=> Looking for any recording awaiting processing from the past " . self::RECORDING_TIME_LIMIT_DAYS . " days.");
$select = '(status = :status_awaiting AND timecreated > :withindays) OR status = :status_reset';
$params['status_reset'] = self::RECORDING_STATUS_RESET;
$params['status_awaiting'] = self::RECORDING_STATUS_AWAITING;
}
$recordings = $DB->get_records_select(static::TABLE, $select, $params, self::DEFAULT_RECORDING_SORT);
// Sort by DEFAULT_RECORDING_SORT we get the same result on different db engines.
$recordingcount = count($recordings);
mtrace("=> Found {$recordingcount} recordings to query");
// Grab the recording IDs.
$recordingids = array_map(function ($recording) {
$recordingids = array_map(function($recording) {
return $recording->recordingid;
}, $recordings);

View File

@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_bigbluebuttonbn\task;
use core\task\scheduled_task;
use mod_bigbluebuttonbn\recording;
/**
* Synchronise pending and dismissed recordings from the server.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 Laurent David Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class check_dismissed_recordings extends scheduled_task {
/**
* Run the migration task.
*/
public function execute() {
recording::sync_pending_recordings_from_server(true);
}
/**
* Get the name of the task for use in the interface.
*
* @return string
*/
public function get_name(): string {
return get_string('taskname:check_dismissed_recordings', 'mod_bigbluebuttonbn');
}
}

View File

@ -0,0 +1,121 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Recordings CLI Migration script.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent [at] call-learning [dt] fr)
*/
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\recording;
define('CLI_SCRIPT', true);
require(__DIR__ . '/../../../config.php');
global $CFG;
require_once($CFG->libdir . '/clilib.php');
// Now get cli options.
list($options, $unrecognized) = cli_get_params(
[
'help' => false,
'courseid' => 0,
'bigbluebuttonid' => 0,
'run' => false
],
[
'h' => 'help',
'c' => 'courseid',
'b' => 'bigbluebuttoncmid',
'r' => 'run'
]
);
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
if ($options['help']) {
$help =
"Check for dismissed recording and see if they appear on the server.
Sometimes when the remote BigBlueButton server is temporarily not accessible it has been seen that the recordings
are set to 'dismissed' status. For now this is a workaround until we refactor slightly the recording API.
Options:
-h, --help Print out this help
-c, --courseid Course identifier (id) in which we look for BigBlueButton activities and recordings. If not specified
we check every single BigBlueButton activity.
-b, --bigbluebuttoncmid Identifier for the BigBlueButton activity we would like to specifically retrieve recordings for. If not
specified we check every single BigBlueButton activity
(scoped or not to a course depending on -c option).
-r,--run If false (default, just display information. By default we just display the information.
Example:
\$ sudo -u www-data /usr/bin/php mod/bigbluebuttonbn/cli/update_dismissed_recordings.php -c=4 -r=1
";
echo $help;
die;
}
$bbcms = [];
if (!empty($options['courseid'])) {
$courseid = $options['courseid'];
$modinfos = get_fast_modinfo($courseid)->get_instances_of('bigbluebuttonbn');
$bbcms = array_values($modinfos);
} else if (!empty($options['bigbluebuttoncmid'])) {
[$course, $bbcm] = get_course_and_cm_from_cmid($options['bigbluebuttoncmid']);
$bbcms = [$bbcm];
} else {
// All bigbluebutton activities.
foreach ($DB->get_fieldset_select('bigbluebuttonbn', 'id', '') as $bbid) {
[$course, $bbcm] = get_course_and_cm_from_instance($bbid, 'bigbluebuttonbn');
array_push($bbcms, $bbcm);
}
}
foreach ($bbcms as $bbcm) {
$instance = instance::get_from_cmid($bbcm->id);
cli_writeln("Processing BigBlueButton {$instance->get_meeting_name()}(id:{$instance->get_instance_id()}),"
. " in course {$bbcm->get_course()->fullname}(id:{$bbcm->get_course()->id})....");
$recordings = recording::get_records(['status' => recording::RECORDING_STATUS_DISMISSED,
'bigbluebuttonbnid' => $instance->get_instance_id()]);
$recordingkeys = array_map(function($rec) {
return $rec->get('recordingid');
}, $recordings);
$recordingmeta = \mod_bigbluebuttonbn\local\proxy\recording_proxy::fetch_recordings($recordingkeys);
if (empty($recordings)) {
cli_writeln("\t->No recordings found ...");
} else {
foreach ($recordings as $recording) {
if (!empty($recordingmeta[$recording->get('recordingid')])) {
$recordingwithmeta = new recording(0, $recording->to_record(), $recordingmeta[$recording->get('recordingid')]);
cli_writeln("\t-> Recording data found for " . $recordingwithmeta->get('name') . ' ID:' .
$recordingwithmeta->get('recordingid'));
if ($options['run']) {
$recordingwithmeta->set('status', recording::RECORDING_STATUS_PROCESSED);
$recordingwithmeta->save();
cli_writeln("\t\t-> Metadata and status updated...");
}
} else {
cli_writeln("\t-> No recording data found for " . $recording->get('recordingid'));
}
}
}
}

View File

@ -34,4 +34,13 @@ $tasks = [
'month' => '*',
'dayofweek' => '*'
],
[
'classname' => 'mod_bigbluebuttonbn\task\check_dismissed_recordings',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*/10', // Every 10 days.
'month' => '*',
'dayofweek' => '*'
],
];

View File

@ -643,6 +643,7 @@ $string['cachedef_serverinfo'] = 'Remote server information';
$string['cachedef_recordings'] = 'Recording metadata';
$string['cachedef_validatedurls'] = 'Cache of validated URL checks';
$string['taskname:check_pending_recordings'] = 'Fetch pending recordings';
$string['taskname:check_dismissed_recordings'] = 'Check for recordings that have not yet been found.';
$string['userlimitreached'] = 'The number of users allowed in a session has been reached.';
$string['waitformoderator'] = 'Waiting for a moderator to join.';

View File

@ -0,0 +1,117 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_bigbluebuttonbn\task;
use advanced_testcase;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\recording;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* Test class for the check_pending_recordings and check_dismissed_recordings task
*
* @package mod_bigbluebuttonbn
* @copyright 2022 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \mod_bigbluebuttonbn\task\check_dismissed_recordings
* @covers \mod_bigbluebuttonbn\task\check_pending_recordings
* @covers \mod_bigbluebuttonbn\recording::sync_pending_recordings_from_server
*/
class check_recordings_task_test extends advanced_testcase {
use testcase_helper_trait;
/**
* @var $RECORDINGS_DATA array fake recording data.
*/
const RECORDINGS_DATA = [
['name' => 'Recording 1'],
['name' => 'Recording 2'],
['name' => 'Recording 3'],
['name' => 'Recording 4'],
];
/**
* Setup for test
*/
public function setUp(): void {
parent::setUp();
$this->initialise_mock_server();
$this->resetAfterTest();
}
/**
* Test that dismissed recordings are retrieved
*/
public function test_check_dismissed_recordings(): void {
$this->create_meeting_and_recordings(recording::RECORDING_STATUS_DISMISSED);
$this->assertEquals(4, recording::count_records());
$this->assertEquals(0, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
$task = new check_dismissed_recordings();
ob_start();
$task->execute();
ob_end_clean();
$this->assertEquals(4, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
}
/**
* Test that pending recordings are retrieved
*/
public function test_check_pending_recordings(): void {
$this->create_meeting_and_recordings();
$this->assertEquals(4, recording::count_records());
$this->assertEquals(0, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
$task = new check_pending_recordings();
ob_start();
$task->execute();
ob_end_clean();
$this->assertEquals(4, recording::count_records(['status' => recording::RECORDING_STATUS_PROCESSED]));
}
/**
* Create sample meeting and recording.
*
* @param int $status status for the newly created recordings
* @return array recording data (not the persistent class but plain object)
*/
private function create_meeting_and_recordings(int $status = recording::RECORDING_STATUS_AWAITING): array {
$generator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
$course = $this->getDataGenerator()->create_course();
$activity = $generator->create_instance([
'course' => $course->id,
'type' => instance::TYPE_ALL
]);
$instance = instance::get_from_instanceid($activity->id);
$generator->create_meeting([
'instanceid' => $instance->get_instance_id(),
'groupid' => $instance->get_group_id()
]);
foreach (self::RECORDINGS_DATA as $data) {
$rdata = $generator->create_recording(
array_merge([
'bigbluebuttonbnid' => $instance->get_instance_id(),
'groupid' => $instance->get_group_id()
], $data)
);
$recording = new recording($rdata->id);
$recording->set('status', $status);
$recording->save();
$recordings[] = $rdata;
}
return $recordings;
}
}

View File

@ -1,5 +1,9 @@
This files describes API changes in the bigbluebuttonbn code.
=== 4.1.2 ===
* Add a new parameter for mod_bigbluebuttonbn\recording::sync_pending_recordings_from_server so sync only 'dismissed' recordings
(This was fixed in 4.2, 4.1.2 and 4.0.7).
=== 4.1 ===
* External function mod_bigbluebuttonbn\external\meeting_info now return the list of the instance features and whether they are
enabled or not.