public function moveInto(NodeInterface $referenceNode, $newName = null)
{
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);
}
$name = $newName !== null ? $newName : $this->getName();
$this->emitBeforeNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
$this->setPath(NodePaths::addNodePathSegment($referenceNode->getPath(), $name));
$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);
}