diff --git a/src/Tree/Entity/Repository/NestedTreeRepository.php b/src/Tree/Entity/Repository/NestedTreeRepository.php index 375f42d6a..39f9fac9b 100644 --- a/src/Tree/Entity/Repository/NestedTreeRepository.php +++ b/src/Tree/Entity/Repository/NestedTreeRepository.php @@ -879,12 +879,10 @@ public function verify(/* array $options = [] */) // @phpstan-ignore-line $meta = $this->getClassMetadata(); $config = $this->listener->getConfiguration($this->getEntityManager(), $meta->getName()); if (isset($config['root'])) { - $trees = $this->getRootNodes(); + $trees = null !== $options['treeRootNode'] + ? [$options['treeRootNode']] // if a root node is specified, verify only it + : $this->getRootNodes(); foreach ($trees as $tree) { - // if a root node is specified, verify only it - if (null !== $options['treeRootNode'] && $options['treeRootNode'] !== $tree) { - continue; - } $this->verifyTree($errors, $tree); } } else { @@ -1034,29 +1032,20 @@ public function recover(/* array $options = [] */) // @phpstan-ignore-line // if it's a forest if (isset($config['root'])) { - foreach ($this->getRootNodes($options['sortByField'], $options['sortDirection']) as $root) { - // if a root node is specified, recover only it - if (null !== $options['treeRootNode'] && $options['treeRootNode'] !== $root) { - continue; - } - - $count = 1; // reset on every root node - $lvl = $config['level_base'] ?? 0; - $doRecover($root, $count, $lvl); - - if ($options['flush']) { - $em->flush(); - } - } + $roots = null !== $options['treeRootNode'] + ? [$options['treeRootNode']] + : $this->getRootNodes($options['sortByField'], $options['sortDirection']); } else { + $roots = $this->getChildren(null, true, $options['sortByField'], $options['sortDirection']); + } + + foreach ($roots as $root) { $count = 1; $lvl = $config['level_base'] ?? 0; - foreach ($this->getChildren(null, true, $options['sortByField'], $options['sortDirection']) as $root) { - $doRecover($root, $count, $lvl); + $doRecover($root, $count, $lvl); - if ($options['flush']) { - $em->flush(); - } + if ($options['flush']) { + $em->flush(); } } }