diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 08:09:40 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 08:09:40 -0700 |
commit | d3ce7f7e36bac0e03db7028eb915ab066124a669 (patch) | |
tree | 7c2948d81084d873a2df39641da830fe09da1218 /modules | |
parent | d34c6b6fb398f7b5f529dd2524fe0895a4b92e8c (diff) | |
parent | fc3273da4d0b34310ba304310396527430c98ce2 (diff) |
Merge branch 'master' of git@github.com:gallery/gallery3
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/models/item.php | 9 |
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; } |