When a user deletes a Course Module, the deletioninprogress field for that course module is set to 1 in the database, and an Ad Hoc task is scheduled to actually do the deletion. If that Ad Hoc task fails to run, then the Course Module is never deleted. I.e. there is no clean-up process which picks up on Course Modules in this state and deletes them.
In our case, we know why the Ad Hoc tasks failed (we were having some problems with server load), but having resolved that issue, the Course Modules which were scheduled for deletion while we were having those issues, are now stuck in limbo.
A bit of description of what is happening behind the scene:
- When deleting a module, this triggers the course_delete_module with the async = true parameter
- This then creates a task core_course\task\course_delete_modules
- The task is ran once (if an exception arise, the module is not delete) and calls course_delete_module() which does the deletion non asynchronously (on the spot)