moodle-local_replication/trigger.php

42 lines
1 KiB
PHP
Raw Normal View History

2022-01-13 07:12:46 +00:00
<?php
require_once("../../config.php");
2022-08-22 09:52:55 +00:00
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.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
$replicationconfig = get_config('local_replication');
$directory = $replicationconfig->directory;
if (!str_ends_with($directory, "/")) $directory = $directory . "/";
if (isset($_GET["categories"])) {
touch($directory . "categories.mew");
echo("Done.");
exit();
}
if (!isset($_GET["id"])) {
die("Missing course ID!");
}
$id = $_GET["id"];
$course = get_course($id);
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");
}
echo("Done.");