-
Bug
-
Resolution: Fixed
-
Critical
-
2.8.7
-
MOODLE_28_STABLE
-
MOODLE_28_STABLE, MOODLE_29_STABLE
-
wip-
MDL-51552-master -
Here are the steps to reproduce the bug.
1. Go to https://moodle.org/demo/
2. Select "Moodle sandbox"
3. Log in as admin
4. Pick a course
5. Enroll as many students as possible (you can probably do four without adding users). Make sure they are "students".
6. Go to Grade Setup "Categories and Items"
7. Create a manual item (Grade type=value)
8. Go to Single View and select the manual item you just created
9. Add "&perpage=2" to the URL and refresh the page (if the parameter is already there, change "&perpage=100" to "&perpage=2")
10. Make sure you get the pagination.
11. Go to the second page and add a grade (i.e. 20) to a student. Save.
12. Go back to the first page and check "Perform bulk insert" for empty grades and hit Save.
13. Go back to the second page and confirm that the previously entered grade, 20, has been overwritten by 0.
Potential cause and solution:
On 2.5, when you save a grade for a manual item, Moodle saves the value in both "rawgrade" and "finalgrade" columns in grade_grades table.
On 2.8, Moodle only saves the value in the "finalgrade" column.
The bulk execution code can be found in the process() function on \grade\report\singleview\classes\local\screen\grade.php.
When the user hits "save" from the single view, the parameter values on the page (the new grades on the page) are sent to the server. However, the students' grades on the subsequent pages are not sent to the server as parameters.
In the process(), if the bulk insert is checked and the student's grade cannot be found in the parameters, it fetches the existing grade from the database and stores it to $grade. (line #338)
Then, it examines whether or not the override flag is there. If the flag is not there, it checks whether or not the rawgrade exists in $grade (this is the PROBLEM! line #349).
If rawgrade is not set, it creates an entry with an empty grade, and add it to a list of parameters. Then later on, the bulk insert happens for the empty grades.
Because Moodle does not use the rawgrade column to store grade values for the manual items any more, we need to modify line #349 to process grades differently for Manual items.
Here is what I suggest.
if (empty($data->$oldoverride)) {
if($gradeitem->itemtype == 'manual')
else
{ $data->$field = (!isset($grade->rawgrade)) ? $null : $grade->rawgrade; }}