From: pichetp Date: Tue, 20 Nov 2007 03:48:29 +0000 (+0000) Subject: Solving MDL-12063 qtype_questions where left orphans when questions whe deleted or X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e9028ffc8715bc64cc634f0b3a5c2b73eb5c8d5b;p=moodle.git Solving MDL-12063 qtype_questions where left orphans when questions whe deleted or qtype change --- diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index fc65b95c0a..bef538b231 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -74,6 +74,24 @@ class embedded_cloze_qtype extends default_questiontype { // if we still have some old wrapped question ids, reuse the next of them if ($oldwrappedid = array_shift($oldwrappedids)) { $wrapped->id = $oldwrappedid; + // + $oldqtype = get_field('question', 'qtype', 'id',$oldwrappedid) ; + if($oldqtype != $wrapped->qtype ) { + echo "

oldqtype $oldqtype newqtype".$wrapped->qtype."

"; + switch ($oldqtype) { + case 'multichoice': + delete_records('question_multichoice', 'question', $oldwrappedid); + break; + case 'shortanswer': + delete_records('question_shortanswer', 'question', $oldwrappedid); + break; + case 'numerical': + delete_records('question_numerical', 'question', $oldwrappedid); + break; + default: + error("questiontype $wrapped->qtype not recognized"); + } + } } $wrapped->name = $question->name; $wrapped->parent = $question->id; @@ -85,8 +103,9 @@ class embedded_cloze_qtype extends default_questiontype { // Delete redundant wrapped questions if(is_array($oldwrappedids) && count($oldwrappedids)){ - $oldwrappedids = implode(',', $oldwrappedids); - delete_records_select('question', "id IN ($oldwrappedids)"); + foreach ($oldwrappedids as $id) { + delete_question($id) ; + } } if (!empty($sequence)) {