Skip to content

Commit

Permalink
Merge branch 'MDL-76956-m401' of https://github.com/sammarshallou/moodle
Browse files Browse the repository at this point in the history
 into MOODLE_401_STABLE
  • Loading branch information
junpataleta committed Feb 28, 2023
2 parents bef0d51 + 40081f5 commit b8a8581
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion lib/grade/grade_category.php
Expand Up @@ -472,9 +472,10 @@ public function pre_regrade_final_grades() {
* 4. Save them in final grades of associated category grade item
*
* @param int $userid The user ID if final grade generation should be limited to a single user
* @param \core\progress\base|null $progress Optional progress indicator
* @return bool
*/
public function generate_grades($userid=null) {
public function generate_grades($userid=null, ?\core\progress\base $progress = null) {
global $CFG, $DB;

$this->load_grade_item();
Expand Down Expand Up @@ -565,6 +566,12 @@ public function generate_grades($userid=null) {
if ($this->grade_item->id == $grade->itemid) {
$oldgrade = $grade;
}

if ($progress) {
// Incrementing the progress by nothing causes it to send an update (once per second)
// to the web browser so as to prevent the connection timing out.
$progress->increment_progress(0);
}
}
$this->aggregate_grades($prevuser,
$items,
Expand Down
11 changes: 9 additions & 2 deletions lib/grade/grade_item.php
Expand Up @@ -781,9 +781,10 @@ public function regrading_finished() {
* because the regrading must be done in correct order!!
*
* @param int $userid Supply a user ID to limit the regrading to a single user
* @param \core\progress\base|null $progress Optional progress object, will be updated per user
* @return bool true if ok, error string otherwise
*/
public function regrade_final_grades($userid=null) {
public function regrade_final_grades($userid=null, ?\core\progress\base $progress = null) {
global $CFG, $DB;

// locked grade items already have correct final grades
Expand All @@ -808,7 +809,7 @@ public function regrade_final_grades($userid=null) {
// aggregate category grade item
$category = $this->load_item_category();
$category->grade_item =& $this;
if ($category->generate_grades($userid)) {
if ($category->generate_grades($userid, $progress)) {
return true;
} else {
return "Could not aggregate final grades for category:".$this->id; // TODO: improve and localize
Expand Down Expand Up @@ -837,6 +838,12 @@ public function regrade_final_grades($userid=null) {
foreach ($rs as $grade_record) {
$grade = new grade_grade($grade_record, false);

// Incrementing the progress by nothing causes it to send an update (once per second)
// to the web browser so as to prevent the connection timing out.
if ($progress) {
$progress->increment_progress(0);
}

if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
// this grade is locked - final grade must be ok
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/gradelib.php
Expand Up @@ -1275,7 +1275,7 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null,
}

// Let's update, calculate or aggregate.
$result = $grade_items[$gid]->regrade_final_grades($userid);
$result = $grade_items[$gid]->regrade_final_grades($userid, $progress);

if ($result === true) {

Expand Down

0 comments on commit b8a8581

Please sign in to comment.