Nested.php 23 KB

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