Kumi
f9ed77bcde
Implement enhanced category and course replication, improving the handling of both by ensuring new and existing categories are processed correctly. Introduce CLI support for bulk category imports using a dedicated flag and provide helper functions like `generateRandomString` and `removePath` for file management. Add a new `trigger_all.php` script to trigger replication for all courses and an `unenroll.php` script for unenrolling users with cleanup of related data. Includes error handling improvements and directory structure checks.
41 lines
1 KiB
PHP
41 lines
1 KiB
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));
|
|
}
|
|
}
|
|
|
|
$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);
|
|
|
|
$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.");
|