diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index e4ff0bfba2..9706d61f49 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -71,6 +71,12 @@ public function is_movie() { } public function delete() { + if ($this->id == 1) { + $v = new Validation(array("id")); + $v->add_error("id", "cant_delete_root_album"); + ORM_Validation_Exception::handle_validation($this->table_name, $v); + } + $old = clone $this; module::event("item_before_delete", $this); diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 1e77076a21..eb9ecc9939 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -336,4 +336,14 @@ public function cant_change_item_type_test() { } $this->assert_true(false, "Shouldn't get here"); } + + public function cant_delete_root_album_test() { + try { + item::root()->delete(); + } catch (ORM_Validation_Exception $e) { + $this->assert_same(array("id" => "cant_delete_root_album"), $e->validation->errors()); + return; // pass + } + $this->assert_true(false, "Shouldn't get here"); + } }