From fc3273da4d0b34310ba304310396527430c98ce2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 30 Jul 2009 08:02:54 -0700 Subject: Add some code to guard the weight calculation against zero rows when we're doing an initial install. --- modules/gallery/models/item.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'modules') 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; } -- cgit v1.2.3