MDL-78082 core_grades: Fix locking issue with natural aggregation

Problem:
When the aggregation method is set to "natural," grade items' weights
and the maximum grade of the grade category's item get recalculated,
causing the needsupdate flag to be set to true. As a result, the locking
process was skipped, leading to unexpected behaviour.

Solution:
To address the issue, the set_locked method has been modified. Instead
of skipping the locking process, the method now schedules the locking of
grade items to occur slightly in the past, specifically one second in
the past. This ensures that the grade item will be automatically locked
after the recalculations are completed.

Explanation:
By making this adjustment, we ensure that the locking process is not
skipped during natural aggregation, maintaining consistent behaviour and
preventing any unintended consequences related to grade item locking.
This commit is contained in:
Shamim Rezaie
2023-09-07 05:50:09 +10:00
parent 314350afee
commit 475f617659
3 changed files with 12 additions and 6 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ define('GRADE_AGGREGATE_WEIGHTED_MEAN2', 11);
define('GRADE_AGGREGATE_EXTRACREDIT_MEAN', 12);
/**
* GRADE_AGGREGATE_WEIGHTED_MEAN2 - Use Natural in the category for grade aggregation.
* GRADE_AGGREGATE_SUM - Use Natural in the category for grade aggregation.
*/
define('GRADE_AGGREGATE_SUM', 13);
+9 -5
View File
@@ -649,12 +649,16 @@ class grade_item extends grade_object {
*/
public function set_locked($lockedstate, $cascade=false, $refresh=true) {
if ($lockedstate) {
/// setting lock
if ($this->needsupdate) {
return false; // can not lock grade without first having final grade
// Setting lock.
if (empty($this->id)) {
return false;
} else if ($this->needsupdate) {
// Can not lock grade without first having final grade,
// so we schedule it to be locked as soon as regrading is finished.
$this->locktime = time() - 1;
} else {
$this->locked = time();
}
$this->locked = time();
$this->update();
if ($cascade) {
+2
View File
@@ -12,6 +12,8 @@ information provided here is intended especially for developers.
* New \core\output\activity_header::get_heading_level() method to get the heading level for a given heading level depending whether
the page displays a heading for the activity (usually a h2 heading containing the activity name).
* count_words() and count_letters() have a new optional parameter called $format to format the text before doing the counting.
* The method grade_item::set_locked() now returns true if the grade item needs to be updated. The method schedules the locking of
the grade item once the recalculations are completed. (This was fixed in 4.3, 4.2.2)
=== 4.2.1 ===
* Added a new parameter in address_in_subnet to give us the ability to check for 0.0.0.0 or not.