diff options
author | Frédéric Guillot <fred@kanboard.net> | 2018-04-27 14:32:58 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2018-04-27 14:32:58 -0700 |
commit | 2d2b50d5dca7afa8523685a682a2dcc78b602ce2 (patch) | |
tree | a77d5a9c819b754bde645256898ebf4a546da3f6 /app/Core | |
parent | bb406d57b1c1ad2736774be18b2f7b4d31abcf63 (diff) |
Remove all attachments when removing a project
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/ObjectStorage/FileStorage.php | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/Core/ObjectStorage/FileStorage.php b/app/Core/ObjectStorage/FileStorage.php index 18453890..410951fb 100644 --- a/app/Core/ObjectStorage/FileStorage.php +++ b/app/Core/ObjectStorage/FileStorage.php @@ -128,12 +128,21 @@ class FileStorage implements ObjectStorageInterface public function remove($key) { $filename = $this->path.DIRECTORY_SEPARATOR.$key; + $result = false; if (file_exists($filename)) { - return unlink($filename); + $result = unlink($filename); + + // Remove parent folder if empty + $parentFolder = dirname($filename); + $files = glob($parentFolder.DIRECTORY_SEPARATOR.'*'); + + if ($files !== false && is_dir($parentFolder) && count($files) === 0) { + rmdir($parentFolder); + } } - return false; + return $result; } /** |