From 3c1ce9546945e579d61c1217a28908c40b4c8995 Mon Sep 17 00:00:00 2001 From: Flotter Totte Date: Wed, 6 Dec 2017 17:36:04 +0800 Subject: [PATCH] Backup and restore feature Backup and restore feature --- backup/backup_enrol_apply_plugin.class.php | 57 +++++++++++++++++++++ backup/restore_enrol_apply_plugin.class.php | 40 +++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 backup/backup_enrol_apply_plugin.class.php create mode 100644 backup/restore_enrol_apply_plugin.class.php diff --git a/backup/backup_enrol_apply_plugin.class.php b/backup/backup_enrol_apply_plugin.class.php new file mode 100644 index 0000000..b16babe --- /dev/null +++ b/backup/backup_enrol_apply_plugin.class.php @@ -0,0 +1,57 @@ +. +/** + * Defines the backup_enrol_lti_plugin class. + * + * @package enrol_lti + * @copyright 2016 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +/** + * Provides the information to backup test enrol instances + */ +class backup_enrol_apply_plugin extends backup_enrol_plugin { + + protected function define_enrol_plugin_structure() { + + // Define the virtual plugin element with the condition to fulfill + $plugin = $this->get_plugin_element(null, '../../enrol', $this->pluginname); + + // Create one standard named plugin element (the visible container) + $pluginwrapper = new backup_nested_element($this->get_recommended_name()); + + // connect the visible container ASAP + $plugin->add_child($pluginwrapper); + + $applymaps = new backup_nested_element('applymaps'); + + // Now create the enrol own structures + $applymap = new backup_nested_element('applymap', array('id'), array( + 'enrol', 'status', 'courseid', 'sortorder', 'name', 'enrolperiod', 'enrolstartdate', 'enrolenddate', 'expirynotify', 'expirythreshold', 'notifyall', 'password', 'cost', 'currency', 'roleid', 'customint1', 'customint2', 'customint3', 'customint4', 'customint5', 'customint6', 'customint7', 'customint8', 'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2', 'customtext1', 'customtext2', 'customtext3', 'customtext4', 'timecreated', 'timemodified')); + + // Now the own termmap tree + $pluginwrapper->add_child($applymaps); + $applymaps->add_child($applymap); + + // set source to populate the data + $applymap->set_source_table('enrol_apply_applicationinfo', + array('enrol' => backup::VAR_PARENTID)); + + return $plugin; + } +} diff --git a/backup/restore_enrol_apply_plugin.class.php b/backup/restore_enrol_apply_plugin.class.php new file mode 100644 index 0000000..c3217b0 --- /dev/null +++ b/backup/restore_enrol_apply_plugin.class.php @@ -0,0 +1,40 @@ +dirroot.'/enrol/apply/lib.php'); + +/** + * Provides the information to restore test enrol instances + */ +class restore_enrol_apply_plugin extends restore_enrol_plugin { + + public function define_enrol_plugin_structure() { + return array( + new restore_path_element('applymap', $this->get_pathfor('/applymaps/applymap')), + ); + } + + /** + * Process the termmap element + */ + public function process_applymap($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $enrolid = $this->get_new_parentid('enrol'); + + if (!$enrolid) { + return; // Enrol instance was not restored + } + $type = $DB->get_field('enrol', 'enrol', array('id'=>$enrolid)); + if ($type !== 'apply') { + return; // Enrol was likely converted to manual + } + $data->enrolid = $enrolid; + $data->courseid = $this->task->get_courseid(); + $newitemid = $DB->insert_record('enrol_apply_applicationinfo', $data); + } + +}