Skip to content

Commit

Permalink
MDL-63926 block_recentlyaccesseditems: Improved get_contexts_for_userid
Browse files Browse the repository at this point in the history
Updated the provider::get_contexts_for_userid method, to prevent false
positives. Previously, the user context would always be returned, now
the method checks data exists for the block first.
  • Loading branch information
mickhawkins committed Nov 14, 2018
1 parent dccda65 commit 13bd038
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blocks/recentlyaccesseditems/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public static function get_metadata(collection $collection) : collection {
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
$params = ['userid' => $userid, 'contextuser' => CONTEXT_USER];
$sql = "SELECT id
FROM {context}
WHERE instanceid = :userid and contextlevel = :contextuser";
$sql = "SELECT c.id
FROM {context} c
JOIN {block_recentlyaccesseditems} b
ON b.userid = c.instanceid
WHERE c.instanceid = :userid
AND c.contextlevel = :contextuser";
$contextlist = new contextlist();
$contextlist->add_from_sql($sql, $params);
return $contextlist;
Expand Down

0 comments on commit 13bd038

Please sign in to comment.