Skip to content

Commit

Permalink
Prevent accidentally deleting the root album.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Jan 28, 2010
1 parent ec0f89f commit 212633d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/gallery/models/item.php
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions modules/gallery/tests/Item_Model_Test.php
Expand Up @@ -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");
}
}

0 comments on commit 212633d

Please sign in to comment.