示例#1
0
 /**
  * Moves this node into the given node
  *
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $referenceNode
  * @throws \TYPO3\TYPO3CR\Exception\NodeExistsException
  * @throws \TYPO3\TYPO3CR\Exception\NodeException
  * @return void
  * @api
  */
 public function moveInto(NodeInterface $referenceNode)
 {
     if ($referenceNode === $this || $referenceNode === $this->getParent()) {
         return;
     }
     if ($this->getPath() === '/') {
         throw new \TYPO3\TYPO3CR\Exception\NodeException('The root node cannot be moved.', 1346769001);
     }
     if ($referenceNode !== $this->getParent() && $referenceNode->getNode($this->getName()) !== NULL) {
         throw new \TYPO3\TYPO3CR\Exception\NodeExistsException('Node with path "' . $this->getName() . '" already exists.', 1292503470);
     }
     if (!$this->isNodeDataMatchingContext()) {
         $this->materializeNodeData();
     }
     $parentPath = $referenceNode->getPath();
     $this->setPath($parentPath . ($parentPath === '/' ? '' : '/') . $this->getName());
     $this->nodeDataRepository->persistEntities();
     $this->nodeDataRepository->setNewIndex($this->nodeData, NodeDataRepository::POSITION_LAST);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeUpdated($this);
 }
 /**
  * Moves this node into the given node
  *
  * @param NodeInterface $referenceNode
  * @return void
  * @throws NodeExistsException
  * @throws NodeException
  * @throws NodeConstraintException
  * @api
  */
 public function moveInto(NodeInterface $referenceNode)
 {
     if ($referenceNode === $this || $referenceNode === $this->getParent()) {
         return;
     }
     if ($this->getPath() === '/') {
         throw new NodeException('The root node cannot be moved.', 1346769001);
     }
     if ($referenceNode !== $this->getParent() && $referenceNode->getNode($this->getName()) !== null) {
         throw new NodeExistsException('Node with path "' . $this->getName() . '" already exists.', 1292503470);
     }
     if (!$referenceNode->willChildNodeBeAutoCreated($this->getName()) && !$referenceNode->isNodeTypeAllowedAsChildNode($this->getNodeType())) {
         throw new NodeConstraintException('Cannot move ' . $this->__toString() . ' into ' . $referenceNode->__toString(), 1404648124);
     }
     $this->emitBeforeNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
     $this->setPath(NodePaths::addNodePathSegment($referenceNode->getPath(), $this->getName()));
     $this->nodeDataRepository->persistEntities();
     $this->nodeDataRepository->setNewIndex($this->nodeData, NodeDataRepository::POSITION_LAST);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitAfterNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
     $this->emitNodeUpdated($this);
 }
示例#3
0
 /**
  * Creates, adds and returns a child node of this node, without setting default
  * properties or creating subnodes.
  *
  * @param string $name Name of the new node
  * @param \TYPO3\TYPO3CR\Domain\Model\NodeType $nodeType Node type of the new node (optional)
  * @param string $identifier The identifier of the node, unique within the workspace, optional(!)
  * @param \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace
  * @param array $dimensions An array of dimension name to dimension values
  * @throws NodeExistsException if a node with this path already exists.
  * @throws \InvalidArgumentException if the node name is not accepted.
  * @return \TYPO3\TYPO3CR\Domain\Model\NodeData
  */
 public function createSingleNodeData($name, NodeType $nodeType = NULL, $identifier = NULL, Workspace $workspace = NULL, array $dimensions = NULL)
 {
     if (!is_string($name) || preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) !== 1) {
         throw new \InvalidArgumentException('Invalid node name "' . $name . '" (a node name must only contain characters, numbers and the "-" sign).', 1292428697);
     }
     $nodeWorkspace = $workspace ?: $this->workspace;
     $newPath = $this->path . ($this->path === '/' ? '' : '/') . $name;
     if ($this->nodeDataRepository->findOneByPath($newPath, $nodeWorkspace, $dimensions) !== NULL) {
         throw new NodeExistsException(sprintf('Node with path "' . $newPath . '" already exists in workspace %s and given dimensions %s.', $nodeWorkspace->getName(), var_export($dimensions, TRUE)), 1292503471);
     }
     $newNodeData = new NodeData($newPath, $nodeWorkspace, $identifier, $dimensions);
     $this->nodeDataRepository->add($newNodeData);
     $this->nodeDataRepository->setNewIndex($newNodeData, NodeDataRepository::POSITION_LAST);
     if ($nodeType !== NULL) {
         $newNodeData->setNodeType($nodeType);
     }
     return $newNodeData;
 }