MDL-68618 mod_forum: stop reverting idnumber when updating instance.
authorPaul Holden <paulh@moodle.com>
Tue, 5 May 2020 22:12:42 +0000 (23:12 +0100)
committerPaul Holden <paulh@moodle.com>
Mon, 10 Aug 2020 08:11:12 +0000 (09:11 +0100)
mod/forum/classes/grades/forum_gradeitem.php
mod/forum/lib.php

index 42b1421..0094e57 100644 (file)
@@ -265,9 +265,12 @@ class forum_gradeitem extends component_gradeitem {
 
         $DB->update_record($this->get_table_name(), $grade);
 
-        // Update in the gradebook.
+        // Update in the gradebook (note that 'cmidnumber' is required in order to update grades).
         $mapper = forum_container::get_legacy_data_mapper_factory()->get_forum_data_mapper();
-        forum_update_grades($mapper->to_legacy_object($this->forum), $grade->userid);
+        $forumrecord = $mapper->to_legacy_object($this->forum);
+        $forumrecord->cmidnumber = $this->forum->get_course_module_record()->idnumber;
+
+        forum_update_grades($forumrecord, $grade->userid);
 
         return true;
     }
index e146293..79cc80f 100644 (file)
@@ -808,13 +808,13 @@ function forum_print_recent_activity($course, $viewfullnames, $timestart) {
 function forum_update_grades($forum, $userid = 0): void {
     global $CFG, $DB;
     require_once($CFG->libdir.'/gradelib.php');
-    $cm = get_coursemodule_from_instance('forum', $forum->id);
-    $forum->cmidnumber = $cm->idnumber;
 
     $ratings = null;
     if ($forum->assessed) {
         require_once($CFG->dirroot.'/rating/lib.php');
 
+        $cm = get_coursemodule_from_instance('forum', $forum->id);
+
         $rm = new rating_manager();
         $ratings = $rm->get_user_grades((object) [
             'component' => 'mod_forum',