@@ -308,23 +308,23 @@ public function moveSubTreeToRoot(Node $node) {
308308 */
309309 public function moveSubTreeBelow (Node $ target , Node $ node ) {
310310 $ newLeftPosition = $ target ->getLeft () + 1 ;
311- $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node );
311+ $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node, $ target -> getDepth () + 1 );
312312 }
313313
314314 /**
315315 * {@inheritdoc}
316316 */
317317 public function moveSubTreeBefore (Node $ target , Node $ node ) {
318318 $ newLeftPosition = $ target ->getLeft ();
319- $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node );
319+ $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node, $ target -> getDepth () );
320320 }
321321
322322 /**
323323 * {@inheritdoc}
324324 */
325325 public function moveSubTreeAfter (Node $ target , Node $ node ) {
326326 $ newLeftPosition = $ target ->getRight () + 1 ;
327- $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node );
327+ $ this ->moveSubTreeToPosition ($ newLeftPosition , $ node, $ target -> getDepth () );
328328 }
329329
330330 /**
@@ -334,11 +334,13 @@ public function moveSubTreeAfter(Node $target, Node $node) {
334334 * The new left position.
335335 * @param \PNX\NestedSet\Node $node
336336 * The node to move.
337+ * @param int $newDepth
338+ * Depth of new position.
337339 *
338340 * @throws \Exception
339341 * If a transaction error occurs.
340342 */
341- protected function moveSubTreeToPosition ($ newLeftPosition , Node $ node ) {
343+ protected function moveSubTreeToPosition ($ newLeftPosition , Node $ node, $ newDepth ) {
342344 try {
343345 // Calculate position adjustment variables.
344346 $ width = $ node ->getRight () - $ node ->getLeft () + 1 ;
@@ -348,14 +350,7 @@ protected function moveSubTreeToPosition($newLeftPosition, Node $node) {
348350 $ this ->connection ->beginTransaction ();
349351
350352 // Calculate depth difference.
351- $ newNode = $ this ->getNodeAtPosition ($ newLeftPosition );
352- if (!$ newNode ) {
353- // No other children at this position, new depth = 1.
354- $ depthDiff = 1 - $ node ->getDepth ();
355- }
356- else {
357- $ depthDiff = $ newNode ->getDepth () - $ node ->getDepth ();
358- }
353+ $ depthDiff = $ newDepth - $ node ->getDepth ();
359354
360355 // Backwards movement must account for new space.
361356 if ($ distance < 0 ) {
0 commit comments