- Log in as admin and go to a course.
- Add a URL activity to a course, for example https:///duckduckgo.com
- Make sure you don't get any errors.
- Purge caches and go to course page.
- Make sure you are able to see the course content.
HQ Team International CIH2-212
The usage of moodle_url in the function url_guess_icon of mod/url/locallib.php that was introduced with
MDL-39324 causes in some circumstances an error causing course/view.php not to be reachable anymore.
Steps to reproduce the problem in the branch MOODLE_311_STABLE release 3.11.4, theme boost:
- add a mod url to a course with an external url, for example https://mypage.com. The display type is not relevant.
- edit the activity changing the external url so that the php function parse_url will return false, for example adding a third / after the protocol: https:///mypage.com and save (notice that at the present, trying to add the problematic url straight away will not work, but it was not so in the past).
- purge all caches and visit course/view.php.
- confirm that one obtains this error and stack trace:
Error code: invalidurl
line 362 of /lib/weblib.php: moodle_exception thrown
line 574 of /mod/url/locallib.php: call to moodle_url->__construct()
line 223 of /mod/url/lib.php: call to url_guess_icon()
line 477 of /course/lib.php: call to url_get_coursemodule_info()
line 670 of /lib/modinfolib.php: call to get_array_of_activities()
line 462 of /lib/modinfolib.php: call to course_modinfo::inner_build_course_cache()
line 417 of /lib/modinfolib.php: call to course_modinfo->__construct()
line 2204 of /lib/modinfolib.php: call to course_modinfo::instance()
line 2050 of /lib/navigationlib.php: call to get_fast_modinfo()
line 2114 of /lib/navigationlib.php: call to global_navigation->generate_sections_and_activities()
line 502 of /course/format/lib.php: call to global_navigation->load_generic_course_sections()
line 168 of /course/format/topics/lib.php: call to format_base->extend_course_navigation()
line 2029 of /lib/navigationlib.php: call to format_topics->extend_course_navigation()
line 1395 of /lib/navigationlib.php: call to global_navigation->load_course_sections()
line 3503 of /lib/navigationlib.php: call to global_navigation->initialise()
line 3548 of /lib/navigationlib.php: call to navbar->has_items()
line 4566 of /lib/outputrenderers.php: call to navbar->get_items()
line 44 of /theme/boost/layout/columns2.php: call to core_renderer->region_main_settings_menu()
line 1396 of /lib/outputrenderers.php: call to include()
line 1326 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
line 246 of /course/edit.php: call to core_renderer->header()
The reason appears to be that the function url_guess_icon is called when executing course_modinfo::inner_build_course_cache(). This happens for example when loading course/view.php after having emptied all caches. When the url is such that the php function parse_url returns false (for example in the case that the url starts with http:///) an exception is thrown in the constructor of moodle_url and this causes the course to be completely inaccessible.
Notice that because of the guard if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') in line 568 of url_guess_icon in /mod/url/locallib.php nothing bad will happen, if the url ends with a / - in our example https:///mypage.com/ will not cause any trouble.
What happened in our site was, that courses created in the past with malformed external urls in some mod_url activities where not accessible anymore after updating.