/** * Update the tree to allow insertion of a leaf at the specified position * * @param int $left left column value * @param mixed $prune Object to prune from the shift * @param ConnectionInterface $con Connection to use. */ public static function makeRoomForLeaf($left, $prune = null, ConnectionInterface $con = null) { // Update database nodes ChildCategoryQuery::shiftRLValues(2, $left, null, $con); // Update all loaded nodes ChildCategoryQuery::updateLoadedNodes($prune, $con); }
/** * Move current node and its children to location $destLeft and updates rest of tree * * @param int $destLeft Destination left value * @param int $levelDelta Delta to add to the levels * @param ConnectionInterface $con Connection to use. */ protected function moveSubtreeTo($destLeft, $levelDelta, ConnectionInterface $con = null) { $left = $this->getLeftValue(); $right = $this->getRightValue(); $treeSize = $right - $left + 1; if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(CategoryTableMap::DATABASE_NAME); } $con->transaction(function () use($con, $treeSize, $destLeft, $left, $right, $levelDelta) { $preventDefault = false; // make room next to the target for the subtree ChildCategoryQuery::shiftRLValues($treeSize, $destLeft, null, $con); if (!$preventDefault) { if ($left >= $destLeft) { // src was shifted too? $left += $treeSize; $right += $treeSize; } if ($levelDelta) { // update the levels of the subtree ChildCategoryQuery::shiftLevel($levelDelta, $left, $right, $con); } // move the subtree to the target ChildCategoryQuery::shiftRLValues($destLeft - $left, $left, $right, $con); } // remove the empty room at the previous location of the subtree ChildCategoryQuery::shiftRLValues(-$treeSize, $right + 1, null, $con); // update all loaded nodes ChildCategoryQuery::updateLoadedNodes(null, $con); }); }