Skip to content

Commit

Permalink
Fix warnings when deleting records that do not exist.
Browse files Browse the repository at this point in the history
Fixes #3037
  • Loading branch information
markstory committed Jul 14, 2012
1 parent 6c90541 commit a7c79e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -124,11 +124,13 @@ public function beforeFind(Model $Model, $query) {
*/
public function beforeDelete(Model $Model, $cascade = true) {
extract($this->settings[$Model->alias]);
$data = current($Model->find('first', array(
$data = $Model->find('first', array(
'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
'fields' => array($Model->alias . '.' . $left, $Model->alias . '.' . $right),
'recursive' => -1)));
$this->_deletedRow = $data;
'recursive' => -1));
if ($data) {
$this->_deletedRow = current($data);
}
return true;
}

Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
Expand Up @@ -914,6 +914,18 @@ public function testDelete() {
$this->assertSame($validTree, true);
}

/**
* Test deleting a record that doesn't exist.
*
* @return void
*/
public function testDeleteDoesNotExist() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$this->Tree->delete(99999);
}

/**
* testRemove method
*
Expand Down

0 comments on commit a7c79e5

Please sign in to comment.