summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-07-30 08:02:54 -0700
committerBharat Mediratta <bharat@menalto.com>2009-07-30 08:02:54 -0700
commitfc3273da4d0b34310ba304310396527430c98ce2 (patch)
treee8e73def07662e62bd757d04bbae2e103f35d124 /modules
parent67d4ae21d5f7363f54782c23d2a7ff1d9e9f0505 (diff)
Add some code to guard the weight calculation against zero rows when
we're doing an initial install.
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/models/item.php9
1 files changed, 6 insertions, 3 deletions
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index a0598ea4..b3c7998b 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -351,11 +351,14 @@ class Item_Model extends ORM_MPTT {
$this->updated = time();
if (!$this->loaded) {
$this->created = $this->updated;
- $weight = Database::instance()
+ // Guard against an empty result when we create the first item. It's unfortunate that we
+ // have to check this every time.
+ // @todo: figure out a better way to bootstrap the weight.
+ $result = Database::instance()
->select("weight")->from("items")
->orderby("weight", "desc")->limit(1)
- ->get()->current()->weight;
- $this->weight = $weight + 1;
+ ->get()->current();
+ $this->weight = ($result ? $result->weight : 0) + 1;
} else {
$send_event = 1;
}