From a75bb4099bea3344f32ff203bd68b1b13dd75d32 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Wed, 30 Aug 2023 10:03:03 +0200 Subject: [PATCH] MDL-77795 mod_bigbluebuttonbn: Change meetingID on duplicate * We need to set a different meetingID when duplicating or importing a BigBlueButtonBN activity to prevent unwanted sharing of recordings between meetings. --- .../restore_bigbluebuttonbn_stepslib.php | 5 ++ .../tests/backup_restore_test.php | 54 ++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/mod/bigbluebuttonbn/backup/moodle2/restore_bigbluebuttonbn_stepslib.php b/mod/bigbluebuttonbn/backup/moodle2/restore_bigbluebuttonbn_stepslib.php index 5bb38451017..f67ba0d7b4a 100644 --- a/mod/bigbluebuttonbn/backup/moodle2/restore_bigbluebuttonbn_stepslib.php +++ b/mod/bigbluebuttonbn/backup/moodle2/restore_bigbluebuttonbn_stepslib.php @@ -57,6 +57,11 @@ class restore_bigbluebuttonbn_activity_structure_step extends restore_activity_s $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/mod/bigbluebuttonbn/tests/backup_restore_test.php b/mod/bigbluebuttonbn/tests/backup_restore_test.php index 05ea93c0154..f173ea1802e 100644 --- a/mod/bigbluebuttonbn/tests/backup_restore_test.php +++ b/mod/bigbluebuttonbn/tests/backup_restore_test.php @@ -51,7 +51,6 @@ class backup_restore_test extends restore_date_testcase { */ public function setUp(): void { parent::setUp(); - $this->initialise_mock_server(); } /** @@ -82,6 +81,7 @@ class backup_restore_test extends restore_date_testcase { $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); } } @@ -100,6 +100,7 @@ class backup_restore_test extends restore_date_testcase { 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(); @@ -179,6 +180,57 @@ class backup_restore_test extends restore_date_testcase { } } + /** + * 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 *