Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 39 and 400] [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Privacy class for requesting user data.
  19   *
  20   * @package    core
  21   * @category   privacy
  22   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace core\privacy;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  use core_privacy\local\metadata\collection;
  31  use core_privacy\local\request\approved_contextlist;
  32  use core_privacy\local\request\approved_userlist;
  33  use core_privacy\local\request\contextlist;
  34  use core_privacy\local\request\userlist;
  35  
  36  /**
  37   * Privacy class for requesting user data.
  38   *
  39   * @package    core
  40   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class provider implements
  44          \core_privacy\local\metadata\provider,
  45          \core_privacy\local\request\subsystem\provider,
  46          \core_privacy\local\request\core_userlist_provider {
  47  
  48      /**
  49       * Returns information about the user data stored in this component.
  50       *
  51       * @param  collection $collection A list of information about this component
  52       * @return collection The collection object filled out with information about this component.
  53       */
  54      public static function get_metadata(collection $collection) : collection {
  55          // These tables are really data about site configuration and not user data.
  56  
  57          // The config_log includes information about which user performed a configuration change.
  58          // The value and oldvalue may contain sensitive information such as accounts for service passwords..
  59          // This is not considered to be user data.
  60          $collection->add_database_table('config_log', [
  61                  'userid'        => 'privacy:metadata:config_log:userid',
  62                  'timemodified'  => 'privacy:metadata:config_log:timemodified',
  63                  'plugin'        => 'privacy:metadata:config_log:plugin',
  64                  'name'          => 'privacy:metadata:config_log:name',
  65                  'value'         => 'privacy:metadata:config_log:value',
  66                  'oldvalue'      => 'privacy:metadata:config_log:oldvalue',
  67              ], 'privacy:metadata:config_log');
  68  
  69          // The upgrade_log includes information about which user performed an upgrade.
  70          // This is not considered to be user data.
  71          $collection->add_database_table('upgrade_log', [
  72                  'type'          => 'privacy:metadata:upgrade_log:type',
  73                  'plugin'        => 'privacy:metadata:upgrade_log:plugin',
  74                  'version'       => 'privacy:metadata:upgrade_log:version',
  75                  'targetversion' => 'privacy:metadata:upgrade_log:targetversion',
  76                  'info'          => 'privacy:metadata:upgrade_log:info',
  77                  'details'       => 'privacy:metadata:upgrade_log:details',
  78                  'backtrace'     => 'privacy:metadata:upgrade_log:backtrace',
  79                  'userid'        => 'privacy:metadata:upgrade_log:userid',
  80                  'timemodified'  => 'privacy:metadata:upgrade_log:timemodified',
  81              ], 'privacy:metadata:upgrade_log');
  82  
  83          // The task_adhoc includes information about pending adhoc tasks, some of which may be run as a user.
  84          // These are removed as the task completes.
  85          $collection->add_database_table('task_adhoc', [
  86                  'component'     => 'privacy:metadata:task_adhoc:component',
  87                  'nextruntime'   => 'privacy:metadata:task_adhoc:nextruntime',
  88                  'userid'        => 'privacy:metadata:task_adhoc:userid',
  89              ], 'privacy:metadata:task_adhoc');
  90  
  91          // The task_log table stores debugging data for tasks.
  92          // These are cleaned regularly and intended purely for debugging.
  93          $collection->add_database_table('task_log', [
  94                  'component'     => 'privacy:metadata:task_log:component',
  95                  'userid'        => 'privacy:metadata:task_log:userid',
  96              ], 'privacy:metadata:task_log');
  97  
  98          // The events_queue includes information about pending events tasks.
  99          // These are stored for short periods whilst being processed into other locations.
 100          $collection->add_database_table('events_queue', [
 101                  'eventdata'     => 'privacy:metadata:events_queue:eventdata',
 102                  'stackdump'     => 'privacy:metadata:events_queue:stackdump',
 103                  'userid'        => 'privacy:metadata:events_queue:userid',
 104                  'timecreated'   => 'privacy:metadata:events_queue:timecreated',
 105              ], 'privacy:metadata:events_queue');
 106  
 107          // The log table is defined in core but used in logstore_legacy.
 108          $collection->add_database_table('log', [
 109              'time' => 'privacy:metadata:log:time',
 110              'userid' => 'privacy:metadata:log:userid',
 111              'ip' => 'privacy:metadata:log:ip',
 112              'action' => 'privacy:metadata:log:action',
 113              'url' => 'privacy:metadata:log:url',
 114              'info' => 'privacy:metadata:log:info'
 115          ], 'privacy:metadata:log');
 116  
 117          // The oauth2_refresh_token stores refresh tokens, allowing ongoing access to select oauth2 services.
 118          // Such tokens are not considered to be user data.
 119          $collection->add_database_table('oauth2_refresh_token', [
 120              'timecreated' => 'privacy:metadata:oauth2_refresh_token:timecreated',
 121              'timemodified' => 'privacy:metadata:oauth2_refresh_token:timemodified',
 122              'userid' => 'privacy:metadata:oauth2_refresh_token:userid',
 123              'issuerid' => 'privacy:metadata:oauth2_refresh_token:issuerid',
 124              'token' => 'privacy:metadata:oauth2_refresh_token:token',
 125              'scopehash' => 'privacy:metadata:oauth2_refresh_token:scopehash'
 126          ], 'privacy:metadata:oauth2_refresh_token');
 127  
 128          return $collection;
 129      }
 130  
 131      /**
 132       * Get the list of contexts that contain user information for the specified user.
 133       *
 134       * @param   int $userid The user to search.
 135       * @return  contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
 136       */
 137      public static function get_contexts_for_userid(int $userid) : contextlist {
 138          return new contextlist();
 139      }
 140  
 141      /**
 142       * Get the list of users who have data within a context.
 143       *
 144       * @param   userlist    $userlist   The userlist containing the list of users who have data in this context/plugin combination.
 145       */
 146      public static function get_users_in_context(userlist $userlist) {
 147          // Don't add any user.
 148      }
 149  
 150      /**
 151       * Export all user data for the specified user, in the specified contexts.
 152       *
 153       * @param approved_contextlist $contextlist The approved contexts to export information for.
 154       */
 155      public static function export_user_data(approved_contextlist $contextlist) {
 156          // None of the core tables should be exported.
 157      }
 158  
 159      /**
 160       * Delete all data for all users in the specified context.
 161       *
 162       * @param context $context The specific context to delete data for.
 163       */
 164      public static function delete_data_for_all_users_in_context(\context $context) {
 165          // None of the the data from these tables should be deleted.
 166      }
 167  
 168      /**
 169       * Delete all user data for the specified user, in the specified contexts.
 170       *
 171       * @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
 172       */
 173      public static function delete_data_for_user(approved_contextlist $contextlist) {
 174          // None of the the data from these tables should be deleted.
 175          // Note: Although it may be tempting to delete the adhoc task data, do not do so.
 176          // The delete process is run as an adhoc task.
 177      }
 178  
 179      /**
 180       * Delete multiple users within a single context.
 181       *
 182       * @param   approved_userlist       $userlist The approved context and user information to delete information for.
 183       */
 184      public static function delete_data_for_users(approved_userlist $userlist) {
 185          // None of the the data from these tables should be deleted.
 186          // Note: Although it may be tempting to delete the adhoc task data, do not do so.
 187          // The delete process is run as an adhoc task.
 188      }
 189  }