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,12 +77,12 @@ try {
}
if (!$course) {
while (!get_course(((int) $courseid) - 1)) {
$name = generateRandomString();
$newcourse = restore_dbops::create_new_course("Placeholder " . $name, $name, $category->id);
if ((int) $newcourse > (int) $courseid) {
cli_error('Did you delete courses by any chance? Cannot create course ' . $courseid . '.');
}
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) {
cli_error('Did you delete courses by any chance? Cannot create course ' . $courseid . '.');
}
}
}
@ -104,10 +105,9 @@ if (!is_readable($infile)) {
$backupdir = "restore_" . uniqid();
if (isset($CFG->backuptempdir)){
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) {
@ -167,7 +182,7 @@ if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
$plan = $rc->get_plan();
if (!$rc->execute_precheck()){
if (!$rc->execute_precheck()) {
$check = $rc->get_precheck_results();
cli_error("Restore pre-check failed!");
}