diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-12-06 21:33:17 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-12-06 21:33:17 -0800 |
commit | 2f5c612036984a6f09995e8c692f399fb8c7fb15 (patch) | |
tree | 2a15c700babb4827ad4543794736a4e81ff8b8c2 | |
parent | fb899c313c9cdf4d6b0529c53d2b647999ad94db (diff) |
Update database queries.
-rw-r--r-- | modules/tag/helpers/tag.php | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 3e8a0d20..8075afe4 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -125,10 +125,16 @@ class tag_Core { * Delete all tags associated with an item */ static function clear_all($item) { - $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->delete("items_tags", array("item_id" => "$item->id")); + db::build() + ->update("tags") + ->set("count", new Database_Expression("`count` - 1")) + ->where("count", ">", 0) + ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id)) + ->execute(); + db::build() + ->delete("items_tags") + ->where("item_id", "=", $item->id) + ->execute(); } /** @@ -138,6 +144,6 @@ class tag_Core { // @todo There's a potential race condition here which we can solve by adding a lock around // this and all the cases where we create/update tags. I'm loathe to do that since it's an // extremely rare case. - Database::instance() ->delete("tags", array("count" => 0)); + db::build()->delete("tags")->where("count", "=", 0)->execute(); } }
\ No newline at end of file |