Allow importer to overwrite course config, I guess?

This commit is contained in:
Kumi 2022-08-22 15:12:21 +00:00
parent c9742bf794
commit 21094f4a51
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -48,7 +48,8 @@ if (empty($options['timestamp'])) {
cli_error('Missing mandatory argument timestamp.', 2);
}
function generateRandomString($length = 10) {
function generateRandomString($length = 10)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
@ -76,7 +77,7 @@ try {
}
if (!$course) {
while (!get_course(((int) $courseid) - 1)) {
while (!$DB->get_record('course', array('id' => ((int) $courseid) - 1), '*')) {
$name = generateRandomString();
$newcourse = restore_dbops::create_new_course("Placeholder " . $name, $name, $category->id);
if ((int) $newcourse > (int) $courseid) {
@ -106,8 +107,7 @@ $backupdir = "restore_" . uniqid();
if (isset($CFG->backuptempdir)) {
$path = $CFG->backuptempdir . DIRECTORY_SEPARATOR . $backupdir;
}
else{
} else {
$path = $CFG->tempdir . DIRECTORY_SEPARATOR . "backup" . DIRECTORY_SEPARATOR . $backupdir;
}
@ -152,13 +152,28 @@ if (!$course && $DB->get_record('course', array('category' => $category->id, 'sh
if ($course) {
cli_writeln("Overwriting current content of existing course -> Course ID: $courseid");
$rc = new restore_controller($backupdir, $courseid, backup::INTERACTIVE_NO,
backup::MODE_GENERAL, 2, 0);
$rc = new restore_controller(
$backupdir,
$courseid,
backup::INTERACTIVE_NO,
backup::MODE_GENERAL,
2,
0
);
$rc->get_plan()->get_setting('overwrite_conf')->set_value(true);
} else {
cli_writeln("Creating new course to restore backup");
$courseid = restore_dbops::create_new_course($fullname, $shortname, $category->id);
$rc = new restore_controller($backupdir, $courseid, backup::INTERACTIVE_NO,
backup::MODE_GENERAL, 2, backup::TARGET_NEW_COURSE);
$rc = new restore_controller(
$backupdir,
$courseid,
backup::INTERACTIVE_NO,
backup::MODE_GENERAL,
2,
backup::TARGET_NEW_COURSE
);
}
if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {