Nested.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <?php
  2. namespace Gedmo\Tree\Strategy\ORM;
  3. use Gedmo\Exception\UnexpectedValueException;
  4. use Doctrine\ORM\Proxy\Proxy;
  5. use Gedmo\Tool\Wrapper\EntityWrapper;
  6. use Gedmo\Tool\Wrapper\AbstractWrapper;
  7. use Gedmo\Tree\Strategy;
  8. use Doctrine\ORM\EntityManager;
  9. use Gedmo\Tree\TreeListener;
  10. use Doctrine\ORM\Mapping\ClassMetadataInfo;
  11. use Doctrine\ORM\Query;
  12. use Gedmo\Mapping\Event\AdapterInterface;
  13. /**
  14. * This strategy makes tree act like
  15. * nested set.
  16. *
  17. * This behavior can inpact the performance of your application
  18. * since nested set trees are slow on inserts and updates.
  19. *
  20. * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
  21. * @package Gedmo.Tree.Strategy.ORM
  22. * @subpackage Nested
  23. * @link http://www.gediminasm.org
  24. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  25. */
  26. class Nested implements Strategy
  27. {
  28. /**
  29. * Previous sibling position
  30. */
  31. const PREV_SIBLING = 'PrevSibling';
  32. /**
  33. * Next sibling position
  34. */
  35. const NEXT_SIBLING = 'NextSibling';
  36. /**
  37. * Last child position
  38. */
  39. const LAST_CHILD = 'LastChild';
  40. /**
  41. * First child position
  42. */
  43. const FIRST_CHILD = 'FirstChild';
  44. /**
  45. * TreeListener
  46. *
  47. * @var AbstractTreeListener
  48. */
  49. protected $listener = null;
  50. /**
  51. * The max number of "right" field of the
  52. * tree in case few root nodes will be persisted
  53. * on one flush for node classes
  54. *
  55. * @var array
  56. */
  57. private $treeEdges = array();
  58. /**
  59. * Stores a list of node position strategies
  60. * for each node by object hash
  61. *
  62. * @var array
  63. */
  64. private $nodePositions = array();
  65. /**
  66. * Stores a list of delayed nodes for correct order of updates
  67. *
  68. * @var array
  69. */
  70. private $delayedNodes = array();
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function __construct(TreeListener $listener)
  75. {
  76. $this->listener = $listener;
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function getName()
  82. {
  83. return Strategy::NESTED;
  84. }
  85. /**
  86. * get DQL expression for id value
  87. *
  88. * @param integer|string $id
  89. * @param EntityManager $em
  90. * @return string
  91. */
  92. private function getIdExpression($id, EntityManager $em)
  93. {
  94. if (is_string($id)) {
  95. $id = $em->getExpressionBuilder()->literal($id);
  96. }
  97. if ($id === null) {
  98. $id = 'NULL';
  99. }
  100. return (string)$id;
  101. }
  102. /**
  103. * Set node position strategy
  104. *
  105. * @param string $oid
  106. * @param string $position
  107. */
  108. public function setNodePosition($oid, $position)
  109. {
  110. $valid = array(
  111. self::FIRST_CHILD,
  112. self::LAST_CHILD,
  113. self::NEXT_SIBLING,
  114. self::PREV_SIBLING
  115. );
  116. if (!in_array($position, $valid, false)) {
  117. throw new \Gedmo\Exception\InvalidArgumentException("Position: {$position} is not valid in nested set tree");
  118. }
  119. $this->nodePositions[$oid] = $position;
  120. }
  121. /**
  122. * {@inheritdoc}
  123. */
  124. public function processScheduledInsertion($em, $node, AdapterInterface $ea)
  125. {
  126. $meta = $em->getClassMetadata(get_class($node));
  127. $config = $this->listener->getConfiguration($em, $meta->name);
  128. $meta->getReflectionProperty($config['left'])->setValue($node, 0);
  129. $meta->getReflectionProperty($config['right'])->setValue($node, 0);
  130. if (isset($config['level'])) {
  131. $meta->getReflectionProperty($config['level'])->setValue($node, 0);
  132. }
  133. if (isset($config['root'])) {
  134. $meta->getReflectionProperty($config['root'])->setValue($node, 0);
  135. }
  136. }
  137. /**
  138. * {@inheritdoc}
  139. */
  140. public function processScheduledUpdate($em, $node, AdapterInterface $ea)
  141. {
  142. $meta = $em->getClassMetadata(get_class($node));
  143. $config = $this->listener->getConfiguration($em, $meta->name);
  144. $uow = $em->getUnitOfWork();
  145. $changeSet = $uow->getEntityChangeSet($node);
  146. if (isset($config['root']) && isset($changeSet[$config['root']])) {
  147. throw new \Gedmo\Exception\UnexpectedValueException("Root cannot be changed manualy, change parent instead");
  148. }
  149. $oid = spl_object_hash($node);
  150. if (isset($changeSet[$config['left']]) && isset($this->nodePositions[$oid])) {
  151. $wrapped = AbstractWrapper::wrap($node, $em);
  152. $parent = $wrapped->getPropertyValue($config['parent']);
  153. // revert simulated changeset
  154. $uow->clearEntityChangeSet($oid);
  155. $wrapped->setPropertyValue($config['left'], $changeSet[$config['left']][0]);
  156. $uow->setOriginalEntityProperty($oid, $config['left'], $changeSet[$config['left']][0]);
  157. // set back all other changes
  158. foreach ($changeSet as $field => $set) {
  159. if ($field !== $config['left']) {
  160. $uow->setOriginalEntityProperty($oid, $field, $set[0]);
  161. $wrapped->setPropertyValue($field, $set[1]);
  162. }
  163. }
  164. $uow->recomputeSingleEntityChangeSet($meta, $node);
  165. $this->updateNode($em, $node, $parent);
  166. } elseif (isset($changeSet[$config['parent']])) {
  167. $this->updateNode($em, $node, $changeSet[$config['parent']][1]);
  168. }
  169. }
  170. /**
  171. * {@inheritdoc}
  172. */
  173. public function processPostPersist($em, $node, AdapterInterface $ea)
  174. {
  175. $meta = $em->getClassMetadata(get_class($node));
  176. $config = $this->listener->getConfiguration($em, $meta->name);
  177. $parent = $meta->getReflectionProperty($config['parent'])->getValue($node);
  178. $this->updateNode($em, $node, $parent, self::LAST_CHILD);
  179. }
  180. /**
  181. * {@inheritdoc}
  182. */
  183. public function processScheduledDelete($em, $node)
  184. {
  185. $meta = $em->getClassMetadata(get_class($node));
  186. $config = $this->listener->getConfiguration($em, $meta->name);
  187. $uow = $em->getUnitOfWork();
  188. $wrapped = AbstractWrapper::wrap($node, $em);
  189. $leftValue = $wrapped->getPropertyValue($config['left']);
  190. $rightValue = $wrapped->getPropertyValue($config['right']);
  191. if (!$leftValue || !$rightValue) {
  192. return;
  193. }
  194. $rootId = isset($config['root']) ? $wrapped->getPropertyValue($config['root']) : null;
  195. $diff = $rightValue - $leftValue + 1;
  196. if ($diff > 2) {
  197. $dql = "SELECT node FROM {$config['useObjectClass']} node";
  198. $dql .= " WHERE node.{$config['left']} BETWEEN :left AND :right";
  199. if (isset($config['root'])) {
  200. $dql .= " AND node.{$config['root']} = ".$this->getIdExpression($rootId, $em);
  201. }
  202. $q = $em->createQuery($dql);
  203. // get nodes for deletion
  204. $q->setParameter('left', $leftValue + 1);
  205. $q->setParameter('right', $rightValue - 1);
  206. $nodes = $q->getResult();
  207. foreach ((array)$nodes as $removalNode) {
  208. $uow->scheduleForDelete($removalNode);
  209. }
  210. }
  211. $this->shiftRL($em, $config['useObjectClass'], $rightValue + 1, -$diff, $rootId);
  212. }
  213. /**
  214. * {@inheritdoc}
  215. */
  216. public function onFlushEnd($em, AdapterInterface $ea)
  217. {
  218. // reset values
  219. $this->treeEdges = array();
  220. $this->updatesOnNodeClasses = array();
  221. }
  222. /**
  223. * {@inheritdoc}
  224. */
  225. public function processPreRemove($em, $node)
  226. {}
  227. /**
  228. * {@inheritdoc}
  229. */
  230. public function processPrePersist($em, $node)
  231. {}
  232. /**
  233. * {@inheritdoc}
  234. */
  235. public function processPreUpdate($em, $node)
  236. {}
  237. /**
  238. * {@inheritdoc}
  239. */
  240. public function processMetadataLoad($em, $meta)
  241. {}
  242. /**
  243. * {@inheritdoc}
  244. */
  245. public function processPostUpdate($em, $entity, AdapterInterface $ea)
  246. {}
  247. /**
  248. * {@inheritdoc}
  249. */
  250. public function processPostRemove($em, $entity, AdapterInterface $ea)
  251. {}
  252. /**
  253. * Update the $node with a diferent $parent
  254. * destination
  255. *
  256. * @param EntityManager $em
  257. * @param object $node - target node
  258. * @param object $parent - destination node
  259. * @param string $position
  260. * @throws Gedmo\Exception\UnexpectedValueException
  261. * @return void
  262. */
  263. public function updateNode(EntityManager $em, $node, $parent, $position = 'FirstChild')
  264. {
  265. $wrapped = AbstractWrapper::wrap($node, $em);
  266. $meta = $wrapped->getMetadata();
  267. $config = $this->listener->getConfiguration($em, $meta->name);
  268. $rootId = isset($config['root']) ? $wrapped->getPropertyValue($config['root']) : null;
  269. $identifierField = $meta->getSingleIdentifierFieldName();
  270. $nodeId = $wrapped->getIdentifier();
  271. $left = $wrapped->getPropertyValue($config['left']);
  272. $right = $wrapped->getPropertyValue($config['right']);
  273. $isNewNode = empty($left) && empty($right);
  274. if ($isNewNode) {
  275. $left = 1;
  276. $right = 2;
  277. }
  278. $oid = spl_object_hash($node);
  279. if (isset($this->nodePositions[$oid])) {
  280. $position = $this->nodePositions[$oid];
  281. }
  282. $level = 0;
  283. $treeSize = $right - $left + 1;
  284. $newRootId = null;
  285. if ($parent) {
  286. $wrappedParent = AbstractWrapper::wrap($parent, $em);
  287. $parentRootId = isset($config['root']) ? $wrappedParent->getPropertyValue($config['root']) : null;
  288. $parentOid = spl_object_hash($parent);
  289. $parentLeft = $wrappedParent->getPropertyValue($config['left']);
  290. $parentRight = $wrappedParent->getPropertyValue($config['right']);
  291. if (empty($parentLeft) && empty($parentRight)) {
  292. // parent node is a new node, but wasn't processed yet (due to Doctrine commit order calculator redordering)
  293. // We delay processing of node to the moment parent node will be processed
  294. if (!isset($this->delayedNodes[$parentOid])) {
  295. $this->delayedNodes[$parentOid] = array();
  296. }
  297. $this->delayedNodes[$parentOid][] = array('node' => $node, 'position' => $position);
  298. return;
  299. }
  300. if (!$isNewNode && $rootId === $parentRootId && $parentLeft >= $left && $parentRight <= $right) {
  301. throw new UnexpectedValueException("Cannot set child as parent to node: {$nodeId}");
  302. }
  303. if (isset($config['level'])) {
  304. $level = $wrappedParent->getPropertyValue($config['level']);
  305. }
  306. switch ($position) {
  307. case self::PREV_SIBLING:
  308. $newParent = $wrappedParent->getPropertyValue($config['parent']);
  309. if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
  310. throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
  311. }
  312. $wrapped->setPropertyValue($config['parent'], $newParent);
  313. $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
  314. $start = $parentLeft;
  315. break;
  316. case self::NEXT_SIBLING:
  317. $newParent = $wrappedParent->getPropertyValue($config['parent']);
  318. if (is_null($newParent) && (isset($config['root']) || $isNewNode)) {
  319. throw new UnexpectedValueException("Cannot persist sibling for a root node, tree operation is not possible");
  320. }
  321. $wrapped->setPropertyValue($config['parent'], $newParent);
  322. $em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $node);
  323. $start = $parentRight + 1;
  324. break;
  325. case self::LAST_CHILD:
  326. $start = $parentRight;
  327. $level++;
  328. break;
  329. case self::FIRST_CHILD:
  330. default:
  331. $start = $parentLeft + 1;
  332. $level++;
  333. break;
  334. }
  335. $this->shiftRL($em, $config['useObjectClass'], $start, $treeSize, $parentRootId);
  336. if (!$isNewNode && $rootId === $parentRootId && $left >= $start) {
  337. $left += $treeSize;
  338. $wrapped->setPropertyValue($config['left'], $left);
  339. }
  340. if (!$isNewNode && $rootId === $parentRootId && $right >= $start) {
  341. $right += $treeSize;
  342. $wrapped->setPropertyValue($config['right'], $right);
  343. }
  344. $newRootId = $parentRootId;
  345. } elseif (!isset($config['root'])) {
  346. $start = isset($this->treeEdges[$meta->name]) ?
  347. $this->treeEdges[$meta->name] : $this->max($em, $config['useObjectClass']);
  348. $this->treeEdges[$meta->name] = $start + 2;
  349. $start++;
  350. } else {
  351. $start = 1;
  352. $newRootId = $nodeId;
  353. }
  354. $diff = $start - $left;
  355. if (!$isNewNode) {
  356. $levelDiff = isset($config['level']) ? $level - $wrapped->getPropertyValue($config['level']) : null;
  357. $this->shiftRangeRL(
  358. $em,
  359. $config['useObjectClass'],
  360. $left,
  361. $right,
  362. $diff,
  363. $rootId,
  364. $newRootId,
  365. $levelDiff
  366. );
  367. $this->shiftRL($em, $config['useObjectClass'], $left, -$treeSize, $rootId);
  368. } else {
  369. $qb = $em->createQueryBuilder();
  370. $qb->update($config['useObjectClass'], 'node');
  371. if (isset($config['root'])) {
  372. $qb->set('node.' . $config['root'], $this->getIdExpression($newRootId, $em));
  373. $wrapped->setPropertyValue($config['root'], $newRootId);
  374. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['root'], $newRootId);
  375. }
  376. if (isset($config['level'])) {
  377. $qb->set('node.' . $config['level'], $level);
  378. $wrapped->setPropertyValue($config['level'], $level);
  379. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['level'], $level);
  380. }
  381. if (isset($newParent)) {
  382. $wrappedNewParent = AbstractWrapper::wrap($newParent, $em);
  383. $newParentId = $wrappedNewParent->getIdentifier();
  384. $qb->set('node.' . $config['parent'], $this->getIdExpression($newParentId, $em));
  385. $wrapped->setPropertyValue($config['parent'], $newParent);
  386. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['parent'], $newParent);
  387. }
  388. $qb->set('node.' . $config['left'], $left + $diff);
  389. $qb->set('node.' . $config['right'], $right + $diff);
  390. $qb->where("node.{$identifierField} = ".$this->getIdExpression($nodeId, $em));
  391. $qb->getQuery()->getSingleScalarResult();
  392. $wrapped->setPropertyValue($config['left'], $left + $diff);
  393. $wrapped->setPropertyValue($config['right'], $right + $diff);
  394. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['left'], $left + $diff);
  395. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['right'], $right + $diff);
  396. }
  397. if (isset($this->delayedNodes[$oid])) {
  398. foreach($this->delayedNodes[$oid] as $nodeData) {
  399. $this->updateNode($em, $nodeData['node'], $node, $nodeData['position']);
  400. }
  401. }
  402. }
  403. /**
  404. * Get the edge of tree
  405. *
  406. * @param EntityManager $em
  407. * @param string $class
  408. * @param integer $rootId
  409. * @return integer
  410. */
  411. public function max(EntityManager $em, $class, $rootId = 0)
  412. {
  413. $meta = $em->getClassMetadata($class);
  414. $config = $this->listener->getConfiguration($em, $meta->name);
  415. $dql = "SELECT MAX(node.{$config['right']}) FROM {$config['useObjectClass']} node";
  416. if (isset($config['root']) && $rootId) {
  417. $dql .= " WHERE node.{$config['root']} = ".$this->getIdExpression($rootId, $em);
  418. }
  419. $query = $em->createQuery($dql);
  420. $right = $query->getSingleScalarResult();
  421. return intval($right);
  422. }
  423. /**
  424. * Shift tree left and right values by delta
  425. *
  426. * @param EntityManager $em
  427. * @param string $class
  428. * @param integer $first
  429. * @param integer $delta
  430. * @param integer|string $rootId
  431. * @return void
  432. */
  433. public function shiftRL(EntityManager $em, $class, $first, $delta, $rootId = null)
  434. {
  435. $meta = $em->getClassMetadata($class);
  436. $config = $this->listener->getConfiguration($em, $class);
  437. $sign = ($delta >= 0) ? ' + ' : ' - ';
  438. $absDelta = abs($delta);
  439. $dql = "UPDATE {$meta->name} node";
  440. $dql .= " SET node.{$config['left']} = node.{$config['left']} {$sign} {$absDelta}";
  441. $dql .= " WHERE node.{$config['left']} >= {$first}";
  442. if (isset($config['root'])) {
  443. $dql .= " AND node.{$config['root']} = ".$this->getIdExpression($rootId, $em);
  444. }
  445. $q = $em->createQuery($dql);
  446. $q->getSingleScalarResult();
  447. $dql = "UPDATE {$meta->name} node";
  448. $dql .= " SET node.{$config['right']} = node.{$config['right']} {$sign} {$absDelta}";
  449. $dql .= " WHERE node.{$config['right']} >= {$first}";
  450. if (isset($config['root'])) {
  451. $dql .= " AND node.{$config['root']} = ".$this->getIdExpression($rootId, $em);
  452. }
  453. $q = $em->createQuery($dql);
  454. $q->getSingleScalarResult();
  455. // update in memory nodes increases performance, saves some IO
  456. foreach ($em->getUnitOfWork()->getIdentityMap() as $className => $nodes) {
  457. // for inheritance mapped classes, only root is always in the identity map
  458. if ($className !== $meta->rootEntityName) {
  459. continue;
  460. }
  461. foreach ($nodes as $node) {
  462. if ($node instanceof Proxy && !$node->__isInitialized__) {
  463. continue;
  464. }
  465. $oid = spl_object_hash($node);
  466. $left = $meta->getReflectionProperty($config['left'])->getValue($node);
  467. $root = isset($config['root']) ? $meta->getReflectionProperty($config['root'])->getValue($node) : null;
  468. if ($root === $rootId && $left >= $first) {
  469. $meta->getReflectionProperty($config['left'])->setValue($node, $left + $delta);
  470. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['left'], $left + $delta);
  471. }
  472. $right = $meta->getReflectionProperty($config['right'])->getValue($node);
  473. if ($root === $rootId && $right >= $first) {
  474. $meta->getReflectionProperty($config['right'])->setValue($node, $right + $delta);
  475. $em->getUnitOfWork()->setOriginalEntityProperty($oid, $config['right'], $right + $delta);
  476. }
  477. }
  478. }
  479. }
  480. /**
  481. * Shift range of right and left values on tree
  482. * depending on tree level diference also
  483. *
  484. * @param EntityManager $em
  485. * @param string $class
  486. * @param integer $first
  487. * @param integer $last
  488. * @param integer $delta
  489. * @param integer|string $rootId
  490. * @param integer|string $destRootId
  491. * @param integer $levelDelta
  492. * @return void
  493. */
  494. public function shiftRangeRL(EntityManager $em, $class, $first, $last, $delta, $rootId = null, $destRootId = null, $levelDelta = null)
  495. {
  496. $meta = $em->getClassMetadata($class);
  497. $config = $this->listener->getConfiguration($em, $class);
  498. $sign = ($delta >= 0) ? ' + ' : ' - ';
  499. $absDelta = abs($delta);
  500. $levelSign = ($levelDelta >= 0) ? ' + ' : ' - ';
  501. $absLevelDelta = abs($levelDelta);
  502. $dql = "UPDATE {$meta->name} node";
  503. $dql .= " SET node.{$config['left']} = node.{$config['left']} {$sign} {$absDelta}";
  504. $dql .= ", node.{$config['right']} = node.{$config['right']} {$sign} {$absDelta}";
  505. if (isset($config['root'])) {
  506. $dql .= ", node.{$config['root']} = ".$this->getIdExpression($destRootId, $em);
  507. }
  508. if (isset($config['level'])) {
  509. $dql .= ", node.{$config['level']} = node.{$config['level']} {$levelSign} {$absLevelDelta}";
  510. }
  511. $dql .= " WHERE node.{$config['left']} >= {$first}";
  512. $dql .= " AND node.{$config['right']} <= {$last}";
  513. if (isset($config['root'])) {
  514. $dql .= " AND node.{$config['root']} = ".$this->getIdExpression($rootId, $em);
  515. }
  516. $q = $em->createQuery($dql);
  517. $q->getSingleScalarResult();
  518. // update in memory nodes increases performance, saves some IO
  519. foreach ($em->getUnitOfWork()->getIdentityMap() as $className => $nodes) {
  520. // for inheritance mapped classes, only root is always in the identity map
  521. if ($className !== $meta->rootEntityName) {
  522. continue;
  523. }
  524. foreach ($nodes as $node) {
  525. if ($node instanceof Proxy && !$node->__isInitialized__) {
  526. continue;
  527. }
  528. $left = $meta->getReflectionProperty($config['left'])->getValue($node);
  529. $right = $meta->getReflectionProperty($config['right'])->getValue($node);
  530. $root = isset($config['root']) ? $meta->getReflectionProperty($config['root'])->getValue($node) : null;
  531. if ($root === $rootId && $left >= $first && $right <= $last) {
  532. $oid = spl_object_hash($node);
  533. $uow = $em->getUnitOfWork();
  534. $meta->getReflectionProperty($config['left'])->setValue($node, $left + $delta);
  535. $uow->setOriginalEntityProperty($oid, $config['left'], $left + $delta);
  536. $meta->getReflectionProperty($config['right'])->setValue($node, $right + $delta);
  537. $uow->setOriginalEntityProperty($oid, $config['right'], $right + $delta);
  538. if (isset($config['root'])) {
  539. $meta->getReflectionProperty($config['root'])->setValue($node, $destRootId);
  540. $uow->setOriginalEntityProperty($oid, $config['root'], $destRootId);
  541. }
  542. if (isset($config['level'])) {
  543. $level = $meta->getReflectionProperty($config['level'])->getValue($node);
  544. $meta->getReflectionProperty($config['level'])->setValue($node, $level + $levelDelta);
  545. $uow->setOriginalEntityProperty($oid, $config['level'], $level + $levelDelta);
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }