Skip to content

Commit

Permalink
MDL-78082 core_grades: Fix locking issue with natural aggregation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rezaies committed Sep 6, 2023
1 parent a1cf8f1 commit fb3f018
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/grade/constants.php
Expand Up @@ -68,7 +68,7 @@
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);

Expand Down
14 changes: 9 additions & 5 deletions lib/grade/grade_item.php
Expand Up @@ -649,12 +649,16 @@ public function is_locked($userid=NULL) {
*/
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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/upgrade.txt
Expand Up @@ -59,7 +59,7 @@ information provided here is intended especially for developers.
the page displays a heading for the activity (usually a h2 heading containing the activity name).
* New method moodleform::filter_shown_headers() is created to show some expanded headers only and hide the rest.
* count_words() and count_letters() have a new optional parameter called $format to format the text before doing the counting.
* New core_renderer::sr_text method to generate screen reader only inline texts without using html_writter.
* New core_renderer::sr_text method to generate screen reader only inline texts without using html_writer.
* New events \core\event\qbank_plugin_enabled and \core\event\qbank_plugin_disabled are triggered when a qbank plugin is enabled or
disabled respectively, with the plugin's frankenstyle name. Any plugins that need to perform an action in response to a qbank
plugin being enabled or disabled should observe these events.
Expand Down Expand Up @@ -158,6 +158,8 @@ being forced open in all behat tests.
but a subset can be specified instead.
* core/form-autocomplete now supports disabled options in the source select list. These will be displayed in the autocomplete
options with the aria-disabled attribute, and will not be selectable.
* 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 ===

Expand Down

0 comments on commit fb3f018

Please sign in to comment.