2009-11-01 10:57:00 +00:00
|
|
|
<?php
|
2002-10-15 16:04:38 +00:00
|
|
|
|
|
|
|
// Deletes the moodledata directory, COMPLETELY!!
|
|
|
|
// BE VERY CAREFUL USING THIS!
|
|
|
|
|
2004-09-24 22:28:50 +00:00
|
|
|
require_once('../config.php');
|
2006-09-25 20:22:55 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2007-04-30 17:08:34 +00:00
|
|
|
|
|
|
|
admin_externalpage_setup('purgemoodledata');
|
2002-10-15 16:04:38 +00:00
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
2006-03-06 10:02:59 +00:00
|
|
|
$sure = optional_param('sure', 0, PARAM_BOOL);
|
|
|
|
$reallysure = optional_param('reallysure', 0, PARAM_BOOL);
|
2005-05-06 03:11:58 +00:00
|
|
|
|
2008-05-02 04:37:02 +00:00
|
|
|
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
|
2002-10-15 16:04:38 +00:00
|
|
|
|
|
|
|
$deletedir = $CFG->dataroot; // The directory to delete!
|
|
|
|
|
2010-03-31 08:05:53 +00:00
|
|
|
echo $OUTPUT->header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading('Purge moodledata');
|
2006-09-25 20:22:55 +00:00
|
|
|
|
2005-05-06 03:11:58 +00:00
|
|
|
if (empty($sure)) {
|
2006-09-25 20:22:55 +00:00
|
|
|
$optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey());
|
2009-11-01 10:57:00 +00:00
|
|
|
|
2010-01-03 20:47:13 +00:00
|
|
|
$formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'));
|
|
|
|
$formcancel = new single_button('index.php', get_string('no'), 'get');
|
2009-08-20 08:39:07 +00:00
|
|
|
echo $OUTPUT->confirm('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?', $formcontinue, $formcancel);
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2002-10-15 16:04:38 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-09-25 20:22:55 +00:00
|
|
|
if (!data_submitted() or empty($reallysure)) {
|
|
|
|
$optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey(), 'reallysure'=>'yes');
|
2010-01-03 20:47:13 +00:00
|
|
|
$formcontinue = new single_button(new moodle_url('delete.php', $optionsyes), get_string('yes'));
|
2010-01-14 19:18:04 +00:00
|
|
|
$formcancel = new single_button('index.php', get_string('no'), 'get');
|
2009-11-01 10:57:00 +00:00
|
|
|
echo $OUTPUT->confirm('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) ?',
|
2009-08-20 08:39:07 +00:00
|
|
|
$formcontinue, $formcancel);
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2002-10-15 16:04:38 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-05-06 03:11:58 +00:00
|
|
|
if (!confirm_sesskey()) {
|
2008-04-09 08:21:51 +00:00
|
|
|
print_error('wrongcall', 'error');
|
2005-05-06 03:11:58 +00:00
|
|
|
}
|
|
|
|
|
2002-10-15 16:04:38 +00:00
|
|
|
/// OK, here goes ...
|
|
|
|
|
|
|
|
delete_subdirectories($deletedir);
|
|
|
|
|
2004-09-24 22:28:50 +00:00
|
|
|
echo '<h1 align="center">Done!</h1>';
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->continue_button($CFG->wwwroot);
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2002-10-15 16:04:38 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
function delete_subdirectories($rootdir) {
|
|
|
|
|
|
|
|
$dir = opendir($rootdir);
|
|
|
|
|
2007-10-15 05:18:58 +00:00
|
|
|
while (false !== ($file = readdir($dir))) {
|
2004-09-24 22:28:50 +00:00
|
|
|
if ($file != '.' and $file != '..') {
|
|
|
|
$fullfile = $rootdir .'/'. $file;
|
|
|
|
if (filetype($fullfile) == 'dir') {
|
2002-10-15 16:04:38 +00:00
|
|
|
delete_subdirectories($fullfile);
|
2004-09-24 22:28:50 +00:00
|
|
|
echo 'Deleting '. $fullfile .' ... ';
|
2002-10-15 16:04:38 +00:00
|
|
|
if (rmdir($fullfile)) {
|
2004-09-24 22:28:50 +00:00
|
|
|
echo 'Done.<br />';
|
2002-10-15 16:04:38 +00:00
|
|
|
} else {
|
2004-09-24 22:28:50 +00:00
|
|
|
echo 'FAILED.<br />';
|
2002-10-15 16:04:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-24 22:28:50 +00:00
|
|
|
echo 'Deleting '. $fullfile .' ... ';
|
|
|
|
if (unlink($fullfile)) {
|
|
|
|
echo 'Done.<br />';
|
2002-10-15 16:04:38 +00:00
|
|
|
} else {
|
2004-09-24 22:28:50 +00:00
|
|
|
echo 'FAILED.<br />';
|
2002-10-15 16:04:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dir);
|
|
|
|
}
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2009-11-01 10:57:00 +00:00
|
|
|
|