Skip to content

Commit

Permalink
MDL-63531 privacy: Update to comments provider to simplfy sql.
Browse files Browse the repository at this point in the history
This updates the get_users_in_context_from_sql query to include
the context id to simplify the calls made from other components.
  • Loading branch information
abgreeve authored and andrewnicols committed Oct 30, 2018
1 parent 6592598 commit d2148f3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 54 deletions.
16 changes: 14 additions & 2 deletions comment/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,29 @@ public static function delete_comments_for_users(\core_privacy\local\request\app
* @param string $alias An alias prefix to use for comment selects to avoid interference with your own sql.
* @param string $component The component to check.
* @param string $area The comment area to check.
* @param int $contextid The context id.
* @param string $insql The SQL to use in a sub-select for the itemid query.
* @param array $params The params required for the insql.
*/
public static function get_users_in_context_from_sql(
userlist $userlist, string $alias, string $component, string $area, string $insql, $params) {
userlist $userlist, string $alias, string $component, string $area, int $contextid = null, string $insql = '',
array $params = []) {

if ($insql != '') {
$insql = "AND {$alias}.itemid {$insql}";
}
$contextsql = '';
if (isset($contextid)) {
$contextsql = "AND {$alias}.contextid = :{$alias}contextid";
$params["{$alias}contextid"] = $contextid;
}

// Comment authors.
$sql = "SELECT {$alias}.userid
FROM {comments} {$alias}
WHERE {$alias}.component = :{$alias}component
AND {$alias}.commentarea = :{$alias}commentarea
AND {$alias}.itemid IN ({$insql})";
$contextsql $insql";

$params["{$alias}component"] = $component;
$params["{$alias}commentarea"] = $area;
Expand Down
11 changes: 2 additions & 9 deletions mod/assign/submission/comments/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,8 @@ public static function get_userids_from_context(\core_privacy\local\request\user
if ($context->contextlevel != CONTEXT_MODULE) {
return;
}
$sql = "SELECT userid
FROM {comments}
WHERE contextid = :contextid
AND component = :component
AND commentarea = :commentarea";
$userlist->add_from_sql('userid', $sql, [
'contextid' => $context->id,
'component' => 'assignsubmission_comments',
'commentarea' => 'submission_comments']);
comments_provider::get_users_in_context_from_sql($userlist, 'c', 'assignsubmission_comments', 'submission_comments',
$context->id);
}

/**
Expand Down
17 changes: 1 addition & 16 deletions mod/data/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,7 @@ public static function get_users_in_context(userlist $userlist) {
$userlist->add_from_sql('userid', $sql, $params);

// Find users with comments.
$sql = "SELECT dr.id
FROM {context} c
JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
JOIN {data} d ON d.id = cm.instance
JOIN {data_records} dr ON dr.dataid = d.id
WHERE c.id = :contextid";

$params = [
'modname' => 'data',
'contextid' => $context->id,
'contextlevel' => CONTEXT_MODULE,
];

\core_comment\privacy\provider::get_users_in_context_from_sql(
$userlist, 'com', 'mod_data', 'database_entry', $sql, $params);
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_data', 'database_entry', $context->id);

// Find users with ratings.
$sql = "SELECT dr.id
Expand Down
18 changes: 2 additions & 16 deletions mod/glossary/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,8 @@ public static function get_users_in_context(userlist $userlist) {
$userlist->add_from_sql('userid', $sql, $params);

// Find users with glossary comments.
$sql = "SELECT ge.id
FROM {context} c
JOIN {course_modules} cm ON cm.id = c.instanceid AND c.contextlevel = :contextlevel
JOIN {modules} m ON m.id = cm.module AND m.name = :modname
JOIN {glossary} g ON g.id = cm.instance
JOIN {glossary_entries} ge ON ge.glossaryid = g.id
WHERE c.id = :contextid";

$params = [
'contextid' => $context->id,
'contextlevel' => CONTEXT_MODULE,
'modname' => 'glossary',
];

\core_comment\privacy\provider::get_users_in_context_from_sql(
$userlist, 'com', 'mod_glossary', 'glossary_entry', $sql, $params);
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_glossary', 'glossary_entry',
$context->id);

// Find users with glossary ratings.
$sql = "SELECT ge.id
Expand Down
12 changes: 1 addition & 11 deletions mod/wiki/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,7 @@ public static function get_users_in_context(userlist $userlist) {
WHERE ctx.id = :contextid";

$userlist->add_from_sql('userid', $sql, $params);

$sql = "
SELECT p.id
FROM {modules} m
JOIN {course_modules} cm ON cm.module = m.id AND m.name = :modname
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel
JOIN {wiki_subwikis} s ON cm.instance = s.wikiid
JOIN {wiki_pages} p ON p.subwikiid = s.id
WHERE ctx.id = :contextid";

\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $sql, $params);
\core_comment\privacy\provider::get_users_in_context_from_sql($userlist, 'com', 'mod_wiki', 'wiki_page', $context->id);
}

/**
Expand Down

0 comments on commit d2148f3

Please sign in to comment.