From 93d3f310b06bf5a5035dc0b2ee291eba4caed1f3 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Wed, 31 Aug 2016 09:50:17 +0800 Subject: [PATCH] MDL-55707 grades: Stop infinite loop when regrading. --- lib/grade/grade_item.php | 3 ++- lib/gradelib.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 229571e4eb0..79db6985143 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -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; diff --git a/lib/gradelib.php b/lib/gradelib.php index b7906269e36..967340a5723 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -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) { //