Commit 05cd2ff6 authored by Marina Glancy's avatar Marina Glancy

MDL-34161 mod_lti: backup and restore of submissions

parent 6489a3d4
...@@ -133,6 +133,17 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step ...@@ -133,6 +133,17 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step
) )
); );
$ltisubmissions = new backup_nested_element('ltisubmissions');
$ltisubmission = new backup_nested_element('ltisubmission', array('id'), array(
'userid',
'datesubmitted',
'dateupdated',
'gradepercent',
'originalgrade',
'launchid',
'state'
));
// Build the tree // Build the tree
$lti->add_child($ltitype); $lti->add_child($ltitype);
$ltitype->add_child($ltitypesconfigs); $ltitype->add_child($ltitypesconfigs);
...@@ -141,6 +152,8 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step ...@@ -141,6 +152,8 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step
$ltitype->add_child($ltitoolproxy); $ltitype->add_child($ltitoolproxy);
$ltitoolproxy->add_child($ltitoolsettings); $ltitoolproxy->add_child($ltitoolsettings);
$ltitoolsettings->add_child($ltitoolsetting); $ltitoolsettings->add_child($ltitoolsetting);
$lti->add_child($ltisubmissions);
$ltisubmissions->add_child($ltisubmission);
// Define sources. // Define sources.
$ltirecord = $DB->get_record('lti', ['id' => $this->task->get_activityid()]); $ltirecord = $DB->get_record('lti', ['id' => $this->task->get_activityid()]);
...@@ -173,9 +186,15 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step ...@@ -173,9 +186,15 @@ class backup_lti_activity_structure_step extends backup_activity_structure_step
$ltitoolproxy->set_source_array([]); $ltitoolproxy->set_source_array([]);
} }
// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$ltisubmission->set_source_table('lti_submission', array('ltiid' => backup::VAR_ACTIVITYID));
}
// Define id annotations // Define id annotations
$ltitype->annotate_ids('user', 'createdby'); $ltitype->annotate_ids('user', 'createdby');
$ltitype->annotate_ids('course', 'course'); $ltitype->annotate_ids('course', 'course');
$ltisubmission->annotate_ids('user', 'userid');
// Define file annotations. // Define file annotations.
$lti->annotate_files('mod_lti', 'intro', null); // This file areas haven't itemid. $lti->annotate_files('mod_lti', 'intro', null); // This file areas haven't itemid.
......
...@@ -59,6 +59,9 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste ...@@ -59,6 +59,9 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste
protected function define_structure() { protected function define_structure() {
$paths = array(); $paths = array();
// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');
$lti = new restore_path_element('lti', '/activity/lti'); $lti = new restore_path_element('lti', '/activity/lti');
$paths[] = $lti; $paths[] = $lti;
$paths[] = new restore_path_element('ltitype', '/activity/lti/ltitype'); $paths[] = new restore_path_element('ltitype', '/activity/lti/ltitype');
...@@ -68,6 +71,11 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste ...@@ -68,6 +71,11 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste
$paths[] = new restore_path_element('ltitoolproxy', '/activity/lti/ltitype/ltitoolproxy'); $paths[] = new restore_path_element('ltitoolproxy', '/activity/lti/ltitype/ltitoolproxy');
$paths[] = new restore_path_element('ltitoolsetting', '/activity/lti/ltitype/ltitoolproxy/ltitoolsettings/ltitoolsetting'); $paths[] = new restore_path_element('ltitoolsetting', '/activity/lti/ltitype/ltitoolproxy/ltitoolsettings/ltitoolsetting');
if ($userinfo) {
$submission = new restore_path_element('ltisubmission', '/activity/lti/ltisubmissions/ltisubmission');
$paths[] = $submission;
}
// Add support for subplugin structures. // Add support for subplugin structures.
$this->add_subplugin_structure('ltisource', $lti); $this->add_subplugin_structure('ltisource', $lti);
$this->add_subplugin_structure('ltiservice', $lti); $this->add_subplugin_structure('ltiservice', $lti);
...@@ -246,6 +254,29 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste ...@@ -246,6 +254,29 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste
$DB->insert_record('lti_tool_settings', $data); $DB->insert_record('lti_tool_settings', $data);
} }
/**
* Process a submission restore
* @param mixed $data The data from backup XML file
*/
protected function process_ltisubmission($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->ltiid = $this->get_new_parentid('lti');
$data->datesubmitted = $this->apply_date_offset($data->datesubmitted);
$data->dateupdated = $this->apply_date_offset($data->dateupdated);
if ($data->userid > 0) {
$data->userid = $this->get_mappingid('user', $data->userid);
}
$newitemid = $DB->insert_record('lti_submission', $data);
$this->set_mapping('ltisubmission', $oldid, $newitemid);
}
protected function after_execute() { protected function after_execute() {
// Add lti related files, no need to match by itemname (just internally handled context). // Add lti related files, no need to match by itemname (just internally handled context).
$this->add_related_files('mod_lti', 'intro', null); $this->add_related_files('mod_lti', 'intro', null);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment