Remove all attachments when removing a project

This commit is contained in:
Frédéric Guillot
2018-04-27 14:32:58 -07:00
parent bb406d57b1
commit 2d2b50d5dc
2 changed files with 28 additions and 7 deletions

View File

@@ -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;
}
/**