Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding missing Model::create() when using Model::save() in a loop. Fi…

…xing some code formatting. Fixes #848
  • Loading branch information...
commit 248a2d3f261229dcb7da30b82d90071bd8a72ab2 1 parent e05d7d1
@ADmad ADmad authored
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/Cake/Model/Behavior/TreeBehavior.php
View
9 lib/Cake/Model/Behavior/TreeBehavior.php
@@ -577,7 +577,6 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null) {
if ($missingParentAction == 'return') {
foreach ($missingParents as $id => $display) {
$this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')';
-
}
return false;
} elseif ($missingParentAction == 'delete') {
@@ -588,13 +587,14 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null) {
}
$count = 1;
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey), 'order' => $left)) as $array) {
- $Model->id = $array[$Model->alias][$Model->primaryKey];
$lft = $count++;
$rght = $count++;
+ $Model->create(false);
+ $Model->id = $array[$Model->alias][$Model->primaryKey];
$Model->save(array($left => $lft, $right => $rght), array('callbacks' => false));
}
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
- $Model->create();
+ $Model->create(false);
$Model->id = $array[$Model->alias][$Model->primaryKey];
$this->_setParent($Model, $array[$Model->alias][$parent]);
}
@@ -846,11 +846,10 @@ protected function _setParent($Model, $parentId = null, $created = false) {
if (($Model->id == $parentId)) {
return false;
-
} elseif (($node[$left] < $parentNode[$left]) && ($parentNode[$right] < $node[$right])) {
return false;
}
- if (empty ($node[$left]) && empty ($node[$right])) {
+ if (empty($node[$left]) && empty($node[$right])) {
$this->_sync($Model, 2, '+', '>= ' . $parentNode[$right], $created);
$result = $Model->save(
array($left => $parentNode[$right], $right => $parentNode[$right] + 1, $parent => $parentId),
Please sign in to comment.
Something went wrong with that request. Please try again.