-
Bug
-
Resolution: Fixed
-
Minor
-
2.6.4, 2.7.1
-
MOODLE_26_STABLE, MOODLE_27_STABLE
-
MOODLE_26_STABLE, MOODLE_27_STABLE
-
master_
MDL-47076 -
If you back up a course including badges, then restore it and the usercreator of the badge doesn't match a user in the system it gets set to 0. I would expect it to default to the user restoring the course (ie $USER->id), it being 0 causes issues if it tries to send messages to notify the creator about the badge being awarded.
Steps to replicate:
1) Create a user and give them a sitewide role like site manager
2) Create a course
3) Log in as the user and create a badge within that course
- Make sure it has a criteria (manual issue by role is probably the easiest)
- Set notify badge creator to everytime on the messages tab
4) Activate the badge
5) Backup the course making sure that users and badges are ticked
6) Download the backup file and upload to a course where no user matches the creator id (or delete the creator from the mdl_user table manually)
7) Restore the course (including the badge) into a new course
8) Check in the database, the creator id of the restored badge will be 0
9) Create a learner, enrol them in the course, and award them the badge
10) Run the cron, you will get the invalid user error below when it tries to send the creator a notification about the badge being awarded.
Default exception handler: Invalid user Debug: SELECT * FROM
{user} WHERE id = ?
[array (
0 => '0',
)]
Error code: invaliduser
- line 1411 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
- line 1387 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
- line 129 of /badges/cron.php: call to moodle_database->get_record()
- line 108 of /badges/cron.php: call to badge_assemble_notification()
- line 35 of /badges/cron.php: call to badge_message_cron()
- line 545 of /lib/cronlib.php: call to badge_cron()
- line 61 of /admin/cli/cron.php: call to cron_run()
!!! Invalid user !!!