-
Bug
-
Resolution: Fixed
-
Minor
-
4.1.4, 4.1.5, 4.1.6, 4.2.1, 4.2.2, 4.2.3, 4.3
-
MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
-
MOODLE_402_STABLE, MOODLE_403_STABLE
-
401_check_cached_empty_modnames
-
403_check_cached_empty_modnames
-
master_check_cached_empty_modnames
-
When calling get_module_types_names() in course/lib.php before the modules have been loaded the result is an array of empty arrays which then is stored in a static $modnames.
When after the modules have been installed the method is called again it then will return the cached values which will break things.
To replicate the issue:
Install a MOODLE_403_STABLE instance.
Add the report_editdates plugin from here https://github.com/opitz/moodle-report_editdates/tree/enabling_activities
Run a PHPUnit test with lib/tests/navigation/views/secondary_test.php
You will get an “Undefined property: stdClass::$activitytype” error.
This is because get_module_types_names() is 1st called during the installation of the plugin before any modules are installed. This produces empty arrays are stored in a static variable.
The 2nd call during the finalising process of the installation - after all modules have been installed - will return the static variable instead of the now available values.
To resolve this I suggest to check not only for a null value but also for an empty array before using cached values.
Line 402 of course/lib.php should change from
“if ($modnames === null || $resetcache) {“
to
“if ($modnames === null || empty($modnames[0]) || $resetcache) {”