Skip to content

Commit

Permalink
MDL-29854 questions: display better message and more useful continue
Browse files Browse the repository at this point in the history
when an error occurs in the middle of processing responeses.
  • Loading branch information
timhunt authored and Aparup Banerjee committed Oct 26, 2011
1 parent 5c6ec45 commit 21c5b22
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lang/en/question.php
Expand Up @@ -133,7 +133,7 @@
$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';
Expand Down
30 changes: 29 additions & 1 deletion mod/quiz/processattempt.php
Expand Up @@ -94,10 +94,22 @@
// 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);
}
Expand All @@ -110,7 +122,23 @@
$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();
Expand Down
74 changes: 44 additions & 30 deletions question/preview.php
Expand Up @@ -82,13 +82,18 @@
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) {
Expand Down Expand Up @@ -140,48 +145,57 @@

// 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 {

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);

$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();

redirect($actionurl);
redirect($actionurl);

} else if (optional_param('finish', null, PARAM_BOOL)) {
try {
} 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);
}
}

Expand Down

0 comments on commit 21c5b22

Please sign in to comment.