コード例 #1
0
 /**
  * inserts node as first child of given node
  *
  * @param NodeWrapper $node
  */
 public function insertAsFirstChildOf(NodeWrapper $node)
 {
     if ($node === $this) {
         throw new \InvalidArgumentException('Cannot insert node as a child of itself');
     }
     $em = $this->getManager()->getEntityManager();
     $newLeft = $node->getLeftValue() + 1;
     $newRight = $node->getLeftValue() + 2;
     $newRoot = $this->hasManyRoots() ? $node->getRootValue() : null;
     // beginTransaction
     $em->getConnection()->beginTransaction();
     try {
         $this->shiftRLRange($newLeft, 0, 2, $newRoot);
         $this->insertNode($newLeft, $newRight, $newRoot);
         $em->flush();
         $em->getConnection()->commit();
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $em->close();
         $em->getConnection()->rollback();
         throw $e;
         // @codeCoverageIgnoreEnd
     }
     // endTransaction
 }