It turns out that we always had a few courses every year with the following issues:
- the mdl_course_modules.section doesn't match any of the mdl_course_sections.id, not only within the course but anywhere in the database, so the integrity of a course is broken
This year however we created a lot of them. Every year before the semester starts course admins use the backup-restore-copy functionalities to create a new version of the same course from the previous session (so they don't have to start from scratch).
The main symptoms are:
- The course cannot be deleted as it gives an 'invalid course module id' error
- The gradebook could look messy if the 'orphaned' activity is graded. The activity name comes up in the gradebook, but the link is missing (see attached screenshot)
- Sometimes manual or auto enrolment gives the 'invalid course module id' error
I am aware of the solution (use the admin/cli/fix_course_sequence.php script), but I am more curious about the cause of the problem. Why and how did it happen? Has anyone faced the same issue? What should we avoid?
I had a better look at the database and we have had courses like this since 2013, so I guess it is not that rare and probably not related to a certain version, but this year we had 4 times more courses than previously over a decade. That is a significant change. Most of the courses are in 'Grid' course format. We had a lot of 'failed' asynchronous copy tasks. A lot was going on, I could not narrow it down to one bug or one particular thing.
Most recent version history:
- Moodle 4.4.2 (Build: 20240812),
- Moodle 4.4.1+ (Build: 20240809)
With this simple report you can double-check your courses:
SELECT DISTINCT
c.id
FROM
mdl_course_modules AS cm
JOIN
mdl_course AS c ON c.id = cm.course
LEFT JOIN
mdl_course_sections AS cs ON cs.course = cm.course
AND cs.id = cm.section
WHERE
cs.id IS NULL
ORDER BY c.id
Any thoughts?
Thanks