MDL-55707 grades: Stop infinite loop when regrading.
authorAdrian Greeve <adrian@moodle.com>
Wed, 31 Aug 2016 01:50:17 +0000 (09:50 +0800)
committerAdrian Greeve <adrian@moodle.com>
Thu, 1 Sep 2016 02:25:13 +0000 (10:25 +0800)
lib/grade/grade_item.php
lib/gradelib.php

index 229571e..79db698 100644 (file)
@@ -680,7 +680,8 @@ class grade_item extends grade_object {
     }
 
     /**
-     * Mark regrading as finished successfully.
+     * Mark regrading as finished successfully. This will also be called when subsequent regrading will not change any grades.
+     * Situations such as an error being found will still result in the regrading being finished.
      */
     public function regrading_finished() {
         global $DB;
index b790626..967340a 100644 (file)
@@ -382,7 +382,17 @@ function grade_regrade_final_grades_if_required($course, callable $callback = nu
         echo $OUTPUT->header();
         echo $OUTPUT->heading(get_string('recalculatinggrades', 'grades'));
         $progress = new \core\progress\display(true);
-        grade_regrade_final_grades($course->id, null, null, $progress);
+        $status = grade_regrade_final_grades($course->id, null, null, $progress);
+
+        // Show regrade errors and set the course to no longer needing regrade (stop endless loop).
+        if (is_array($status)) {
+            foreach ($status as $error) {
+                $errortext = new \core\output\notification($error, \core\output\notification::NOTIFY_ERROR);
+                echo $OUTPUT->render($errortext);
+            }
+            $courseitem = grade_item::fetch_course_item($course->id);
+            $courseitem->regrading_finished();
+        }
 
         if ($callback) {
             //