Nested.php 23 KB

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