From: tjhunt Date: Wed, 19 Dec 2007 12:11:03 +0000 (+0000) Subject: MDL-12647 - Moving multiple_choice questions between contexts breaks them. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9088c6e2e4daaea5a8f83bebced3dea93eb248e4;p=moodle.git MDL-12647 - Moving multiple_choice questions between contexts breaks them. There was a subtle interaction between get_question_options and replace_file_links for this question type. Merged from MOODLE_19_STABLE. --- diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index ddd3622b38..92f5dfbc15 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -641,13 +641,18 @@ class question_multichoice_qtype extends default_questiontype { function replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination){ parent::replace_file_links($question, $fromcourseid, $tocourseid, $url, $destination); // replace links in the question_match_sub table. + // We need to use a separate object, because in load_question_options, $question->options->answers + // is changed from a comma-separated list of ids to an array, so calling update_record on + // $question->options stores 'Array' in that column, breaking the question. $optionschanged = false; - $question->options->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); - $question->options->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); - $question->options->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); + $newoptions = new stdClass; + $newoptions->id = $question->options->id; + $newoptions->correctfeedback = question_replace_file_links_in_html($question->options->correctfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); + $newoptions->partiallycorrectfeedback = question_replace_file_links_in_html($question->options->partiallycorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); + $newoptions->incorrectfeedback = question_replace_file_links_in_html($question->options->incorrectfeedback, $fromcourseid, $tocourseid, $url, $destination, $optionschanged); if ($optionschanged){ - if (!update_record('question_multichoice', addslashes_recursive($question->options))) { - error('Couldn\'t update \'question_multichoice\' record '.$question->options->id); + if (!update_record('question_multichoice', addslashes_recursive($newoptions))) { + error('Couldn\'t update \'question_multichoice\' record '.$newoptions->id); } } $answerchanged = false;