public function makeRoot($newRoot)
    {
        if($this->isRoot())
        {
            return;
        }

        if(!$this->hasManyRoots())
        {
            throw new \BadMethodCallException(sprintf('%s::%s is only supported on multiple root trees', __CLASS__, __METHOD__));
        }

        $em = $this->getManager()->getEntityManager();
        $lftField = $this->getLeftFieldName();
        $rgtField = $this->getRightFieldName();
        $rootField = $this->getRootFieldName();

        $oldRgt = $this->getRightValue();
        $oldLft = $this->getLeftValue();
        $oldRoot = $this->getRootValue();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            // Update descendants lft/rgt/root values
           $diff = 1 - $oldLft;
            $qb = $em->createQueryBuilder()
                ->update(get_class($this->getNode()), 'n')
                ->set("n.$lftField", "n.$lftField + ?1")
                ->setParameter(1, $diff)
                ->set("n.$rgtField", "n.$rgtField + ?2")
                ->setParameter(2, $diff)
                ->set("n.$rootField", "?3")
                ->setParameter(3, $newRoot)
                ->where("n.$lftField > ?4")
                ->setParameter(4, $oldLft)
                ->andWhere("n.$rgtField < ?5")
                ->setParameter(5, $oldRgt)
                ->andWhere("n.$rootField = ?6")
                ->setParameter(6, $oldRoot);
            $qb->getQuery()->execute();
            $this->getManager()->updateValues($oldLft, $oldRgt, $diff, $oldRoot, $newRoot);

            // Close gap in old tree
            $first = $oldRgt + 1;
            $delta = $oldLft - $oldRgt - 1;
            $this->shiftRLRange($first, 0, $delta, $oldRoot);

            // Set new lft/rgt/root values for root node
            $this->setLeftValue(1);
            $this->setRightValue($oldRgt - $oldLft + 1);
            $this->setRootValue($newRoot);
            $em->persist($this->getNode());

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction
    }
public function makeRoot($newRoot)
    {
        if($this->isRoot())
        {
            return;
        }

        if(!$this->hasManyRoots())
        {
            throw new \BadMethodCallException(sprintf('%s::%s is only supported on multiple root trees', __CLASS__, __METHOD__));
        }

        $em = $this->getManager()->getEntityManager();
        $lftField = $this->getLeftFieldName();
        $rgtField = $this->getRightFieldName();
        $rootField = $this->getRootFieldName();

        $oldRgt = $this->getRightValue();
        $oldLft = $this->getLeftValue();
        $oldRoot = $this->getRootValue();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            // Update descendants lft/rgt/root values
           $diff = 1 - $oldLft;
            $qb = $em->createQueryBuilder()
                ->update(get_class($this->getNode()), 'n')
                ->set("n.$lftField", "n.$lftField + ?1")
                ->setParameter(1, $diff)
                ->set("n.$rgtField", "n.$rgtField + ?2")
                ->setParameter(2, $diff)
                ->set("n.$rootField", "?3")
                ->setParameter(3, $newRoot)
                ->where("n.$lftField > ?4")
                ->setParameter(4, $oldLft)
                ->andWhere("n.$rgtField < ?5")
                ->setParameter(5, $oldRgt)
                ->andWhere("n.$rootField = ?6")
                ->setParameter(6, $oldRoot);
            $qb->getQuery()->execute();
            $this->getManager()->updateValues($oldLft, $oldRgt, $diff, $oldRoot, $newRoot);

            // Close gap in old tree
            $first = $oldRgt + 1;
            $delta = $oldLft - $oldRgt - 1;
            $this->shiftRLRange($first, 0, $delta, $oldRoot);

            // Set new lft/rgt/root values for root node
            $this->setLeftValue(1);
            $this->setRightValue($oldRgt - $oldLft + 1);
            $this->setRootValue($newRoot);
            $em->persist($this->getNode());

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction
    }
public function makeRoot ( $ newRoot ) { if ( $ this -> isRoot ( ) ) { return ; } if ( ! $ this -> hasManyRoots ( ) ) { throw new \ BadMethodCallException ( sprintf ( '%s::%s is only supported on multiple root trees' , __CLASS__ , __METHOD__ ) ) ; } $ em = $ this -> getManager ( ) -> getEntityManager ( ) ; $ lftField = $ this -> getLeftFieldName ( ) ; $ rgtField = $ this -> getRightFieldName ( ) ; $ rootField = $ this -> getRootFieldName ( ) ; $ oldRgt = $ this -> getRightValue ( ) ; $ oldLft = $ this -> getLeftValue ( ) ; $ oldRoot = $ this -> getRootValue ( ) ; // beginTransaction $ em -> getConnection ( ) -> beginTransaction ( ) ; try { // Update descendants lft/rgt/root values $ diff = 1 - $ oldLft ; $ qb = $ em -> createQueryBuilder ( ) -> update ( get_class ( $ this -> getNode ( ) ) , 'n' ) -> set ( "n.$lftField" , "n.$lftField + ?1" ) -> setParameter ( 1 , $ diff ) -> set ( "n.$rgtField" , "n.$rgtField + ?2" ) -> setParameter ( 2 , $ diff ) -> set ( "n.$rootField" , "?3" ) -> setParameter ( 3 , $ newRoot ) -> where ( "n.$lftField > ?4" ) -> setParameter ( 4 , $ oldLft ) -> andWhere ( "n.$rgtField < ?5" ) -> setParameter ( 5 , $ oldRgt ) -> andWhere ( "n.$rootField = ?6" ) -> setParameter ( 6 , $ oldRoot ) ; $ qb -> getQuery ( ) -> execute ( ) ; $ this -> getManager ( ) -> updateValues ( $ oldLft , $ oldRgt , $ diff , $ oldRoot , $ newRoot ) ; // Close gap in old tree $ first = $ oldRgt + 1 ; $ delta = $ oldLft - $ oldRgt - 1 ; $ this -> shiftRLRange ( $ first , 0 , $ delta , $ oldRoot ) ; // Set new lft/rgt/root values for root node $ this -> setLeftValue ( 1 ) ; $ this -> setRightValue ( $ oldRgt - $ oldLft + 1 ) ; $ this -> setRootValue ( $ newRoot ) ; $ em -> persist ( $ this -> getNode ( ) ) ; $ em -> flush ( ) ; $ em -> getConnection ( ) -> commit ( ) ; } catch ( \ Exception $ e ) { // @codeCoverageIgnoreStart $ em -> close ( ) ; $ em -> getConnection ( ) -> rollback ( ) ; throw $ e ; // @codeCoverageIgnoreEnd } // endTransaction }
Makes this node a root node.

@param mixed $newRoot
Makes this node a root node .