Merge branch 'w24_MDL-28394_m26_enrolrestore' of git://github.com/skodak/moodle
This commit is contained in:
@@ -73,8 +73,20 @@ class restore_course_task extends restore_task {
|
||||
|
||||
$this->add_step(new restore_course_legacy_files_step('legacy_files'));
|
||||
|
||||
// Restore course enrolments (plugins and membership). Conditionally prevented for any IMPORT/HUB operation
|
||||
if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) {
|
||||
// Deal with enrolment methods and user enrolments.
|
||||
if ($this->plan->get_mode() == backup::MODE_IMPORT) {
|
||||
// No need to do anything with enrolments.
|
||||
|
||||
} else if (!$this->get_setting_value('users') or $this->plan->get_mode() == backup::MODE_HUB) {
|
||||
if ($this->get_target() == backup::TARGET_CURRENT_ADDING or $this->get_target() == backup::TARGET_EXISTING_ADDING) {
|
||||
// Keep current enrolments unchanged.
|
||||
} else {
|
||||
// If no instances yet add default enrol methods the same way as when creating new course in UI.
|
||||
$this->add_step(new restore_default_enrolments_step('default_enrolments'));
|
||||
}
|
||||
|
||||
} else {
|
||||
// Restore course enrolment data.
|
||||
$this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@ class restore_root_task extends restore_task {
|
||||
$rootenrolmanual = new restore_users_setting('enrol_migratetomanual', base_setting::IS_BOOLEAN, false);
|
||||
$rootenrolmanual->set_ui(new backup_setting_ui_checkbox($rootenrolmanual, get_string('rootenrolmanual', 'backup')));
|
||||
$rootenrolmanual->get_ui()->set_changeable(enrol_is_enabled('manual'));
|
||||
$rootenrolmanual->get_ui()->set_changeable($changeable);
|
||||
$this->add_setting($rootenrolmanual);
|
||||
$users->add_dependency($rootenrolmanual);
|
||||
|
||||
|
||||
@@ -1625,6 +1625,29 @@ class restore_ras_and_caps_structure_step extends restore_structure_step {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no instances yet add default enrol methods the same way as when creating new course in UI.
|
||||
*/
|
||||
class restore_default_enrolments_step extends restore_execution_step {
|
||||
public function define_execution() {
|
||||
global $DB;
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$this->get_courseid()), '*', MUST_EXIST);
|
||||
|
||||
if ($DB->record_exists('enrol', array('courseid'=>$this->get_courseid(), 'enrol'=>'manual'))) {
|
||||
// Something already added instances, do not add default instances.
|
||||
$plugins = enrol_get_plugins(true);
|
||||
foreach ($plugins as $plugin) {
|
||||
$plugin->restore_sync_course($course);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Looks like a newly created course.
|
||||
enrol_course_updated(true, $course, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This structure steps restores the enrol plugins and their underlying
|
||||
* enrolments, performing all the mappings and/or movements required
|
||||
|
||||
Reference in New Issue
Block a user