Skip to content

Commit

Permalink
Merge branch 'MDL-80289-403' of https://github.com/call-learning/moodle
Browse files Browse the repository at this point in the history
… into MOODLE_403_STABLE
  • Loading branch information
HuongNV13 committed Feb 1, 2024
2 parents ad243c9 + 5665add commit c093084
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mod/bigbluebuttonbn/classes/instance.php
Expand Up @@ -216,10 +216,20 @@ private static function get_instance_info_retriever(int $id, int $idtype = self:
* @return null|self
*/
public static function get_from_meetingid(string $meetingid): ?self {
global $DB;
// Here we try to manage cases where the meetingid was actually produced by the old plugin or we have actually
// changed the identifiers for the instance.
$matches = self::parse_meetingid($meetingid);
$existinginstanceid = $DB->get_field('bigbluebuttonbn', 'id', ['meetingid' => $matches['meetingid']]);
if (empty($existinginstanceid)) {
debugging("The meeting id with ID ($meetingid) was not found in the bigbluebuttonbn table", DEBUG_DEVELOPER);
$existinginstanceid = $matches['instanceid']; // We try to "guess" the meeting id from its instance id. We should
// not really do that as this changes simply if we move the course elsewhere.
debugging("Trying to get the instanceid from the meeting ID. This will soon be deprecated", DEBUG_DEVELOPER);
}
$instance = self::get_from_instanceid($existinginstanceid);

$instance = self::get_from_instanceid($matches['instanceid']);

// Check for the group if any.
if ($instance && array_key_exists('groupid', $matches)) {
$instance->set_group_id($matches['groupid']);
}
Expand Down
28 changes: 28 additions & 0 deletions mod/bigbluebuttonbn/tests/instance_test.php
Expand Up @@ -157,6 +157,34 @@ public function test_get_from_meetingid_group(): void {
$this->assertEquals($cm->id, $instance->get_cm_id());
}

/**
* Test getting Meeting ID from log as Log field (meetingid) is the full meeting id (with courseid, and bigbluebuttonid).
*
* @covers ::get_from_meetingid
*/
public function test_get_from_meetingid_from_log(): void {
global $DB;

$this->resetAfterTest();
[
'record' => $record,
'course' => $course,
'cm' => $cm,
] = $this->get_test_instance();
$instance = instance::get_from_cmid($cm->id);
$instance->set_group_id(1);
logger::log_meeting_joined_event($instance, 1);
$logs = $DB->get_records('bigbluebuttonbn_logs',
['courseid' => $course->id, 'bigbluebuttonbnid' => $instance->get_instance_id()], 'timecreated DESC');
$log = end($logs);
$retrievedinstance = instance::get_from_meetingid(
$log->meetingid
);

$this->assertEquals($cm->instance, $retrievedinstance->get_instance_id());
$this->assertEquals($cm->id, $retrievedinstance->get_cm_id());
}

/**
* Ensure that invalid meetingids throw an appropriate exception.
*
Expand Down
Expand Up @@ -124,6 +124,7 @@ public function test_upgrade_recordings_basic(): void {
foreach ($matchesarray as $matches) {
$this->expectOutputRegex('/' . implode('.*', $matches) . '/s');
}
$this->resetDebugging(); // We might have debugging message that are sent by get_from_meetingid and can ignore them.
}

/**
Expand Down Expand Up @@ -186,6 +187,7 @@ public function test_upgrade_recordings_imported_basic(): void {
foreach ($matchesarray as $matches) {
$this->expectOutputRegex('/' . implode('.*', $matches) . '/s');
}
$this->resetDebugging(); // We might have debugging message that are sent by get_from_meetingid and can ignore them.
}

/**
Expand Down

0 comments on commit c093084

Please sign in to comment.