-
Bug
-
Resolution: Fixed
-
Minor
-
4.1.6, 4.2.3, 4.3, 4.3.3, 4.4
-
2
-
HQ 2024 Sprint I2.2 Moppies
In MDL-58266, a new course module view tracking table was added. But in some cases, a viewed entry can be added, even when it shouldn't be. Specifically if completion_info->update_state() is called some cases.
To recreate:
- Have a course with some students in it.
- Create an activity in that course with some form of activity completion enabled (it doesn't have to be 'viewed').
- Look in the course_modules_viewed table for the course module you just created, and confirm it has no records in it for your test user(s).
- In the activity completion report, mark the activity as complete for a user.
- If you inspect the DB again, still won't see a viewed record.
- Now, for that same user, click to un-complete that activity for the user.
- Now if you check in the database, you will see that the user got a 'viewed' record added, even though that user never viewed the completion.
This specifically seems to happen when update_state() is called, and the user has a module completion record, but it is not in a complete state. From what I can tell, this is all because completion_info->get_completion_data() added in MDL-5826. It seems to assume that a user can't have a completion state in an activity if they haven't viewed it - so if they do have a completion state (whether completed or not), they must have viewed it, which is incorrect.
Basically, the first part of the query will return a row if there is a course_modules_completion has a record in it - even if no viewed record is present. And the function then assumes if a row was returned from that statement, then it must have been viewed - rather than checking the actual returned value. That viewed = 1 then gets gets passed to internal_set_data(), which creates the viewed record, because it doesn't exist.
I haven't tested it, but I'm pretty sure the line:
$data->viewed = 1; |
Needs to be replaced with something like:
$data->viewed = empty($data->cmvuserid) ? 0 : 1; |
(and moving the unsets down).
Note that while the given example above is somewhat niche, I found this while digging into an issue in reset code found in Moodle Workplace.
- is a regression caused by
-
MDL-58266 "Student must view this activity to complete it" should be written to database
- Closed