first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,236 @@
<?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\message\message;
use core\task\adhoc_task;
use mod_bigbluebuttonbn\instance;
use moodle_exception;
use stdClass;
/**
* Class containing the abstract class for notification processes in BBB.
*
* @package mod_bigbluebuttonbn
* @copyright 2023 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class base_send_notification extends adhoc_task {
/** @var instance */
protected $instance = null;
/** @var object */
protected $coursecontact = null;
/**
* Execute the task.
*/
public function execute() {
$this->send_all_notifications();
}
/**
* Append additional elements of custom data
*
* @param array $newdata
*/
protected function append_custom_data(array $newdata): void {
if ($currentdata = (array) $this->get_custom_data()) {
$newdata = array_merge($currentdata, $newdata);
}
$this->set_custom_data($newdata);
}
/**
* Set the instanceid in the custom data.
*
* @param int $instanceid
*/
public function set_instance_id(int $instanceid): void {
$this->append_custom_data(['instanceid' => $instanceid]);
}
/**
* Get the bigbluebutton instance that this notification is for.
*
* @return instance|null null if the instance could not be loaded.
*/
protected function get_instance(): ?instance {
// This means the customdata is broken, and needs to be fixed.
if (empty($this->get_custom_data()->instanceid)) {
throw new \coding_exception("Task custom data was missing instanceid");
}
if ($this->instance === null) {
$this->instance = instance::get_from_instanceid($this->get_custom_data()->instanceid);
}
return $this->instance;
}
/**
* Get the preferred course contact for this notification.
*
* @return stdClass
*/
protected function get_course_contact(): stdClass {
global $DB;
if ($this->coursecontact === null) {
// Get course managers so they can be highlighted in the list.
$coursecontext = $this->get_instance()->get_course_context();
if ($managerroles = get_config('', 'coursecontact')) {
$coursecontactroles = explode(',', $managerroles);
foreach ($coursecontactroles as $roleid) {
$contacts = get_role_users($roleid, $coursecontext, true, 'u.id', 'u.id ASC');
foreach ($contacts as $contact) {
$this->coursecontact = $contact;
break;
}
}
}
if ($this->coursecontact === null) {
$this->coursecontact = \core_user::get_noreply_user();
}
}
return $this->coursecontact;
}
/**
* Get the list of recipients for the notification.
*
* @return stdClass[]
*/
protected function get_recipients(): array {
// Potential users should be active users only.
return get_enrolled_users(
$this->get_instance()->get_course_context(),
'mod/bigbluebuttonbn:view',
0,
'u.*',
null,
0,
0,
true
);
}
/**
* Get the HTML message content.
*
* @return string
*/
abstract protected function get_html_message(): string;
/**
* Get the plain text message content.
*
* @return string
*/
protected function get_message(): string {
return html_to_text($this->get_html_message());
}
/**
* Get the short summary message.
*
* @return string
*/
abstract protected function get_small_message(): string;
/**
* Get the preferred message format
*
* @return string
*/
protected function get_message_format(): string {
return FORMAT_HTML;
}
/**
* Get the notification type.
*
* @return string
*/
abstract protected function get_notification_type(): string;
/**
* Get the subject of the notification.
*
* @return string
*/
abstract protected function get_subject(): string;
/**
* Send all of the notifications
*/
protected function send_all_notifications(): void {
$instance = $this->get_instance();
// Cannot do anything without a valid instance.
if (empty($instance)) {
mtrace("Instance was empty, skipping");
return;
}
foreach ($this->get_recipients() as $recipient) {
try {
\core_user::require_active_user($recipient, true, true);
\core\cron::setup_user($recipient);
} catch (moodle_exception $e) {
// Skip sending.
continue;
}
$this->send_notification_to_current_user();
}
\core\cron::setup_user();
}
/**
* Send the notificiation to the current user.
*/
protected function send_notification_to_current_user(): void {
global $USER;
$instance = $this->get_instance();
$eventdata = new message();
$eventdata->courseid = $instance->get_course_id();
$eventdata->component = 'mod_bigbluebuttonbn';
$eventdata->name = $this->get_notification_type();
$eventdata->userfrom = $this->get_course_contact();
$eventdata->userto = $USER;
$eventdata->subject = $this->get_subject();
$eventdata->smallmessage = $this->get_small_message();
$eventdata->fullmessage = $this->get_message();
$eventdata->fullmessageformat = $this->get_message_format();
$eventdata->fullmessagehtml = $this->get_html_message();
$eventdata->notification = 1;
$eventdata->contexturl = $this->get_instance()->get_view_url();
$eventdata->contexturlname = $this->get_instance()->get_meeting_name();
message_send($eventdata);
}
}
@@ -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');
}
}
@@ -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 recordings from the server.
*
* @package mod_bigbluebuttonbn
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class check_pending_recordings extends scheduled_task {
/**
* Run the migration task.
*/
public function execute() {
recording::sync_pending_recordings_from_server();
}
/**
* Get the name of the task for use in the interface.
*
* @return string
*/
public function get_name(): string {
return get_string('taskname:check_pending_recordings', 'mod_bigbluebuttonbn');
}
}
@@ -0,0 +1,60 @@
<?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\adhoc_task;
use core_user;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
/**
* Class containing the scheduled task for updating the completion state.
*
* @package mod_bigbluebuttonbn
* @copyright 2019 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class completion_update_state extends adhoc_task {
/**
* Run bigbluebuttonbn cron.
*/
public function execute() {
// Get the custom data.
$data = $this->get_custom_data();
// Ensure the customdata structure is corect.
if (empty($data->bigbluebuttonbn->id) || empty($data->userid)) {
throw new \coding_exception("Task customdata was missing bigbluebuttonbn->id or userid");
}
// If coursemodule does not exist, ignore (likely has been deleted).
if (get_coursemodule_from_instance('bigbluebuttonbn', $data->bigbluebuttonbn->id) === false) {
mtrace("Course module does not exist, ignoring.");
return;
}
// If user does not exist, ignore (likely has been deleted).
if (core_user::get_user($data->userid) === false) {
mtrace("User does not exist, ignoring.");
return;
}
mtrace("Task completion_update_state running for user {$data->userid}");
// Process the completion.
bigbluebutton_proxy::update_completion_state($data->bigbluebuttonbn, $data->userid);
}
}
@@ -0,0 +1,96 @@
<?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\adhoc_task;
use mod_bigbluebuttonbn\recording;
/**
* Class containing the scheduled task for converting recordings for the BigBlueButton version 2.5 in Moodle 4.0.
*
* @package mod_bigbluebuttonbn
* @copyright 2021 Jesus Federico, Blindside Networks Inc <jesus at blindsidenetworks dot com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class reset_recordings extends adhoc_task {
/** @var int Chunk size to use when resetting recordings */
protected static $chunksize = 100;
/**
* Run the migration task.
*/
public function execute() {
if ($this->process_reset_recordings()) {
\core\task\manager::queue_adhoc_task(new static());
}
}
/**
* Process all bigbluebuttonbn_recordings looking for entries which should be reset to be fetched again.
*
* @return bool Whether any more recodgins are waiting to be processed
*/
protected function process_reset_recordings(): bool {
global $DB;
$classname = static::class;
mtrace("Executing {$classname}...");
// Read a block of recordings to be updated.
$recs = $this->get_recordngs_to_reset();
if (empty($recs)) {
mtrace("No recordings were found for reset...");
// No more logs. Stop queueing.
return false;
}
// Reset status of {chunksize} recordings.
mtrace("Reset status of " . self::$chunksize . " recordings...");
$sql = "UPDATE {bigbluebuttonbn_recordings}
SET status = :status_reset
WHERE id = " . implode(' OR id = ', array_keys($recs));
$DB->execute($sql,
['status_reset' => recording::RECORDING_STATUS_RESET]
);
return true;
}
/**
* Get the list of recordings to be reset.
*
* @return array
*/
protected function get_recordngs_to_reset(): array {
global $DB;
return $DB->get_records_sql(
'SELECT * FROM {bigbluebuttonbn_recordings}
WHERE status = :status_processed OR status = :status_notified
ORDER BY timecreated DESC', [
'status_processed' => recording::RECORDING_STATUS_PROCESSED,
'status_notified' => recording::RECORDING_STATUS_NOTIFIED
],
0,
self::$chunksize
);
}
}
@@ -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/>.
declare(strict_types=1);
namespace mod_bigbluebuttonbn\task;
use core\task\adhoc_task;
use core\message\message;
use mod_bigbluebuttonbn\local\config;
/**
* Deprecated Ad-hoc task to send a notification related to the disabling of the BigBlueButton activity module.
*
* The ad-hoc tasks sends a notification to the administrator informing that the BigBlueButton activity module has
* been disabled and they are required to confirm their acceptance of the data processing agreement prior to
* re-enabling it.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_bigbluebutton_module_disabled_notification extends adhoc_task {
/**
* Execute the task.
*/
public function execute() {
// Log the debug message.
$message = "Attempted to run deprecated send_bigbluebutton_module_disabled_notification task.";
debugging($message, DEBUG_DEVELOPER);
}
}
@@ -0,0 +1,109 @@
<?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_user;
use html_writer;
/**
* This adhoc task will send emails to guest users with the meeting's details
*
* @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)
*/
class send_guest_emails extends base_send_notification {
/**
* Get the notification type.
*
* @return string
*/
protected function get_notification_type(): string {
return 'guest_invited';
}
/**
* Send all the emails
*/
protected function send_all_notifications(): void {
$customdata = $this->get_custom_data();
if (!empty($customdata->emails)) {
foreach ($customdata->emails as $email) {
$user = core_user::get_noreply_user();
$user->email = $email;
$user->mailformat = 1; // HTML format.
email_to_user(
$user,
core_user::get_noreply_user(),
$this->get_subject(),
$this->get_small_message(),
$this->get_html_message()
);
}
}
}
/**
* Get the subject of the notification.
*
* @return string
*/
protected function get_subject(): string {
return get_string('guest_invitation_subject', 'mod_bigbluebuttonbn', $this->get_string_vars());
}
/**
* Get variables to make available to strings.
*
* @return array
*/
protected function get_string_vars(): array {
$customdata = $this->get_custom_data();
$sender = core_user::get_user($customdata->useridfrom);
return [
'course_fullname' => $this->get_instance()->get_course()->fullname,
'course_shortname' => $this->get_instance()->get_course()->shortname,
'name' => $this->get_instance()->get_cm()->name,
'guestjoinurl' => $this->get_instance()->get_guest_access_url()->out(false),
'guestpassword' => $this->get_instance()->get_guest_access_password(),
'sender' => fullname($sender)
];
}
/**
* Get the short summary message.
*
* @return string
*/
protected function get_small_message(): string {
return get_string('guest_invitation_small_message', 'mod_bigbluebuttonbn', $this->get_string_vars());
}
/**
* Get the HTML message content.
*
* @return string
*/
protected function get_html_message(): string {
return html_writer::tag(
'p',
get_string('guest_invitation_full_message', 'mod_bigbluebuttonbn', $this->get_string_vars())
);
}
}
@@ -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\adhoc_task;
/**
* Class containing the deprecated class for send_notification event in BBB.
*
* @package mod_bigbluebuttonbn
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_notification extends adhoc_task {
/**
* Execute the task.
*/
public function execute() {
// Log the debug message.
$message = $this->generate_message();
debugging($message, DEBUG_DEVELOPER);
}
/**
* Output the debug log message.
*
* @return string The debug log message.
*/
public function generate_message() {
return "Attempted to run deprecated implementation of send_notification task.";
}
}
@@ -0,0 +1,83 @@
<?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 html_writer;
/**
* Class containing the adhoc task to send a recording ready notification.
*
* @package mod_bigbluebuttonbn
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_recording_ready_notification extends base_send_notification {
/**
* Get the notification type.
*
* @return string
*/
protected function get_notification_type(): string {
return 'recording_ready';
}
/**
* Get the subject of the notification.
*
* @return string
*/
protected function get_subject(): string {
$instance = $this->get_instance();
return get_string('notification_recording_ready_subject', 'mod_bigbluebuttonbn', $this->get_string_vars());
}
/**
* Get the short summary message.
*
* @return string
*/
protected function get_small_message(): string {
return get_string('notification_recording_ready_small', 'mod_bigbluebuttonbn', $this->get_string_vars());
}
/**
* Get the HTML message content.
*
* @return string
*/
protected function get_html_message(): string {
return html_writer::tag(
'p',
get_string('notification_recording_ready_html', 'mod_bigbluebuttonbn', $this->get_string_vars())
);
}
/**
* Get variables to make available to strings.
*
* @return array
*/
protected function get_string_vars(): array {
return [
'course_fullname' => $this->instance->get_course()->fullname,
'course_shortname' => $this->instance->get_course()->shortname,
'name' => $this->instance->get_cm()->name,
'link' => $this->instance->get_view_url()->out(),
];
}
}
@@ -0,0 +1,203 @@
<?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\adhoc_task;
use core\task\manager;
use Matrix\Exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\recording_proxy;
use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\recording;
use moodle_exception;
/**
* Class containing the scheduled task for converting recordings for the BigBlueButton version 2.5 in Moodle 4.0.
*
* @package mod_bigbluebuttonbn
* @copyright 2021 Jesus Federico, Blindside Networks Inc <jesus at blindsidenetworks dot com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class upgrade_recordings_task extends adhoc_task {
/**
* Run the migration task.
*/
public function execute() {
$info = $this->get_custom_data();
$meetingid = $info->meetingid;
$isimported = $info->isimported ?? 0;
$this->process_bigbluebuttonbn_logs($meetingid, $isimported);
}
/**
* Process all bigbluebuttonbn logs looking for entries which should be converted to meetings.
*
* @param string $meetingid
* @param bool $isimported
* @return bool Whether any more logs are waiting to be processed
* @throws \dml_exception
* @throws moodle_exception
*/
protected function process_bigbluebuttonbn_logs(string $meetingid, bool $isimported): bool {
global $DB;
$classname = static::class;
mtrace("Executing {$classname} for meeting {$meetingid}...");
// Fetch the logs queued for upgrade.
mtrace("Fetching logs for conversion");
// Each log is ordered by timecreated.
[$select, $params] = $this->get_sql_query_for_logs($meetingid, $isimported);
$logsrs = $DB->get_recordset_select('bigbluebuttonbn_logs',
$select,
$params,
'timecreated DESC',
'id, meetingid, timecreated, log');
if (!$logsrs->valid()) {
mtrace("No logs were found for conversion.");
// No more logs. Stop queueing.
return false;
}
// Retrieve recordings from the servers for this meeting.
$recordings = recording_proxy::fetch_recording_by_meeting_id([$meetingid]);
// Sort recordings by meetingId, then startTime.
uasort($recordings, function($a, $b) {
return $b['startTime'] - $a['startTime'];
});
// Create an instance of bigbluebuttonbn_recording per valid recording.
mtrace("Creating new recording records...");
$recordingcount = 0;
foreach ($recordings as $recordingid => $recording) {
$importeddata = $isimported ? '' : json_encode($recording);
try {
$instance = instance::get_from_meetingid($recording['meetingID']);
} catch (Exception $e) {
mtrace("Unable to parse meetingID " . $e->getMessage());
continue;
}
if ($instance) {
$newrecording = [
'courseid' => $instance->get_course_id(),
'bigbluebuttonbnid' => $instance->get_instance_id(),
'groupid' => $instance->get_group_id(), // The groupid should be taken from the meetingID.
'recordingid' => $recordingid,
'status' => recording::RECORDING_STATUS_PROCESSED,
];
} else {
mtrace("Unable to find an activity for {$recording['meetingID']}. This recording is headless.");
// This instance does not exist any more.
// Use the data in the log instead of the instance.
$meetingdata = instance::parse_meetingid($recording['meetingID']);
$newrecording = [
'courseid' => $meetingdata['courseid'],
'bigbluebuttonbnid' => $meetingdata['instanceid'],
'groupid' => 0,
'recordingid' => $recordingid,
'status' => recording::RECORDING_STATUS_PROCESSED,
];
if (array_key_exists('groupid', $meetingdata)) {
$newrecording['groupid'] = $meetingdata['groupid'];
}
}
if ($DB->record_exists('bigbluebuttonbn_recordings', $newrecording)) {
mtrace("A recording already exists for {$recording['recordID']}. Skipping.");
// A recording matching these characteristics alreay exists.
continue;
}
// Recording has not been imported, check if we still have more logs.
// We try to guess which logs matches which recordings are they are classed in the same order.
// But this is just an attempt.
$log = null;
if ($logsrs->valid()) {
$log = $logsrs->current();
$logsrs->next();
}
$timecreated = empty($log) ? time() : $log->timecreated;
$newrecording['imported'] = $isimported;
$newrecording['headless'] = 0;
$newrecording['importeddata'] = $importeddata;
$newrecording['timecreated'] = $newrecording['timemodified'] = $timecreated;
// If we could not match with a log, we still create the recording.
$DB->insert_record('bigbluebuttonbn_recordings', $newrecording);
$recordingcount++;
}
mtrace("Migrated {$recordingcount} recordings.");
// Now deactivate logs by marking all of them as migrated.
// Reason for this is that we don't want to run another migration here and we don't know
// which logs matches which recordings.
$DB->set_field_select('bigbluebuttonbn_logs', 'log',
$isimported ? logger::EVENT_IMPORT_MIGRATED : logger::EVENT_CREATE_MIGRATED,
$select,
$params
);
$logsrs->close();
return true;
}
/**
* Get the query (records_select) for the logs to convert.
*
* Each log is ordered by timecreated.
*
* @param string $meetingid
* @param bool $isimported
* @return array
*/
protected function get_sql_query_for_logs(string $meetingid, bool $isimported): array {
global $DB;
if ($isimported) {
return [
'log = :logmatch AND meetingid = :meetingid',
['logmatch' => logger::EVENT_IMPORT, 'meetingid' => $meetingid],
];
}
return [
'log = :logmatch AND meetingid = :meetingid AND ' . $DB->sql_like('meta', ':match'),
[
'logmatch' => logger::EVENT_CREATE,
'match' => '%true%',
'meetingid' => $meetingid
],
];
}
/**
* Schedule all upgrading tasks.
*
* @param bool $importedrecordings
* @return void
* @throws \dml_exception
*/
public static function schedule_upgrade_per_meeting($importedrecordings = false) {
global $DB;
$meetingids = $DB->get_fieldset_sql(
'SELECT DISTINCT meetingid FROM {bigbluebuttonbn_logs} WHERE log = :createorimport',
['createorimport' => $importedrecordings ? logger::EVENT_IMPORT : logger::EVENT_CREATE]
);
foreach ($meetingids as $mid) {
$createdrecordingtask = new static();
$createdrecordingtask->set_custom_data((object) ['meetingid' => $mid, 'isimported' => $importedrecordings]);
manager::queue_adhoc_task($createdrecordingtask);
}
}
}