diff --git a/mod/bigbluebuttonbn/classes/instance.php b/mod/bigbluebuttonbn/classes/instance.php index bac9b80859e..3bdfb8d43e7 100644 --- a/mod/bigbluebuttonbn/classes/instance.php +++ b/mod/bigbluebuttonbn/classes/instance.php @@ -193,10 +193,20 @@ EOF; * @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']); } diff --git a/mod/bigbluebuttonbn/tests/instance_test.php b/mod/bigbluebuttonbn/tests/instance_test.php index 8fe81cb2277..5163e13ebf0 100644 --- a/mod/bigbluebuttonbn/tests/instance_test.php +++ b/mod/bigbluebuttonbn/tests/instance_test.php @@ -157,6 +157,34 @@ class instance_test extends advanced_testcase { $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. * diff --git a/mod/bigbluebuttonbn/tests/task/upgrade_recordings_task_test.php b/mod/bigbluebuttonbn/tests/task/upgrade_recordings_task_test.php index 24abb24f6e0..82e652a9370 100644 --- a/mod/bigbluebuttonbn/tests/task/upgrade_recordings_task_test.php +++ b/mod/bigbluebuttonbn/tests/task/upgrade_recordings_task_test.php @@ -124,6 +124,7 @@ class upgrade_recordings_task_test extends advanced_testcase { 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. } /** @@ -186,6 +187,7 @@ class upgrade_recordings_task_test extends advanced_testcase { 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. } /**