Merge branch 'MDL-29854_b' of git://github.com/timhunt/moodle
authorAparup Banerjee <aparup@moodle.com>
Wed, 26 Oct 2011 03:23:09 +0000 (11:23 +0800)
committerAparup Banerjee <aparup@moodle.com>
Wed, 26 Oct 2011 03:23:09 +0000 (11:23 +0800)
lang/en/question.php
mod/quiz/processattempt.php
question/preview.php

index 7b73533..c963b3e 100644 (file)
@@ -135,7 +135,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';
index 7c25b7a..4ec7afe 100644 (file)
@@ -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();
index 2dc5755..e027be6 100644 (file)
@@ -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 {
+
+        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);
     }
 }