mirror of
https://github.com/moodle/moodle.git
synced 2025-04-11 19:42:35 +02:00
MDL-74404 mod_bigbluebuttonbn: Delete logs when course reset
* When Delete custom logs is selected we should delete all logs in bigbluebuttonbn_logs table related to this course (join, add events...)
This commit is contained in:
parent
7ce003b666
commit
8ab0990345
@ -84,7 +84,7 @@ class reset {
|
||||
* 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;
|
||||
@ -117,4 +117,15 @@ class reset {
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -391,18 +391,28 @@ class lib_test extends \advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
@ -412,6 +422,65 @@ class lib_test extends \advanced_testcase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user