From 5c68519d9233eabe98fce34fc00cdd4595f03ded Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 26 Jan 2010 00:23:45 -0800 Subject: Specialize the album cover id check to allow the root album to have no album cover. --- modules/gallery/models/item.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 4f5105b1..e4ff0bfb 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -717,7 +717,7 @@ class Item_Model extends ORM_MPTT { public function validate($array=null) { if (!$array) { $this->rules = array( - "album_cover_item_id" => array("callbacks" => array(array($this, "valid_item"))), + "album_cover_item_id" => array("callbacks" => array(array($this, "valid_album_cover"))), "description" => array("rules" => array("length[0,65535]")), "mime_type" => array("callbacks" => array(array($this, "valid_field"))), "name" => array("rules" => array("length[0,255]", "required"), @@ -848,14 +848,18 @@ class Item_Model extends ORM_MPTT { } /** - * Make sure the field refers to a valid item by id, or is null. + * Make sure the album cover item id refers to a valid item, or is null. */ - public function valid_item(Validation $v, $field) { - if ($this->$field && db::build() + public function valid_album_cover(Validation $v, $field) { + if ($this->id == 1) { + return; + } + + if ($this->album_cover_item_id && db::build() ->from("items") - ->where("id", "=", $this->$field) + ->where("id", "=", $this->album_cover_item_id) ->count_records() != 1) { - $v->add_error($field, "invalid_item"); + $v->add_error("album_cover_item_id", "invalid_item"); } } -- cgit v1.2.3