-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
3.9.25, 4.1.9, 4.2.6, 4.3.3, 4.4
-
MOODLE_39_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
Analytics models with context restrictions are displaying errors if the linked course or course category is deleted. This appears to be happening because a false bool is being returned instead of the context, which is not properly handled and causing multiple errors.
The most obvious error is when trying to edit the analytics model, which will fail with the Exception - Call to a member function get_context_name() on bool. The "Invalid site elements" page and the train scheduled task can also fail due to incorrect number of query parameters if the model and/or context is fully set up.
The following steps replicate this for a course category context, but the same can be done with a course.
- Create a new course category (Site Administration -> Courses -> Add a category)
- Go to analytics models page (Site Administration -> General -> Analytics -> Analytics Models)
- Open the edit page for an analytics model that can use context restrictions such as "Students who have not accessed the course yet"
- Add the newly created course category as a context and click save changes. If you try to edit the analytics model at this point it will work.
- Go to course management (Site Administration -> Courses -> Manage courses and categories)
- Delete the course category that was added to the analytics model
- Go back to analytics models page (Site Administration -> General -> Analytics -> Analytics models)
- Attempt to open the edit page for the analytics model you've been using. You will get an Exception - Call to a member function get_context_name() on bool
These steps alone aren't enough to replicate the incorrect number of query parameters error on the "Invalid site elements" page or train scheduled task (unsure on exact requirements to replicate), but these are caused by the same issue and when debugging is enabled these still display a warning "Attempt to read property "id" on bool".
I suspect that the main solution here is to filter out 'false' contexts in core_analytics\model\get_contexts(), but deleted contextids in the analytics_models table should also be cleaned up as part of the analytics cleanup task.