Skip to content

Commit

Permalink
MDL-55707 grades: Stop infinite loop when regrading.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Sep 1, 2016
1 parent 35d5053 commit 93d3f31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ public function has_hidden_grades($groupsql="", array $params=null, $groupwheres
}

/**
* 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;
Expand Down
12 changes: 11 additions & 1 deletion lib/gradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
//
Expand Down

0 comments on commit 93d3f31

Please sign in to comment.