2002-10-15 16:04:38 +00:00
< ? PHP //$Id$
// 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
2006-08-25 08:27:27 +00:00
require_capability ( 'moodle/site:config' , get_context_instance ( CONTEXT_SYSTEM , SITEID ));
2002-10-15 16:04:38 +00:00
$deletedir = $CFG -> dataroot ; // The directory to delete!
2007-04-30 17:08:34 +00:00
admin_externalpage_print_header ();
2006-09-25 20:22:55 +00:00
print_heading ( 'Purge moodledata' );
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 ());
notice_yesno ( 'Are you completely sure you want to delete everything inside the directory ' . $deletedir . ' ?' ,
'delete.php' , 'index.php' , $optionsyes , NULL , 'post' , 'get' );
2007-04-30 17:08:34 +00:00
admin_externalpage_print_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' );
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) ?' ,
'delete.php' , 'index.php' , $optionsyes , NULL , 'post' , 'get' );
2007-04-30 17:08:34 +00:00
admin_externalpage_print_footer ();
2002-10-15 16:04:38 +00:00
exit ;
}
2005-05-06 03:11:58 +00:00
if ( ! confirm_sesskey ()) {
error ( 'This script was called wrongly' );
}
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>' ;
2002-10-15 16:04:38 +00:00
print_continue ( $CFG -> wwwroot );
2007-04-30 17:08:34 +00:00
admin_externalpage_print_footer ();
2002-10-15 16:04:38 +00:00
exit ;
function delete_subdirectories ( $rootdir ) {
$dir = opendir ( $rootdir );
while ( $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
2005-05-06 03:11:58 +00:00
?>