From 76a819557c77845e147d1f67143df508af999eab Mon Sep 17 00:00:00 2001 From: Flotter Totte Date: Wed, 6 Dec 2017 17:31:54 +0800 Subject: [PATCH] Backup and restore feature Backup and restore feature --- lib.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib.php b/lib.php index 15bfaad..2ff23ab 100644 --- a/lib.php +++ b/lib.php @@ -479,4 +479,30 @@ class enrol_apply_plugin extends enrol_plugin { } return $content; } + + /** + * Backup execution step hook. + * + * @param backup_enrolments_execution_step $step + * @param stdClass $enrol + */ + public function backup_annotate_custom_fields(backup_enrolments_execution_step $step, stdClass $enrol) { + // annotate customint1 as a role + $step->annotate_id('role', $enrol->customint1); + } + + public function restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid) { + global $DB, $CFG; + + $data->customint1 = $step->get_mappingid('role', $data->customint1, null); + + $instanceid = $this->add_instance($course, (array)$data); + $step->set_mapping('enrol', $oldid, $instanceid); + + //$this->sync_enrols($DB->get_record('enrol', array('id'=>$instanceid))); + } + + public function restore_user_enrolment(restore_enrolments_structure_step $step, $data, $instance, $userid, $oldinstancestatus) { + $this->enrol_user($instance, $userid, null, $data->timestart, $data->timeend, $oldinstancestatus); + } }