MDL-62035 core_comment: Update to deletion methods.
Also clarification with the export method to clarify that it is only for one context.
This commit is contained in:
@@ -59,15 +59,15 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
/**
|
||||
* Writes user data to the writer for the user to download.
|
||||
*
|
||||
* @param array $context Contexts to run through and return data.
|
||||
* @param \context $context The context to export data for.
|
||||
* @param string $component The component that is calling this function
|
||||
* @param string $commentarea The comment area related to the component
|
||||
* @param int $itemid An identifier for a group of comments
|
||||
* @param array $subcontext The sub-context in which to export this data
|
||||
* @param bool $onlyforthisuser Only return the comments this user made.
|
||||
*/
|
||||
public static function export_comments($context, $component, $commentarea, $itemid, $subcontext, $onlyforthisuser = true) {
|
||||
|
||||
public static function export_comments(\context $context, string $component, string $commentarea, int $itemid,
|
||||
array $subcontext, bool $onlyforthisuser = true) {
|
||||
$data = new \stdClass;
|
||||
$data->context = $context;
|
||||
$data->area = $commentarea;
|
||||
@@ -102,13 +102,27 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all comments for a specified context.
|
||||
* Deletes all comments for a specified context, component, and commentarea.
|
||||
*
|
||||
* @param \context $context Details about which context to delete comments for.
|
||||
* @param string $component Component to delete.
|
||||
* @param string $commentarea Comment area to delete.
|
||||
* @param int $itemid The item ID for use with deletion.
|
||||
*/
|
||||
public static function delete_comments_for_all_users_in_context(\context $context) {
|
||||
public static function delete_comments_for_all_users(\context $context, string $component, string $commentarea = null,
|
||||
int $itemid = null) {
|
||||
global $DB;
|
||||
$DB->delete_records('comments', ['contextid' => $context->id]);
|
||||
$params = [
|
||||
'contextid' => $context->id,
|
||||
'component' => $component
|
||||
];
|
||||
if (isset($commentarea)) {
|
||||
$params['commentarea'] = $commentarea;
|
||||
}
|
||||
if (isset($itemid)) {
|
||||
$params['itemid'] = $itemid;
|
||||
}
|
||||
$DB->delete_records('comments', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,17 +130,34 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
|
||||
*
|
||||
* @param \core_privacy\local\request\approved_contextlist $contextlist Contains the user ID and a list of contexts to be
|
||||
* deleted from.
|
||||
* @param string $component Component to delete from.
|
||||
* @param string $commentarea Area to delete from.
|
||||
* @param int $itemid The item id to delete from.
|
||||
*/
|
||||
public static function delete_comments_for_user(\core_privacy\local\request\approved_contextlist $contextlist) {
|
||||
public static function delete_comments_for_user(\core_privacy\local\request\approved_contextlist $contextlist,
|
||||
string $component, string $commentarea = null, int $itemid = null) {
|
||||
global $DB;
|
||||
|
||||
$userid = $contextlist->get_user()->id;
|
||||
$contextids = implode(',', $contextlist->get_contextids());
|
||||
$params = ['userid' => $userid];
|
||||
$params = [
|
||||
'userid' => $userid,
|
||||
'component' => $component,
|
||||
];
|
||||
$areasql = '';
|
||||
if (isset($commentarea)) {
|
||||
$params['commentarea'] = $commentarea;
|
||||
$areasql = 'AND commentarea = :commentarea';
|
||||
}
|
||||
$itemsql = '';
|
||||
if (isset($itemid)) {
|
||||
$params['itemid'] = $itemid;
|
||||
$itemsql = 'AND itemid = :itemid';
|
||||
}
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
|
||||
$params += $inparams;
|
||||
|
||||
$select = "userid = :userid and contextid $insql";
|
||||
$select = "userid = :userid AND component = :component $areasql $itemsql AND contextid $insql";
|
||||
$DB->delete_records_select('comments', $select, $params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user