MDL-65724 core: Force restore to use the settings from the plan

When importing use the import settings.
This commit is contained in:
Peter 2019-06-24 12:57:17 +08:00 committed by Peter Dias
parent d7374522ed
commit 74d95c7bf9
2 changed files with 54 additions and 1 deletions

View File

@ -955,6 +955,52 @@ class core_backup_moodle2_testcase extends advanced_testcase {
$this->assertEquals('', $requests[2]->searcharea);
}
/**
* Test restoring courses based on the backup plan. Primarily used with
* the import functionality
*/
public function test_restore_course_using_plan_defaults() {
global $DB, $CFG, $USER;
$this->resetAfterTest(true);
$this->setAdminUser();
$CFG->enableglobalsearch = true;
// Set admin config setting so that activities are not restored by default.
set_config('restore_general_activities', 0, 'restore');
// Create a course.
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$course2 = $generator->create_course();
$course3 = $generator->create_course();
// Add a forum.
$forum = $generator->create_module('forum', ['course' => $course->id]);
// Backup course...
$CFG->backup_file_logger_level = backup::LOG_NONE;
$bc = new backup_controller(backup::TYPE_1COURSE, $course->id,
backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT,
$USER->id);
$backupid = $bc->get_backupid();
$bc->execute_plan();
$bc->destroy();
// Restore it on top of course2 (should duplicate the forum).
$rc = new restore_controller($backupid, $course2->id,
backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id,
backup::TARGET_EXISTING_ADDING, null, backup::RELEASESESSION_NO);
$this->assertTrue($rc->execute_precheck());
$rc->execute_plan();
$rc->destroy();
// Get the forums now on the old course.
$modinfo = get_fast_modinfo($course2->id);
$forums = $modinfo->get_instances_of('forum');
$this->assertCount(0, $forums);
}
/**
* The Question category hierarchical structure was changed in Moodle 3.5.
* From 3.5, all question categories in each context are a child of a single top level question category for that context.

View File

@ -282,7 +282,14 @@ abstract class restore_controller_dbops extends restore_dbops {
if ($plan->setting_exists($settingname)) {
$setting = $plan->get_setting($settingname);
$value = self::get_setting_default($config, $setting);
$locked = (get_config('restore', $config . '_locked') == true);
$locked = (get_config('restore',$config . '_locked') == true);
// Use the original value when this is an import and the setting is unlocked.
if ($controller->get_mode() == backup::MODE_IMPORT && $controller->get_interactive()) {
if (!$uselocks || !$locked) {
$value = $setting->get_value();
}
}
// We can only update the setting if it isn't already locked by config or permission.
if ($setting->get_status() != base_setting::LOCKED_BY_CONFIG