moodle-local_replication/trigger.php

28 lines
811 B
PHP
Raw Normal View History

2022-01-13 07:12:46 +00:00
<?php
require_once("../../config.php");
2022-01-13 10:36:16 +00:00
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));
}
}
2022-01-13 07:12:46 +00:00
$id = $_GET["id"];
$course = get_course($id);
$replicationconfig = get_config('local_replication');
$directory = $replicationconfig->directory;
2022-01-13 10:36:16 +00:00
if (!str_ends_with($directory, "/")) $directory = $directory . "/";
2022-01-13 07:12:46 +00:00
$context = context_course::instance($id);
if (!has_capability('local/replication:replicate', $context)) {
die("User not allowed to trigger replication!");
}
if (!touch($directory . $id . "-" . $course->category . ".mew")) {
die("Could not touch $directory$id-{$course->category}.mew");
}