Skip to content

Commit

Permalink
Merge branch 'MDL-28369' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jul 25, 2011
2 parents d98b0fe + ad858cd commit 14c9423
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2371,11 +2371,13 @@ protected function define_structure() {

$category = new restore_path_element('question_category', '/question_categories/question_category');
$question = new restore_path_element('question', '/question_categories/question_category/questions/question');
$hint = new restore_path_element('question_hint',
'/question_categories/question_category/questions/question/question_hints/question_hint');

// Apply for 'qtype' plugins optional paths at question level
$this->add_plugin_structure('qtype', $question);

return array($category, $question);
return array($category, $question, $hint);
}

protected function process_question_category($data) {
Expand Down Expand Up @@ -2484,19 +2486,19 @@ protected function process_question_hint($data) {
// Adjust some columns
$data->questionid = $newquestionid;
// Insert record
$newitemid = $DB->insert_record('question_answers', $data);
$newitemid = $DB->insert_record('question_hints', $data);

// The question existed, we need to map the existing question_answers
// The question existed, we need to map the existing question_hints
} else {
// Look in question_answers by answertext matching
// Look in question_hints by hint text matching
$sql = 'SELECT id
FROM {question_hints}
WHERE questionid = ?
AND ' . $DB->sql_compare_text('hint', 255) . ' = ' . $DB->sql_compare_text('?', 255);
$params = array($newquestionid, $data->hint);
$newitemid = $DB->get_field_sql($sql, $params);
// If we haven't found the newitemid, something has gone really wrong, question in DB
// is missing answers, exception
// is missing hints, exception
if (!$newitemid) {
$info = new stdClass();
$info->filequestionid = $oldquestionid;
Expand All @@ -2505,7 +2507,7 @@ protected function process_question_hint($data) {
throw new restore_step_exception('error_question_hint_missing_in_db', $info);
}
}
// Create mapping (we'll use this intensively when restoring question_states. And also answerfeedback files)
// Create mapping (I'm not sure if this is really needed?)
$this->set_mapping('question_hint', $oldid, $newitemid);
}

Expand Down

0 comments on commit 14c9423

Please sign in to comment.