diff options
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/filestore.php | 51 | ||||
-rw-r--r-- | engine/lib/users.php | 1 |
2 files changed, 52 insertions, 0 deletions
diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index 455d011d5..4fa0dc96e 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -1296,6 +1296,57 @@ function file_set_page_owner($file) { } } +/** + * Recursively delete a directory + * + * @param str $directory + */ +function delete_directory($directory) { + // sanity check: must be a directory + if (!$handle = opendir($directory)) { + return FALSE; + } + + // loop through all files + while (($file = readdir($handle)) !== FALSE) { + if (in_array($file, array('.', '..'))) { + continue; + } + + $path = "$directory/$file"; + if (is_dir($path)) { + // recurse down through directory + if (!delete_directory($path)) { + return FALSE; + } + } else { + // delete file + unlink($path); + } + } + + // remove empty directory + closedir($handle); + return rmdir($directory); +} + +/** + * Removes all user files + * + * @param ElggUser $user + * @return void + */ +function clear_user_files($user) { + global $CONFIG; + + $time_created = date('Y/m/d', $user->time_created); + $file_path = "$CONFIG->dataroot$time_created/$user->guid"; + if (file_exists($file_path)) { + delete_directory($file_path); + } +} + + /// Variable holding the default datastore $DEFAULT_FILE_STORE = NULL; diff --git a/engine/lib/users.php b/engine/lib/users.php index 313566dfd..d7d13bdfe 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -156,6 +156,7 @@ class ElggUser extends ElggEntity // Delete owned data clear_annotations_by_owner($this->guid); clear_metadata_by_owner($this->guid); + clear_user_files($this); // Delete entity return parent::delete(); |