From cfdfc85ddce75d46387c49f224a6d36cbac5b94e Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 9 May 2008 15:22:46 +0000 Subject: [PATCH] MDL-14750 - Multianswer questions get broken by backup and restore becuase question->parent is not recoded properly in the database. --- question/restorelib.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/question/restorelib.php b/question/restorelib.php index 2e534c93c80..fe47beea0ed 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -259,17 +259,23 @@ $question->parent = $restored_questions[$i]->parent; - //If it's a new question in the DB, restore it + /// If it's a new question in the DB, restore it if ($restored_questions[$i]->is_new) { - ////We have to recode the parent field - if ($question->parent) { + /// We have to recode the parent field + if ($question->parent && $question->qtype != 'random') { + /// If the parent field needs to be changed, do it here. Random questions are dealt with above. if ($parent = backup_getid($restore->backup_unique_code,"question",$question->parent)) { $question->parent = $parent->new_id; - } elseif ($question->parent = $oldid) { - $question->parent = $newid; + if ($question->parent != $restored_questions[$i]->parent) { + if (!set_field('question', 'parent', $question->parent, 'id', $newid)) { + echo 'Could not update parent '.$question->parent.' for question '.$oldid.'
'; + $status = false; + } + } } else { echo 'Could not recode parent '.$question->parent.' for question '.$oldid.'
'; + $status = false; } }