Skip to content

Commit d497a17

Browse files
authored
Merge pull request #1693 from wording3/patch-2
Tree level update in method recover()
2 parents f2548d7 + ba4315b commit d497a17

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/Gedmo/Tree/Entity/Repository/NestedTreeRepository.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,26 +815,32 @@ public function recover()
815815
$self = $this;
816816
$em = $this->_em;
817817

818-
$doRecover = function ($root, &$count) use ($meta, $config, $self, $em, &$doRecover) {
818+
$doRecover = function ($root, &$count, &$lvl) use ($meta, $config, $self, $em, &$doRecover) {
819819
$lft = $count++;
820820
foreach ($self->getChildren($root, true) as $child) {
821-
$doRecover($child, $count);
821+
$depth = ($lvl + 1);
822+
$doRecover($child, $count, $depth);
822823
}
823824
$rgt = $count++;
824825
$meta->getReflectionProperty($config['left'])->setValue($root, $lft);
825826
$meta->getReflectionProperty($config['right'])->setValue($root, $rgt);
827+
if (isset($config['level'])) {
828+
$meta->getReflectionProperty($config['level'])->setValue($root, $lvl);
829+
}
826830
$em->persist($root);
827831
};
828832

829833
if (isset($config['root'])) {
830834
foreach ($this->getRootNodes() as $root) {
831835
$count = 1; // reset on every root node
832-
$doRecover($root, $count);
836+
$lvl = 0;
837+
$doRecover($root, $count, $lvl);
833838
}
834839
} else {
835840
$count = 1;
841+
$lvl = 0;
836842
foreach ($this->getChildren(null, true) as $root) {
837-
$doRecover($root, $count);
843+
$doRecover($root, $count, $lvl);
838844
}
839845
}
840846
}

0 commit comments

Comments
 (0)