Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 3.1.5, 3.2, 3.3
-
Component/s: Badges
-
Testing Instructions:
-
Difficulty:Easy
-
Affected Branches:MOODLE_31_STABLE, MOODLE_32_STABLE, MOODLE_33_STABLE
-
Fixed Branches:MOODLE_32_STABLE, MOODLE_33_STABLE
-
Pull from Repository:
-
Pull Master Branch:
MDL-59049-master -
Pull Master Diff URL:
-
Sprint:3.4 Sprint 4
Description
If you have badges on a course which are driven by activity completion criteria, which are awarded to users, then later on the course is deleted, the badge remains on their profile, but when you click on it, you get a fatal error "Can not find data record in database".
Steps:
- Add activity completion to an activity on a Moodle course
- Create a new badge and set the criteria to require completion of that activity
- Enable the badge
- Have a student complete the activity and be awarded the badge
- Delete the course
- Visit the student's profile
- Click on the badge from the deleted course
Can not find data record in database.
More information about this error
Debug info: SELECT c.id, c.enablecompletion, c.cacherev, c.startdate
FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
WHERE b.id = :badgeid
[array (
'badgeid' => '2562',
)]
Error code: invalidrecordunknown
The problem lies in line 49 of /badges/criteria/award_criteria_activity.php:
$this->course = $DB->get_record_sql('SELECT c.id, c.enablecompletion, c.cacherev, c.startdate |
FROM {badge} b INNER JOIN {course} c ON b.courseid = c.id
|
WHERE b.id = :badgeid ', array('badgeid' => $this->badgeid), MUST_EXIST); |
The "MUST_EXIST" flag causes the error, since the course no longer exists.
For our Moodle i've removed that flag, but I don't know if you want to come up with a different way around it for the core badges code, if you really need the MUST_EXIST flag.