Skip to content

Commit 0156070

Browse files
committed
MDL-65084 recent items: Handle deleted courses
The method should not cause errors when a course with activities that the user has visited no longer exists. Ensuring that we only get records for courses still in the database will stop any course not found erros from get_fast_modinfo() (cherry picked from commit f1d4c355fb25321756cfbed3b38afbe6e91ccdf9)
1 parent c58a1e9 commit 0156070

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

blocks/recentlyaccesseditems/classes/helper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ public static function get_recent_items(int $limit = 0) {
5353
return $recentitems;
5454
}
5555

56-
// Determine sort sql clause.
57-
$sort = 'timeaccess DESC';
58-
5956
$paramsql = array('userid' => $userid);
60-
$records = $DB->get_records('block_recentlyaccesseditems', $paramsql, $sort);
57+
$sql = "SELECT rai.*
58+
FROM {block_recentlyaccesseditems} rai
59+
JOIN {course} c ON c.id = rai.courseid
60+
WHERE userid = :userid
61+
ORDER BY rai.timeaccess DESC";
62+
$records = $DB->get_records_sql($sql, $paramsql);
6163
$order = 0;
6264

6365
// Get array of items by course. Use $order index to keep sql sorted results.

0 commit comments

Comments
 (0)