summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-03-24 19:04:43 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-03-24 19:04:43 +0000
commit3523bf5d90cee4a90b7b4c467fefb80128a97fb7 (patch)
tree69b50123e8fc2928d45d4c72cb0e1fcbe9998a7c /core
parent414e58a4272078ae7a411688a948bf78c37fbf0d (diff)
Change the item model so it will actually delete all the file system
objects when an item is deleted.
Diffstat (limited to 'core')
-rw-r--r--core/models/item.php45
1 files changed, 29 insertions, 16 deletions
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);
}
}
}