Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'w24_MDL-28394_m25_enrolrestore' of git://github.com/sko…

…dak/moodle into MOODLE_25_STABLE
  • Loading branch information...
commit 9d1a909f0ece996502879b4162765efde168afe8 2 parents c9d1c49 + d98b9a9
@danpoltawski danpoltawski authored
View
16 backup/moodle2/restore_course_task.class.php
@@ -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'));
}
View
1  backup/moodle2/restore_root_task.class.php
@@ -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);
View
23 backup/moodle2/restore_stepslib.php
@@ -1626,6 +1626,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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.