-
Bug
-
Resolution: Fixed
-
Major
-
2.3.7, 2.4.4, 2.5, 2.6
-
MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
-
MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
-
MDL-39932_master -
When mapping feedback to a course, an error will be received if a course is deleted that happens to have the same id as that of the row in the feedback_sitecourse_map table.
Steps to reproduce:
1. Start with a fresh Moodle install.
2. Create 2 courses (any format)
3. Delete the first course (where courseid = 1)
4. Create a Feedback Module
5. Select "Map feedback to courses" then search and map to the 2nd course
6. After 'mapping' has completed (i.e. the page refreshes), this error will appear:
"Can not find data record in database table course."
|
|
Debugging trace:
|
Debug info: SELECT id,category FROM {course} WHERE id = ?
|
[array (
|
0 => '1',
|
)]
|
Error code: invalidrecord
|
Stack trace:
|
line 1372 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
|
line 1348 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
|
line 6576 of /lib/accesslib.php: call to moodle_database->get_record()
|
line 133 of /mod/feedback/mapcourse.php: call to context_course::instance()
|
If we look at the guilty line:
133. $cmapcontext = context_course::instance($cmap->id);
|
134. $cmapshortname = format_string($cmap->shortname, true, array('context' => $cmapcontext));
|
135. $coursecontext = context_course::instance($cmap->courseid);
|
136. $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
|
A course context is being created using the 'id' primary key of the 'feedback_sitecourse_map' table. Naturally a course with this 'courseid' does not exist since we've deleted it. I'm not that well-versed in Moodle code but presumably a context shouldn't be created based on the mapping module but of the course itself. Which leads me to believe the above 4 lines should be re-written as:
133. $coursecontext = context_course::instance($cmap->courseid);
|
134. $cmapshortname = format_string($cmap->shortname, true, array('context' => $coursecontext));
|
135. $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext));
|
If this makes sense, I'll attach a git patch that solves the problem (tested and working on our dev system but not extensively).