mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding missing Model::create() when using Model::save() in a loop. Fixing some code formatting. Fixes #848
This commit is contained in:
parent
e05d7d1791
commit
248a2d3f26
1 changed files with 4 additions and 5 deletions
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue