3 // Deletes the moodledata directory, COMPLETELY!!
4 // BE VERY CAREFUL USING THIS!
6 require_once('../config.php');
7 require_once($CFG->libdir
.'/adminlib.php');
8 $adminroot = admin_get_root();
9 admin_externalpage_setup('purgemoodledata', $adminroot);
13 $sure = optional_param('sure', 0, PARAM_BOOL
);
14 $reallysure = optional_param('reallysure', 0, PARAM_BOOL
);
16 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
, SITEID
));
18 $deletedir = $CFG->dataroot
; // The directory to delete!
20 admin_externalpage_print_header($adminroot);
21 print_heading('Purge moodledata');
24 $optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey());
25 notice_yesno ('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?',
26 'delete.php', 'index.php', $optionsyes, NULL, 'post', 'get');
27 admin_externalpage_print_footer($adminroot);
31 if (!data_submitted() or empty($reallysure)) {
32 $optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey(), 'reallysure'=>'yes');
33 notice_yesno ('Are you REALLY REALLY completely sure you want to delete everything inside the directory '. $deletedir .' (this includes all user images, and any other course files that have been created) ?',
34 'delete.php', 'index.php', $optionsyes, NULL, 'post', 'get');
35 admin_externalpage_print_footer($adminroot);
39 if (!confirm_sesskey()) {
40 error('This script was called wrongly');
45 delete_subdirectories($deletedir);
47 echo '<h1 align="center">Done!</h1>';
48 print_continue($CFG->wwwroot
);
49 admin_externalpage_print_footer($adminroot);
53 function delete_subdirectories($rootdir) {
55 $dir = opendir($rootdir);
57 while ($file = readdir($dir)) {
58 if ($file != '.' and $file != '..') {
59 $fullfile = $rootdir .'/'. $file;
60 if (filetype($fullfile) == 'dir') {
61 delete_subdirectories($fullfile);
62 echo 'Deleting '. $fullfile .' ... ';
63 if (rmdir($fullfile)) {
69 echo 'Deleting '. $fullfile .' ... ';
70 if (unlink($fullfile)) {