@@ -207,9 +207,10 @@ public function moveAsLastChild(string $tableExpression, string $rootColumnName,
207207            throw  new  NestedSetExceptionInvalidNodeOperation ('Cannot move node as last child of itself or into a descendant ' );
208208        }
209209
210-         $ level  = ($ parent ['level ' ] + 1 ) -  $ child [ ' level ' ] ;
210+         $ level  = ($ parent ['level ' ] + 1 );
211211
212-         $ this  ->updateNodePosition ($ tableExpression , $ child , $ parent ['right ' ], $ level );
212+         $ this  ->updateLevel ($ tableExpression , $ child ['id ' ], $ level );
213+         $ this  ->updateNodePosition ($ tableExpression , $ child , $ parent ['right ' ], $ level  - $ child ['level ' ]);
213214    }
214215
215216    /** 
@@ -233,9 +234,10 @@ public function moveAsFirstChild(string $tableExpression, string $rootColumnName
233234            throw  new  NestedSetExceptionInvalidNodeOperation ('Cannot move node as first child of itself or into a descendant ' );
234235        }
235236
236-         $ level  = ($ parent ['level ' ] + 1 ) -  $ child [ ' level ' ] ;
237+         $ level  = ($ parent ['level ' ] + 1 );
237238
238-         $ this  ->updateNodePosition ($ tableExpression , $ child , $ parent ['left ' ] + 1 , $ level );
239+         $ this  ->updateLevel ($ tableExpression , $ child ['id ' ], $ level );
240+         $ this  ->updateNodePosition ($ tableExpression , $ child , $ parent ['left ' ] + 1 , $ level  - $ child ['level ' ]);
239241    }
240242
241243    /** 
@@ -259,9 +261,10 @@ public function moveAsPrevSibling(string $tableExpression, string $rootColumnNam
259261            throw  new  NestedSetExceptionInvalidNodeOperation ('Cannot move node as prev sibling of itself or into a descendant ' );
260262        }
261263
262-         $ level  = $ sibling ['level ' ] -  $ child [ ' level ' ] ;
264+         $ level  = $ sibling ['level ' ];
263265
264-         $ this  ->updateNodePosition ($ tableExpression , $ child , $ sibling ['left ' ], $ level );
266+         $ this  ->updateLevel ($ tableExpression , $ child ['id ' ], $ level );
267+         $ this  ->updateNodePosition ($ tableExpression , $ child , $ sibling ['left ' ], $ level  - $ child ['level ' ]);
265268    }
266269
267270    /** 
@@ -285,9 +288,10 @@ public function moveAsNextSibling(string $tableExpression, string $rootColumnNam
285288            throw  new  NestedSetExceptionInvalidNodeOperation ('Cannot move node as next sibling of itself or into a descendant ' );
286289        }
287290
288-         $ level  = $ sibling ['level ' ] -  $ child [ ' level ' ] ;
291+         $ level  = $ sibling ['level ' ];
289292
290-         $ this  ->updateNodePosition ($ tableExpression , $ child , $ sibling ['right ' ] + 1 , $ level );
293+         $ this  ->updateLevel ($ tableExpression , $ child ['id ' ], $ level );
294+         $ this  ->updateNodePosition ($ tableExpression , $ child , $ sibling ['right ' ] + 1 , $ level  - $ child ['level ' ]);
291295    }
292296
293297    /** 
@@ -465,4 +469,18 @@ private function applyDeltaToSubtree(string $tableExpression, int $rootValue, in
465469            ])
466470            ->execute ();
467471    }
472+ 
473+     /** 
474+      * @param string $tableExpression 
475+      * @param int $id 
476+      * @param int $level 
477+      */ 
478+     private  function  updateLevel (string  $ tableExpression , int  $ id , int  $ level )
479+     {
480+         $ this  ->connection ->update (
481+             $ tableExpression ,
482+             [$ this  ->levelCol  => $ level ],
483+             [$ this  ->pkCol  => $ id ]
484+         );
485+     }
468486}
0 commit comments