Merge branch 'MDL-71949-fix-backup-log-master' of https://github.com/matthewhilton/moodle

This commit is contained in:
Ilya Tregubov 2022-01-12 11:40:56 +02:00
commit 30148593b2
5 changed files with 27 additions and 1 deletions

View File

@ -203,6 +203,7 @@ if (!async_helper::is_async_pending($id, 'course', 'backup')) {
$asynctask = new \core\task\asynchronous_backup_task();
$asynctask->set_blocking(false);
$asynctask->set_custom_data(array('backupid' => $backupid));
$asynctask->set_userid($USER->id);
\core\task\manager::queue_adhoc_task($asynctask);
// Add ajax progress bar and initiate ajax via a template.

View File

@ -171,6 +171,7 @@ if ($restore->get_stage() != restore_ui::STAGE_PROCESS) {
$restoreid = $restore->get_restoreid();
$asynctask = new \core\task\asynchronous_restore_task();
$asynctask->set_blocking(false);
$asynctask->set_userid($USER->id);
$asynctask->set_custom_data(array('backupid' => $restoreid));
\core\task\manager::queue_adhoc_task($asynctask);

View File

@ -59,6 +59,10 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
$forum2 = $generator->create_module('forum', array(
'course' => $course->id, 'completion' => COMPLETION_TRACKING_MANUAL));
// Create a teacher user to call the backup.
$teacher = $generator->create_user();
$generator->enrol_user($teacher->id, $course->id, 'editingteacher');
// We need a grade, easiest is to add an assignment.
$assignrow = $generator->create_module('assign', array(
'course' => $course->id));
@ -79,6 +83,15 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
$DB->set_field('course_sections', 'availability', $availability, array(
'course' => $course->id, 'section' => 1));
// Enable logging.
$this->preventResetByRollback();
set_config('enabled_stores', 'logstore_standard', 'tool_log');
set_config('buffersize', 0, 'logstore_standard');
get_log_manager(true);
// Start backup process.
$this->setUser($teacher->id);
// Make the backup controller for an async backup.
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_YES, backup::MODE_ASYNC, $USER->id);
@ -96,6 +109,7 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
$asynctask = new \core\task\asynchronous_backup_task();
$asynctask->set_blocking(false);
$asynctask->set_custom_data(['backupid' => $backupid]);
$asynctask->set_userid($USER->id);
\core\task\manager::queue_adhoc_task($asynctask);
// We are expecting trace output during this test.
@ -108,11 +122,18 @@ class core_backup_async_backup_testcase extends \core_privacy\tests\provider_tes
$task->execute();
\core\task\manager::adhoc_task_complete($task);
$postbackuprec = $DB->get_record('backup_controllers', array('backupid' => $backupid));
$postbackuprec = $DB->get_record('backup_controllers', ['backupid' => $backupid]);
// Check backup was created successfully.
$this->assertEquals(backup::STATUS_FINISHED_OK, $postbackuprec->status);
$this->assertEquals(1.0, $postbackuprec->progress);
$this->assertEquals($teacher->id, $postbackuprec->userid);
// Check that the backupid was logged correctly.
$logrec = $DB->get_record('logstore_standard_log', ['userid' => $postbackuprec->userid,
'target' => 'course_backup'], '*', MUST_EXIST);
$otherdata = json_decode($logrec->other);
$this->assertEquals($backupid, $otherdata->backupid);
}
/**

View File

@ -118,6 +118,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
$asynctask = new \core\task\asynchronous_restore_task();
$asynctask->set_blocking(false);
$asynctask->set_custom_data(array('backupid' => $restoreid));
$asynctask->set_userid($USER->id);
\core\task\manager::queue_adhoc_task($asynctask);
// We are expecting trace output during this test.
@ -135,6 +136,7 @@ class core_backup_async_restore_testcase extends \core_privacy\tests\provider_te
// Check backup was created successfully.
$this->assertEquals(backup::STATUS_FINISHED_OK, $postrestorerec->status);
$this->assertEquals(1.0, $postrestorerec->progress);
$this->assertEquals($USER->id, $postrestorerec->userid);
}
/**

View File

@ -151,6 +151,7 @@ class backup_plan extends base_plan implements loggable {
'mode' => $this->controller->get_mode(),
'interactive' => $this->controller->get_interactive(),
'type' => $this->controller->get_type(),
'backupid' => $this->controller->get_backupid()
);
$event = \core\event\course_backup_created::create(array(
'objectid' => $this->get_courseid(),