moodle-local_replication/trigger_all.php
Kumi f9ed77bcde
feat(replication): enhance course and category management
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.
2024-09-09 14:55:36 +02:00

33 lines
935 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));
}
}
$context = context_system::instance();
if (!has_capability('local/replication:replicate', $context)) {
die("User not allowed to trigger replication!");
}
$courses = get_courses();
$replicationconfig = get_config('local_replication');
$directory = $replicationconfig->directory;
if (!str_ends_with($directory, "/")) $directory = $directory . "/";
foreach ($courses as $course) {
if (!touch($directory . $course->id . "-" . $course->category . ".mew")) {
die("Could not touch $directory$id-{$course->category}.mew");
}
}
echo("Done.");