MDL-85721 qtype: Cope with missing options records

If we restore a question (or any other) which has had its
qtype_xxx_options record deleted, we get a notification output when we
try to build the options.

This may be called from an AJAX request (such as when we duplicate a
quiz), and outputting the notification breaks the AJAX response.
Returning false also means we don't get the answers attached to the
questiondata options, so the structure doesn't match the restored data,
and we get duplication.

This emits the errors via debugging instead, which allows it to be
supressed or logged, and allows get_question_options() to continue
running.
This commit is contained in:
Mark Johnson
2025-07-01 11:52:48 +01:00
parent 4f196b4671
commit 0105cdb0de
2 changed files with 93 additions and 6 deletions
+4 -6
View File
@@ -904,7 +904,7 @@ class question_type {
* specific information (it is passed by reference).
*/
public function get_question_options($question) {
global $DB, $OUTPUT;
global $DB;
if (!isset($question->options)) {
$question->options = new stdClass();
@@ -921,9 +921,8 @@ class question_type {
$question->options->$field = $extra_data->$field;
}
} else {
echo $OUTPUT->notification('Failed to load question options from the table ' .
debugging('Failed to load question options from the table ' .
$question_extension_table . ' for questionid ' . $question->id);
return false;
}
}
@@ -938,9 +937,8 @@ class question_type {
WHERE qa.question = ?
ORDER BY qa.id", array($question->id));
if (!$answers) {
echo $OUTPUT->notification('Failed to load question answers from the table ' .
$answerextensiontable . 'for questionid ' . $question->id);
return false;
debugging('Failed to load question answers from the table ' .
$answerextensiontable . ' for questionid ' . $question->id);
}
} else {
// Don't check for success or failure because some question types do