Skip to content

Commit

Permalink
MDL-74404 mod_bigbluebuttonbn: Delete logs when course reset
Browse files Browse the repository at this point in the history
* When Delete custom logs is selected we should delete all logs in
bigbluebuttonbn_logs table related to this course (join, add events...)
  • Loading branch information
laurentdavid committed Apr 1, 2022
1 parent 7ce003b commit 8ab0990
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
13 changes: 12 additions & 1 deletion mod/bigbluebuttonbn/classes/local/helpers/reset.php
Expand Up @@ -84,7 +84,7 @@ public static function reset_tags(int $courseid): void {
* Used by the reset_course_userdata for deleting events linked to bigbluebuttonbn instances in the course.
*
* @param string $courseid
* @return bool status array
* @return bool status
*/
public static function reset_events($courseid) {
global $DB;
Expand Down Expand Up @@ -117,4 +117,15 @@ public static function reset_course_items(): array {
}
return $items;
}

/**
* Reset logs for each BBB instance of this course
*
* @param int $courseid
* @return bool status
*/
public static function reset_logs(int $courseid) {
global $DB;
return $DB->delete_records('bigbluebuttonbn_logs', ['courseid' => $courseid]);
}
}
7 changes: 7 additions & 0 deletions mod/bigbluebuttonbn/lib.php
Expand Up @@ -327,6 +327,13 @@ function bigbluebuttonbn_reset_userdata(stdClass $data) {
unset($items['tags']);
$status[] = reset::reset_getstatus('tags');
}

if (!empty($data->reset_bigbluebuttonbn_logs)) {
// Remove all the tags linked to the room/activities in this course.
reset::reset_logs($data->courseid);
unset($items['logs']);
$status[] = reset::reset_getstatus('logs');
}
return $status;
}

Expand Down
71 changes: 70 additions & 1 deletion mod/bigbluebuttonbn/tests/lib_test.php
Expand Up @@ -391,18 +391,28 @@ public function test_bigbluebuttonbn_reset_course_form_defaults() {
}

/**
* Check user data
* Reset user data
*
* @covers ::bigbluebuttonbn_reset_userdata
*/
public function test_bigbluebuttonbn_reset_userdata() {
global $DB;
$this->resetAfterTest();
$data = new stdClass();
$user = $this->getDataGenerator()->create_user();

list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);

logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);
$data->courseid = $this->get_course()->id;
$data->reset_bigbluebuttonbn_tags = true;
$data->reset_bigbluebuttonbn_logs = true;
$data->course = $bbactivity->course;
// Add and Join.
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
$results = bigbluebuttonbn_reset_userdata($data);
$this->assertCount(0, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
$this->assertEquals([
'component' => 'BigBlueButton',
'item' => 'Deleted tags',
Expand All @@ -412,6 +422,65 @@ public function test_bigbluebuttonbn_reset_userdata() {
);
}

/**
* Reset user data in a course and checks it does not delete logs elsewhere
*
* @covers ::bigbluebuttonbn_reset_userdata
*/
public function test_bigbluebuttonbn_reset_userdata_in_a_course() {
global $DB;
$this->resetAfterTest();
$data = new stdClass();
$datagenerator = $this->getDataGenerator();
$user = $datagenerator->create_user();

list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);

// Now create another activity in a course and add a couple of logs.
// Aim is to make sure that only logs from one course are deleted.
$course1 = $datagenerator->create_course();
list($bbactivitycontext1, $bbactivitycm1, $bbactivity1) = $this->create_instance($course1);
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity1->id), 0);

$data->courseid = $this->get_course()->id;
$data->reset_bigbluebuttonbn_tags = true;
$data->reset_bigbluebuttonbn_logs = true;
$data->course = $bbactivity->course;
// Add and Join.
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity1->id]));
bigbluebuttonbn_reset_userdata($data);
$this->assertCount(0, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity1->id]));
}

/**
* Reset user data in a course but do not delete logs
*
* @covers ::bigbluebuttonbn_reset_userdata
*/
public function test_bigbluebuttonbn_reset_userdata_logs_not_deleted() {
global $DB;
$this->resetAfterTest();
$data = new stdClass();
$datagenerator = $this->getDataGenerator();
$user = $datagenerator->create_user();

list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);

$data->courseid = $this->get_course()->id;
$data->reset_bigbluebuttonbn_logs = false;
$data->course = $bbactivity->course;
// Add and Join.
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
bigbluebuttonbn_reset_userdata($data);
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
}

/**
* Check course module
*
Expand Down

0 comments on commit 8ab0990

Please sign in to comment.