diff options
| author | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-02 16:37:09 +0000 | 
|---|---|---|
| committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-02 16:37:09 +0000 | 
| commit | f97dedf3e494cd056b411367f5ed4d464b037c02 (patch) | |
| tree | 8b8ac72145f2504aebb0f7b1a6dd5869c7b0f3a1 /modules/tag | |
| parent | ef58ac91e8c23832e657a4f8dee57fe0b7733ae8 (diff) | |
Fix for Trac Ticket #30
Diffstat (limited to 'modules/tag')
| -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;"); +  } +  } | 
