Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Created March 21, 2018 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewnicols/8c613c803d81ddd9c8d44ca8a80c8ffe to your computer and use it in GitHub Desktop.
Save andrewnicols/8c613c803d81ddd9c8d44ca8a80c8ffe to your computer and use it in GitHub Desktop.
<?php
define('CLI_SCRIPT', true);
require_once('config.php');
$user = \core_user::get_user(2);
\core\session\manager::init_empty_session();
\core\session\manager::set_user($user);
$manager = new \core_privacy\manager();
$approvedlist = new \core_privacy\local\request\contextlist_collection($user->id);
$contextlists = $manager->get_contexts_for_userid($user->id);
foreach ($contextlists as $contextlist) {
$approvedlist->add_contextlist(new \core_privacy\local\request\approved_contextlist(
$user,
$contextlist->get_component(),
$contextlist->get_contextids()
));
}
$exportedcontent = $manager->export_user_data($approvedlist);
echo "\n";
echo "== File was successfully exported to {$exportedcontent}\n";
$basedir = make_temp_directory('privacy');
$exportpath = make_unique_writable_directory($basedir, true);
$fp = get_file_packer();
$fp->extract_to_pathname($exportedcontent, $exportpath);
echo "== File export was uncompressed to {$exportpath}\n";
echo "============================================================================\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment