moodle-local_replication/trigger.php
2022-08-22 09:52:55 +00:00

45 lines
1.5 KiB
PHP

<?php
require_once("../../config.php");
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
$id = $_GET["id"];
$course = get_course($id);
$replicationconfig = get_config('local_replication');
$directory = $replicationconfig->directory;
$context = context_course::instance($id);
if (!has_capability('local/replication:replicate', $context)) {
die("User not allowed to trigger replication!");
}
$bc = new backup_controller(\backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id);
$tasks = $bc->get_plan()->get_tasks();
foreach ($tasks as &$task) {
if ($task instanceof \backup_root_task) {
$setting = $task->get_setting('users');
$setting->set_value('0');
$setting = $task->get_setting('anonymize');
$setting->set_value('1');
$setting = $task->get_setting('role_assignments');
$setting->set_value('0');
$setting = $task->get_setting('filters');
$setting->set_value('0');
$setting = $task->get_setting('comments');
$setting->set_value('0');
$setting = $task->get_setting('logs');
$setting->set_value('0');
$setting = $task->get_setting('grade_histories');
$setting->set_value('0');
}
}
$filename = $directory . '/course_' . $id . "_" . $course->category . "_" . date('U') . '.mbz';
$bc->set_status(backup::STATUS_AWAITING);
$bc->execute_plan();
echo('Course is now getting replicated. <a href="javascript:history.back();">Back to Course Administration</a>');