willianmano / moodle-theme_moove

A Moodle Boost child theme
GNU General Public License v3.0
175 stars 157 forks source link

Fix profile page loading when userid parameter is missing #385

Closed ijuanfe closed 2 years ago

ijuanfe commented 2 years ago

This will fix the issue https://github.com/willianmano/moodle-theme_moove/issues/382 as well as any profile page loading when the userid parameter is missing or is equal to 0.

Another example where you can reproduce this bug is when a user is looking at his/her profile page and wants to change the language through the user menu. After clicking on any language it will redirect to an URL where the userid is equal to 0 (E.g. https://[somedomain]/moodle400/user/profile.php?**id=0**&lang=es).

This error happens because the call to the function get_record() in this line https://github.com/willianmano/moodle-theme_moove/blob/aa2b9f0acf36bd47d5dc802935819b765ea39cf3/layout/mypublic.php#L32 will throw a Moodle exception after trying to get a record where a userid is equal to 0, but there is none.

You can take a look exactly to where this Moodle exception happens as the function is called with the parameter MUST_EXIST here: https://github.com/moodle/moodle/blob/bcd0bdaf513fc76213c04bd581f6afd430b32fb4/lib/dml/moodle_database.php#L1673