MDL-33434 mssql: Improve handling of returned ids on insert.
[moodle.git] / admin / delete.php
blob9ffc222e96c0aecde055c30006d9efc8309d515e
1 <?php
3 // Deletes the moodledata directory, COMPLETELY!!
4 // BE VERY CAREFUL USING THIS!
6 require_once('../config.php');
7 require_once($CFG->libdir.'/adminlib.php');
9 admin_externalpage_setup('purgemoodledata');
11 require_login();
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));
18 $deletedir = $CFG->dataroot; // The directory to delete!
20 echo $OUTPUT->header();
21 echo $OUTPUT->heading('Purge moodledata');
23 if (empty($sure)) {
24 $optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey());
26 $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'));
27 $formcancel = new single_button('index.php', get_string('no'), 'get');
28 echo $OUTPUT->confirm('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?', $formcontinue, $formcancel);
29 echo $OUTPUT->footer();
30 exit;
33 if (!data_submitted() or empty($reallysure)) {
34 $optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey(), 'reallysure'=>'yes');
35 $formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'));
36 $formcancel = new single_button('index.php', get_string('no'), 'get');
37 echo $OUTPUT->confirm('Are you REALLY REALLY completely sure you want to delete everything inside the directory '.
38 $deletedir .' (this includes all user images, and any other course files that have been created) ?',
39 $formcontinue, $formcancel);
40 echo $OUTPUT->footer();
41 exit;
44 if (!confirm_sesskey()) {
45 print_error('wrongcall', 'error');
48 /// OK, here goes ...
50 delete_subdirectories($deletedir);
52 echo '<h1 align="center">Done!</h1>';
53 echo $OUTPUT->continue_button($CFG->wwwroot);
54 echo $OUTPUT->footer();
55 exit;
58 function delete_subdirectories($rootdir) {
60 $dir = opendir($rootdir);
62 while (false !== ($file = readdir($dir))) {
63 if ($file != '.' and $file != '..') {
64 $fullfile = $rootdir .'/'. $file;
65 if (filetype($fullfile) == 'dir') {
66 delete_subdirectories($fullfile);
67 echo 'Deleting '. $fullfile .' ... ';
68 if (rmdir($fullfile)) {
69 echo 'Done.<br />';
70 } else {
71 echo 'FAILED.<br />';
73 } else {
74 echo 'Deleting '. $fullfile .' ... ';
75 if (unlink($fullfile)) {
76 echo 'Done.<br />';
77 } else {
78 echo 'FAILED.<br />';
83 closedir($dir);