From cfb80c69faaba6a199695c21737f52c1bc3194ec Mon Sep 17 00:00:00 2001 From: Gregory Faller Date: Wed, 29 Jan 2014 22:23:47 +1030 Subject: [PATCH 1/1] MDL-37714: Fix marking guide comment restoration During restoration, marking guides currently nest frequently used comments too deeply. This updates the path to the correct location and provides a legacy function for backup files created with frequently used comments nested incorrectly. --- .../moodle2/backup_gradingform_guide_plugin.class.php | 2 +- .../moodle2/restore_gradingform_guide_plugin.class.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php b/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php index 75af83a..6ca09c9 100644 --- a/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php +++ b/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php @@ -65,7 +65,7 @@ class backup_gradingform_guide_plugin extends backup_gradingform_plugin { $pluginwrapper->add_child($criteria); $criteria->add_child($criterion); - $criteria->add_child($comments); + $pluginwrapper->add_child($comments); $comments->add_child($comment); // Set sources to populate the data. diff --git a/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php b/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php index dd99814..befe797 100644 --- a/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php +++ b/grade/grading/form/guide/backup/moodle2/restore_gradingform_guide_plugin.class.php @@ -45,8 +45,12 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin { $paths[] = new restore_path_element('gradingform_guide_criterion', $this->get_pathfor('/guidecriteria/guidecriterion')); + // MDL-37714: Correctly locate frequent used comments in both the + // current and incorrect old format. $paths[] = new restore_path_element('gradingform_guide_comment', $this->get_pathfor('/guidecomments/guidecomment')); + $paths[] = new restore_path_element('gradingform_guide_comment_legacy', + $this->get_pathfor('/guidecriteria/guidecomments/guidecomment')); return $paths; } @@ -98,6 +102,20 @@ class restore_gradingform_guide_plugin extends restore_gradingform_plugin { $DB->insert_record('gradingform_guide_comments', $data); } + + /** + * Processes comments element data + * + * @param array|stdClass $data The data to insert as a comment + */ + public function process_gradingform_guide_comment_legacy($data) { + global $DB; + + $data = (object)$data; + $data->definitionid = $this->get_new_parentid('grading_definition'); + + $DB->insert_record('gradingform_guide_comments', $data); + } /** * Processes filling element data -- 1.8.3.4 (Apple Git-47)