Skip to content

Commit

Permalink
CONTRIB-9708: Fix dupe meetingid
Browse files Browse the repository at this point in the history
* Fix meetingid duplication during Course import process
  • Loading branch information
ssj365 committed Oct 3, 2024
1 parent 6d1ee2c commit 5a3aa8b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions backup/moodle2/restore_bigbluebuttonbn_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 53 additions & 1 deletion tests/backup_restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class backup_restore_test extends restore_date_testcase {
*/
public function setUp(): void {
parent::setUp();
$this->initialise_mock_server();
}

/**
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 5a3aa8b

Please sign in to comment.