diff --git a/lang/en/question.php b/lang/en/question.php index ba1bd4bdbdd..d86dcbed9f9 100644 --- a/lang/en/question.php +++ b/lang/en/question.php @@ -133,7 +133,7 @@ $string['errormovingquestions'] = 'Error while moving questions with ids {$a}.'; $string['errorpostprocess'] = 'Error occurred during post-processing!'; $string['errorpreprocess'] = 'Error occurred during pre-processing!'; $string['errorprocess'] = 'Error occurred during processing!'; -$string['errorprocessingresponses'] = 'An error occurred while processing your responses.'; +$string['errorprocessingresponses'] = 'An error occurred while processing your responses ({$a}). Click continue to return to the page you were on and try again.'; $string['errorsavingcomment'] = 'Error saving the comment for question {$a->name} in the database.'; $string['errorupdatingattempt'] = 'Error updating attempt {$a->id} in the database.'; $string['exportcategory'] = 'Export category'; diff --git a/mod/quiz/processattempt.php b/mod/quiz/processattempt.php index 7c25b7a8f0d..4ec7afe5b53 100644 --- a/mod/quiz/processattempt.php +++ b/mod/quiz/processattempt.php @@ -94,10 +94,22 @@ if (!$finishattempt) { // Just process the responses for this page and go to the next page. try { $attemptobj->process_all_actions($timenow); + } catch (question_out_of_sequence_exception $e) { print_error('submissionoutofsequencefriendlymessage', 'question', $attemptobj->attempt_url(null, $thispage)); + + } catch (Exception $e) { + // This sucks, if we display our own custom error message, there is no way + // to display the original stack trace. + $debuginfo = ''; + if (!empty($e->debuginfo)) { + $debuginfo = $e->debuginfo; + } + print_error('errorprocessingresponses', 'question', + $attemptobj->attempt_url(null, $thispage), $e->getMessage(), $debuginfo); } + $transaction->allow_commit(); redirect($nexturl); } @@ -110,7 +122,23 @@ add_to_log($attemptobj->get_courseid(), 'quiz', 'close attempt', $attemptobj->get_quizid(), $attemptobj->get_cmid()); // Update the quiz attempt record. -$attemptobj->finish_attempt($timenow); +try { + $attemptobj->finish_attempt($timenow); + +} catch (question_out_of_sequence_exception $e) { + print_error('submissionoutofsequencefriendlymessage', 'question', + $attemptobj->attempt_url(null, $thispage)); + +} catch (Exception $e) { + // This sucks, if we display our own custom error message, there is no way + // to display the original stack trace. + $debuginfo = ''; + if (!empty($e->debuginfo)) { + $debuginfo = $e->debuginfo; + } + print_error('errorprocessingresponses', 'question', + $attemptobj->attempt_url(null, $thispage), $e->getMessage(), $debuginfo); +} // Send the user to the review page. $transaction->allow_commit(); diff --git a/question/preview.php b/question/preview.php index 2dc57555937..e027be67f0f 100644 --- a/question/preview.php +++ b/question/preview.php @@ -82,13 +82,18 @@ if ($previewid) { if (!isset($SESSION->question_previews[$previewid])) { print_error('notyourpreview', 'question'); } + try { $quba = question_engine::load_questions_usage_by_activity($previewid); + } catch (Exception $e) { + // This may not seem like the right error message to display, but + // actually from the user point of view, it makes sense. print_error('submissionoutofsequencefriendlymessage', 'question', question_preview_url($question->id, $options->behaviour, $options->maxmark, $options, $options->variant, $context), null, $e); } + $slot = $quba->get_first_question_number(); $usedquestion = $quba->get_question($slot); if ($usedquestion->id != $question->id) { @@ -140,48 +145,57 @@ $actionurl = question_preview_action_url($question->id, $quba->get_id(), $option // Process any actions from the buttons at the bottom of the form. if (data_submitted() && confirm_sesskey()) { - if (optional_param('restart', false, PARAM_BOOL)) { - restart_preview($previewid, $question->id, $options, $context); - } else if (optional_param('fill', null, PARAM_BOOL)) { - $correctresponse = $quba->get_correct_response($slot); - $quba->process_action($slot, $correctresponse); + try { - $transaction = $DB->start_delegated_transaction(); - question_engine::save_questions_usage_by_activity($quba); - $transaction->allow_commit(); + if (optional_param('restart', false, PARAM_BOOL)) { + restart_preview($previewid, $question->id, $options, $context); - redirect($actionurl); + } else if (optional_param('fill', null, PARAM_BOOL)) { + $correctresponse = $quba->get_correct_response($slot); + $quba->process_action($slot, $correctresponse); - } else if (optional_param('finish', null, PARAM_BOOL)) { - try { + $transaction = $DB->start_delegated_transaction(); + question_engine::save_questions_usage_by_activity($quba); + $transaction->allow_commit(); + + redirect($actionurl); + + } else if (optional_param('finish', null, PARAM_BOOL)) { $quba->process_all_actions(); - } catch (question_out_of_sequence_exception $e) { - print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl); - } - $quba->finish_all_questions(); + $quba->finish_all_questions(); - $transaction = $DB->start_delegated_transaction(); - question_engine::save_questions_usage_by_activity($quba); - $transaction->allow_commit(); - redirect($actionurl); + $transaction = $DB->start_delegated_transaction(); + question_engine::save_questions_usage_by_activity($quba); + $transaction->allow_commit(); + redirect($actionurl); - } else { - try { + } else { $quba->process_all_actions(); - } catch (question_out_of_sequence_exception $e) { - print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl); + + $transaction = $DB->start_delegated_transaction(); + question_engine::save_questions_usage_by_activity($quba); + $transaction->allow_commit(); + + $scrollpos = optional_param('scrollpos', '', PARAM_RAW); + if ($scrollpos !== '') { + $actionurl->param('scrollpos', (int) $scrollpos); + } + redirect($actionurl); } - $transaction = $DB->start_delegated_transaction(); - question_engine::save_questions_usage_by_activity($quba); - $transaction->allow_commit(); + } catch (question_out_of_sequence_exception $e) { + print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl); - $scrollpos = optional_param('scrollpos', '', PARAM_RAW); - if ($scrollpos !== '') { - $actionurl->param('scrollpos', (int) $scrollpos); + } catch (Exception $e) { + // This sucks, if we display our own custom error message, there is no way + // to display the original stack trace. + $debuginfo = ''; + if (!empty($e->debuginfo)) { + $debuginfo = $e->debuginfo; } - redirect($actionurl); + print_error('errorprocessingresponses', 'question', $actionurl, + $e->getMessage(), $debuginfo); } }