From 336632fea0a955d74099cd169b3178c01f250ff5 Mon Sep 17 00:00:00 2001 From: Joe7 Date: Mon, 3 Jan 2011 13:21:54 +0100 Subject: Keep view counters of all item types accurate Added common increment_view_count() func in item model for reuse --- modules/gallery/models/item.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index fc5c3ff9..d4df0a78 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -1078,6 +1078,16 @@ class Item_Model_Core extends ORM_MPTT { return $data; } + /** + * Increments the view counter of this item + * We can't use math in ORM or the query builder, so do this by hand. It's important + * that we do this with math, otherwise concurrent accesses will damage accuracy. + */ + public function increment_view_count() { + db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $this->id") + ->execute(); + } + private function _cache_buster($path) { return "?m=" . (string)(file_exists($path) ? filemtime($path) : 0); } -- cgit v1.2.3