moodle-local_replication/trigger.php
2022-01-13 11:36:16 +01:00

27 lines
811 B
PHP

<?php
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!");
}
touch($directory . $id . "-" . $course->category . ".mew");