aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/filestore.php
diff options
context:
space:
mode:
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-23 19:43:49 +0000
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-11-23 19:43:49 +0000
commit8f2d3255c30320ab06c2081cd4d7e446e90747cf (patch)
tree04c594a48d5c69a1a04813e7fdfc23c720a10002 /engine/lib/filestore.php
parenta13dcbfbd2f47aeae09ec2270d36c1131e28362e (diff)
downloadelgg-8f2d3255c30320ab06c2081cd4d7e446e90747cf.tar.gz
elgg-8f2d3255c30320ab06c2081cd4d7e446e90747cf.tar.bz2
Deleting a user will remove all user files.
Fixes #607 git-svn-id: http://code.elgg.org/elgg/trunk@3700 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/filestore.php')
-rw-r--r--engine/lib/filestore.php51
1 files changed, 51 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;