From f97dedf3e494cd056b411367f5ed4d464b037c02 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 2 Feb 2009 16:37:09 +0000 Subject: Fix for Trac Ticket #30 --- modules/tag/helpers/tag_event.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'modules') 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;"); + } + } -- cgit v1.2.3