diff options
-rw-r--r-- | modules/tag/helpers/tag_event.php | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index ccb22df9..7192edec 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -49,22 +49,11 @@ class tag_event_Core { } 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("UPDATE `tags` SET `count` = `count` - 1 WHERE `count` > 0 " . + "AND `id` IN (SELECT `tag_id` from `items_tags` WHERE `item_id` = $item->id)"); + $db->query("DELETE FROM `tags` WHERE `count` = 0 AND `id` IN (" . + "SELECT `tag_id` from `items_tags` WHERE `item_id` = $item->id)"); $db->query("DELETE FROM `items_tags` WHERE `item_id` = $item->id;"); } |