From 5a3aa8bb75453b33ea3795bffa996ec5f9079c50 Mon Sep 17 00:00:00 2001 From: "Shamiso.Jaravaza" <33659194+ssj365@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:04:55 -0600 Subject: [PATCH] CONTRIB-9708: Fix dupe meetingid * Fix meetingid duplication during Course import process --- .../restore_bigbluebuttonbn_stepslib.php | 5 ++ tests/backup_restore_test.php | 54 ++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/backup/moodle2/restore_bigbluebuttonbn_stepslib.php b/backup/moodle2/restore_bigbluebuttonbn_stepslib.php index 4411f7e2f..346ed8421 100644 --- a/backup/moodle2/restore_bigbluebuttonbn_stepslib.php +++ b/backup/moodle2/restore_bigbluebuttonbn_stepslib.php @@ -57,6 +57,11 @@ protected function process_bigbluebuttonbn(array $data) { $data = (object) $data; $data->course = $this->get_courseid(); $data->timemodified = $this->apply_date_offset($data->timemodified); + // Check if we are in backup::MODE_IMPORT (we set a new meetingid) or backup::MODE_GENERAL (we keep the same meetingid). + if ($this->get_task()->get_info()->mode == backup::MODE_IMPORT || empty($data->meetingid)) { + // We are in backup::MODE_IMPORT, we need to renew the meetingid. + $data->meetingid = \mod_bigbluebuttonbn\meeting::get_unique_meetingid_seed(); + } // Insert the bigbluebuttonbn record. $newitemid = $DB->insert_record('bigbluebuttonbn', $data); // Immediately after inserting "activity" record, call this. diff --git a/tests/backup_restore_test.php b/tests/backup_restore_test.php index c4ab79d6b..0da05b22e 100644 --- a/tests/backup_restore_test.php +++ b/tests/backup_restore_test.php @@ -49,7 +49,6 @@ class backup_restore_test extends restore_date_testcase { */ public function setUp(): void { parent::setUp(); - $this->initialise_mock_server(); } /** @@ -80,6 +79,7 @@ public function test_backup_restore(): void { $DB->get_record('bigbluebuttonbn', ['course' => $newcourseid, 'type' => $type], '*', MUST_EXIST); // One record. $this->assert_bbb_activities_same($bbactivity[$type], $newbbb); + $this->assertEquals($bbactivity[$type]->meetingid, $newbbb->meetingid); } } @@ -98,6 +98,7 @@ public function test_backup_restore(): void { public function test_backup_restore_with_recordings(): void { global $DB; $this->resetAfterTest(); + $this->initialise_mock_server(); set_config('bigbluebuttonbn_importrecordings_enabled', 1); // This is for imported recording. $generator = $this->getDataGenerator(); @@ -177,6 +178,57 @@ public function test_backup_restore_with_recordings(): void { } } + /** + * Check duplicating activity does not duplicate meeting id + * + * @dataProvider bbb_type_provider + */ + public function test_duplicate_module_no_meetingid(int $type) { + list($bbactivitycontext, $bbactivitycm, $bbactivity) + = $this->create_instance($this->get_course(), ['type' => $type]); + $newcm = duplicate_module($this->get_course(), $bbactivitycm); + $oldinstance = instance::get_from_cmid($bbactivitycm->id); + $newinstance = instance::get_from_cmid($newcm->id); + + $this->assertNotEquals($oldinstance->get_instance_var('meetingid'), $newinstance->get_instance_var('meetingid')); + } + + /** + * Check that using the recycle bin keeps the meeting id + * + * @dataProvider bbb_type_provider + */ + public function test_recycle_module_keep_meetingid(int $type) { + list($bbactivitycontext, $bbactivitycm, $bbactivity) + = $this->create_instance($this->get_course(), ['type' => $type]); + // Delete the course module. + course_delete_module($bbactivitycm->id); + // Now, run the course module deletion adhoc task. + \phpunit_util::run_all_adhoc_tasks(); + $currentinstances = instance::get_all_instances_in_course($this->course->id); + $this->assertEmpty($currentinstances); + // Try restoring. + $recyclebin = new \tool_recyclebin\course_bin($this->course->id); + foreach ($recyclebin->get_items() as $item) { + $recyclebin->restore_item($item); + } + $restoredinstance = instance::get_all_instances_in_course($this->course->id); + $restoredinstance = end($restoredinstance); + $this->assertEquals($restoredinstance->get_instance_var('meetingid'), $bbactivity->meetingid); + } + + /** + * Return an array of BigBlueButton types + * @return array[] + */ + public function bbb_type_provider() { + return [ + 'All' => [instance::TYPE_ALL], + 'Recording Only' => [instance::TYPE_RECORDING_ONLY], + 'Room Only' => [instance::TYPE_ROOM_ONLY] + ]; + } + /** * Check two bbb activities are the same *