Adding missing Model::create() when using Model::save() in a loop. Fixing some code formatting. Fixes #848

This commit is contained in:
ADmad 2011-12-18 03:43:36 +05:30
parent e05d7d1791
commit 248a2d3f26

View file

@ -577,7 +577,6 @@ class TreeBehavior extends ModelBehavior {
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 @@ class TreeBehavior extends ModelBehavior {
}
$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 @@ class TreeBehavior extends ModelBehavior {
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),