diff --git a/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php index 78741ec2a57..387406d93e4 100644 --- a/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php +++ b/grade/grading/form/rubric/backup/moodle2/backup_gradingform_rubric_plugin.class.php @@ -106,8 +106,13 @@ class backup_gradingform_rubric_plugin extends backup_gradingform_plugin { // Set sources to populate the data - $filling->set_source_table('gradingform_rubric_fillings', - array('instanceid' => backup::VAR_PARENTID)); + // Binding criterionid to ensure it's existence + $filling->set_source_sql('SELECT rf.* + FROM {gradingform_rubric_fillings} rf + JOIN {grading_instances} gi ON gi.id = rf.instanceid + JOIN {gradingform_rubric_criteria} rc ON rc.id = rf.criterionid AND gi.definitionid = rc.definitionid + WHERE rf.instanceid = :instanceid', + array('instanceid' => backup::VAR_PARENTID)); // no need to annotate ids or files yet (one day when remark field supports // embedded fileds, they must be annotated here) diff --git a/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php b/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php index 62b5c96d9da..adb95978aa9 100644 --- a/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php +++ b/grade/grading/form/rubric/backup/moodle2/restore_gradingform_rubric_plugin.class.php @@ -109,6 +109,9 @@ class restore_gradingform_rubric_plugin extends restore_gradingform_plugin { $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid); $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid); - $DB->insert_record('gradingform_rubric_fillings', $data); + if (!empty($data->criterionid)) { + $DB->insert_record('gradingform_rubric_fillings', $data); + } + } }