Skip to content

Commit

Permalink
Add some code to guard the weight calculation against zero rows when
Browse files Browse the repository at this point in the history
we're doing an initial install.
  • Loading branch information
bharat committed Jul 30, 2009
1 parent 67d4ae2 commit fc3273d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/gallery/models/item.php
Expand Up @@ -351,11 +351,14 @@ public function save() {
$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;
}
Expand Down

0 comments on commit fc3273d

Please sign in to comment.