From: tjhunt Date: Fri, 9 May 2008 15:10:39 +0000 (+0000) Subject: MDL-14750 - Multianswer questions get broken by backup and restore becuase question... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9ade28e57e0fde0da2e05f4f2d314b84f3c656dc;p=moodle.git MDL-14750 - Multianswer questions get broken by backup and restore becuase question->parent is not recoded properly in the database. This commit also fixes a regression introduced by the fix for MDL-5482. --- diff --git a/question/restorelib.php b/question/restorelib.php index 678a785e91..de606e423d 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -392,11 +392,9 @@ // Fixing bug #5482: random questions have parent field set to its own id, // see: $QTYPES['random']->get_question_options() - if ($question->qtype == 'random') { - $question->parent = $newid; - //we have to update the random question if the question has been inserted - if ($creatingnewquestion && $newid) - $status = set_field('question', 'parent', $question->parent, 'id', $newid); + if ($question->qtype == 'random' && $creatingnewquestion) { + $question->parent = $question->id; + $status = set_field('question', 'parent', $question->parent, 'id', $question->id); } //Save newid to backup tables @@ -427,17 +425,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; } }