From 3523bf5d90cee4a90b7b4c467fefb80128a97fb7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 24 Mar 2009 19:04:43 +0000 Subject: Change the item model so it will actually delete all the file system objects when an item is deleted. --- core/models/item.php | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'core/models') diff --git a/core/models/item.php b/core/models/item.php index 9eaa2ed5..bd2d3024 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -97,23 +97,36 @@ class Item_Model extends ORM_MPTT { $original_resize_path = $this->resize_path(); $original_thumb_path = $this->thumb_path(); - // If there is no name, the path is invalid so don't try to delete parent::delete(); - if (!empty($this->name)) { - if ($this->is_album()) { - @dir::unlink($original_path); - @dir::unlink($original_resize_path); - @dir::unlink($original_thumb_path); - } else { - if (file_exists($original_path)) { - @unlink($original_path); - } - if (file_exists($original_resize_path)) { - @unlink($original_resize_path); - } - if (file_exists($original_thumb_path)) { - @unlink($original_thumb_path); - } + if (is_dir($original_path)) { + if (file_exists($original_path)) { + dir::unlink($original_path); + } + /* + * Both the thumb path and the resize path contain a path to .album.jpg + * So we need to try to delete both the path (may not exist) and its directory. + */ + if (file_exists($original_resize_path)) { + unlink($original_resize_path); + } + if (file_exists(dirname($original_resize_path))) { + dir::unlink(dirname($original_resize_path)); + } + if (file_exists($original_thumb_path)) { + unlink($original_thumb_path); + } + if (file_exists(dirname($original_thumb_path))) { + dir::unlink(dirname($original_thumb_path)); + } + } else { + if (file_exists($original_path)) { + unlink($original_path); + } + if (file_exists($original_resize_path)) { + unlink($original_resize_path); + } + if (file_exists($original_thumb_path)) { + unlink($original_thumb_path); } } } -- cgit v1.2.3