MDL-63666 logging: Add support for removal of context users.
[moodle.git] / admin / tool / log / store / standard / classes / privacy / provider.php
index 4ee8007..76a4e1f 100644 (file)
@@ -40,7 +40,8 @@ use core_privacy\local\request\contextlist;
  */
 class provider implements
     \core_privacy\local\metadata\provider,
-    \tool_log\local\privacy\logstore_provider {
+    \tool_log\local\privacy\logstore_provider,
+    \tool_log\local\privacy\logstore_userlist_provider {
 
     use \tool_log\local\privacy\moodle_database_export_and_delete;
 
@@ -86,6 +87,22 @@ class provider implements
         ]);
     }
 
+    /**
+     * Add user IDs that contain user information for the specified context.
+     *
+     * @param \core_privacy\local\request\userlist $userlist The userlist to add the users to.
+     * @return void
+     */
+    public static function add_userids_for_context(\core_privacy\local\request\userlist $userlist) {
+        $params = ['contextid' => $userlist->get_context()->id];
+        $sql = "SELECT userid, relateduserid, realuserid
+                  FROM {logstore_standard_log}
+                 WHERE contextid = :contextid";
+        $userlist->add_from_sql('userid', $sql, $params);
+        $userlist->add_from_sql('relateduserid', $sql, $params);
+        $userlist->add_from_sql('realuserid', $sql, $params);
+    }
+
     /**
      * Get the database object.
      *