MDL-61743 core_privacy: Add context level checks for all users deletion

This commit is contained in:
David Monllao 2018-03-27 09:08:50 +02:00
parent fa9243cd85
commit 3650af761a
2 changed files with 18 additions and 0 deletions

View File

@ -153,6 +153,11 @@ class provider implements
* @param context $context The specific context to delete data for.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
if (!$context instanceof \context_block) {
return;
}
// The only way to delete data for the html block is to delete the block instance itself.
blocks_delete_instance(static::get_instance_from_context($context));
}
@ -165,6 +170,10 @@ class provider implements
public static function delete_data_for_user(approved_contextlist $contextlist) {
// The only way to delete data for the html block is to delete the block instance itself.
foreach ($contextlist as $context) {
if (!$context instanceof \context_block) {
continue;
}
blocks_delete_instance(static::get_instance_from_context($context));
}
}

View File

@ -184,6 +184,11 @@ class provider implements
if (empty($context)) {
return;
}
if (!$context instanceof \context_module) {
return;
}
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
$DB->delete_records('choice_answers', ['choiceid' => $instanceid]);
}
@ -202,6 +207,10 @@ class provider implements
$userid = $contextlist->get_user()->id;
foreach ($contextlist->get_contexts() as $context) {
if (!$context instanceof \context_module) {
return;
}
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
$DB->delete_records('choice_answers', ['choiceid' => $instanceid, 'userid' => $userid]);
}