Skip to content

Commit

Permalink
Merge branch 'w24_MDL-28394_m25_enrolrestore' of git://github.com/sko…
Browse files Browse the repository at this point in the history
…dak/moodle into MOODLE_25_STABLE
  • Loading branch information
danpoltawski committed Jun 10, 2013
2 parents c9d1c49 + d98b9a9 commit 9d1a909
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
16 changes: 14 additions & 2 deletions backup/moodle2/restore_course_task.class.php
Expand Up @@ -73,8 +73,20 @@ public function build() {

$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'));
}

Expand Down
1 change: 1 addition & 0 deletions backup/moodle2/restore_root_task.class.php
Expand Up @@ -115,6 +115,7 @@ protected function define_settings() {
$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);

Expand Down
23 changes: 23 additions & 0 deletions backup/moodle2/restore_stepslib.php
Expand Up @@ -1625,6 +1625,29 @@ public function process_override($data) {
}
}

/**
* 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
Expand Down

0 comments on commit 9d1a909

Please sign in to comment.