diff options
-rw-r--r-- | modules/tag/helpers/tag_event.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 1025c9d2..ccb22df9 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -47,4 +47,25 @@ class tag_event_Core { return; } + + static function item_before_delete($item) { + $tags = ORM::factory("tag") + ->join("items_tags", "tags.id", "items_tags.tag_id") + ->join("items", "items.id", "items_tags.item_id") + ->where("items_tags.item_id", $item->id) + ->find_all(); + + foreach($tags as $tag) { + $tag->count--; + if ($tag->count > 0) { + $tag->save(); + } else { + $tag->delete(); + } + } + + $db = Database::instance(); + $db->query("DELETE FROM `items_tags` WHERE `item_id` = $item->id;"); + } + } |