Blind code to use MEW

This commit is contained in:
Kumi 2022-01-13 11:36:16 +01:00
parent b16eec356f
commit 4f62900be1
2 changed files with 13 additions and 41 deletions

View file

@ -8,4 +8,5 @@ $string['pluginname'] = $string['modulename'];
$string['settings'] = 'Settings';
$string['directory'] = 'Directory to dump exports to';
$string['directory'] = 'Directory to dump triggers to';
$string['directoryhelp'] = 'Full path to the directory where Moodle Export Worker is looking for its trigger files';

View file

@ -2,55 +2,26 @@
require_once("../../config.php");
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
if (! function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool
{
$needle_len = strlen($needle);
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
}
}
$id = $_GET["id"];
$course = get_course($id);
$replicationconfig = get_config('local_replication');
$directory = $replicationconfig->directory;
if (!str_ends_with($directory, "/")) $directory = $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();
$result = $bc->get_results();
if(isset($result['backup_destination']) && $result['backup_destination']) {
$file = $result['backup_destination'];
if(!$file->copy_content_to($filename)) {
echo("Problems copying final backup to '". $filename . "'");
}
}
echo('Course is now getting replicated. <a href="javascript:history.back();">Back to Course Administration</a>');
touch($directory . $id . "-" . $course->category . ".mew");