summaryrefslogtreecommitdiff
path: root/modules/gallery/models
diff options
context:
space:
mode:
authorJoe7 <jozsef.rnagy@site.hu>2011-01-03 13:21:54 +0100
committerBharat Mediratta <bharat@menalto.com>2011-01-03 11:01:02 -0800
commit336632fea0a955d74099cd169b3178c01f250ff5 (patch)
treeea4f7b41d735dc41bbeb6f073052a8215ecc42a0 /modules/gallery/models
parente760200eeec2f003f95072118a6cc52971c76dad (diff)
Keep view counters of all item types accurate
Added common increment_view_count() func in item model for reuse
Diffstat (limited to 'modules/gallery/models')
-rw-r--r--modules/gallery/models/item.php10
1 files changed, 10 insertions, 0 deletions
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);
}