commit e4601323a7b277136d5dc2c24e95ff3deef61468 Author: Dustin Ernst Date: Thu Feb 23 13:05:21 2012 -0600 Process user enrolments before attempting to assign roles. restore_ras_and_caps_structure_step->process_assignment() had documentation saying that enrolments should be processed before it is run. The restore task was calling it before doing the enrolments, so the roles for any plugin other than manual couldn't be properly restored. Also, the previously unreachable bit of code that did the role_assign for plugins caused an error because it was looking for a field in the enrol table that doesn't exist. After this change, any enrolment plugin with a function enrol_plugin_supports() that returns ENROL_RESTORE_EXACT for it's ENROL_RESTORE_TYPE will have it's enrolments properly restored from a course backup. diff --git a/backup/moodle2/restore_course_task.class.php b/backup/moodle2/restore_course_task.class.php index 1ab98bf..76b5f60 100644 --- a/backup/moodle2/restore_course_task.class.php +++ b/backup/moodle2/restore_course_task.class.php @@ -66,14 +66,14 @@ class restore_course_task extends restore_task { $this->add_step(new restore_course_structure_step('course_info', 'course.xml')); } - // Restore course role assignments and overrides (internally will observe the role_assignments setting) - $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml')); - // 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) { $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml')); } + // Restore course role assignments and overrides (internally will observe the role_assignments setting) + $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml')); + // Restore course filters (conditionally) if ($this->get_setting_value('filters')) { $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml')); diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index acf17be..df4a78e 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1274,7 +1274,7 @@ class restore_ras_and_caps_structure_step extends restore_structure_step { } else if ((strpos($data->component, 'enrol_') === 0)) { // Deal with enrolment roles if ($enrolid = $this->get_mappingid('enrol', $data->itemid)) { - if ($component = $DB->get_field('enrol', 'component', array('id'=>$enrolid))) { + if ($component = "enrol_".$DB->get_field('enrol', 'enrol', array('id'=>$enrolid))) { //note: we have to verify component because it might have changed if ($component === 'enrol_manual') { // manual is a special case, we do not use components - this owudl happen when converting from other plugin