/** * Update a site * * @param Site $site A site to update * @param string $newSiteNodeName A new site node name * @return void * @Flow\Validate(argumentName="$site", type="UniqueEntity") * @Flow\Validate(argumentName="$newSiteNodeName", type="NotEmpty") * @Flow\Validate(argumentName="$newSiteNodeName", type="StringLength", options={ "minimum"=1, "maximum"=250 }) * @Flow\Validate(argumentName="$newSiteNodeName", type="TYPO3.Neos:NodeName") */ public function updateSiteAction(Site $site, $newSiteNodeName) { if ($site->getNodeName() !== $newSiteNodeName) { $oldSiteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $site->getNodeName()); $newSiteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $newSiteNodeName); /** @var $workspace Workspace */ foreach ($this->workspaceRepository->findAll() as $workspace) { $siteNode = $this->nodeDataRepository->findOneByPath($oldSiteNodePath, $workspace); if ($siteNode !== null) { $siteNode->setPath($newSiteNodePath); } } $site->setNodeName($newSiteNodeName); $this->nodeDataRepository->persistEntities(); } $this->siteRepository->update($site); $this->addFlashMessage('The site "%s" has been updated.', 'Update', null, array(htmlspecialchars($site->getName())), 1412371798); $this->unsetLastVisitedNodeAndRedirect('index'); }
/** * Update a site * * @param Site $site A site to update * @param string $newSiteNodeName A new site node name * @return void * @Flow\Validate(argumentName="$site", type="UniqueEntity") * @Flow\Validate(argumentName="$newSiteNodeName", type="NotEmpty") * @Flow\Validate(argumentName="$newSiteNodeName", type="StringLength", options={ "minimum"=1, "maximum"=250 }) * @Flow\Validate(argumentName="$newSiteNodeName", type="TYPO3.Neos:NodeName") */ public function updateSiteAction(Site $site, $newSiteNodeName) { if ($site->getNodeName() !== $newSiteNodeName) { $oldSiteNodePath = '/sites/' . $site->getNodeName(); $newSiteNodePath = '/sites/' . $newSiteNodeName; /** @var $workspace Workspace */ foreach ($this->workspaceRepository->findAll() as $workspace) { $siteNode = $this->nodeDataRepository->findOneByPath($oldSiteNodePath, $workspace); if ($siteNode !== NULL) { $siteNode->setPath($newSiteNodePath); } } $site->setNodeName($newSiteNodeName); $this->nodeDataRepository->persistEntities(); } $this->siteRepository->update($site); $this->addFlashMessage('The site "%s" has been updated.', 'Update', NULL, array($site->getName()), 1412371798); $this->unsetLastVisitedNodeAndRedirect('index'); }
/** * 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); }
/** * Testcase for bug #34291 (TYPO3CR reordering does not take unpersisted * node order changes into account) * * The error can be reproduced in the following way: * * - First, create some nodes, and persist. * - Then, move a node after another one, filling the LAST free sorting index between the nodes. Do NOT persist after that. * - After that, try to *again* move a node to this spot. In this case, we need to *renumber* * the node indices, and the system needs to take the before-moved node into account as well. * * The bug tested by this testcase led to wrong orderings on the floworg website in * the documentation part under some circumstances. * * @test */ public function renumberingTakesUnpersistedNodeOrderChangesIntoAccount() { $rootNode = $this->context->getRootNode(); $liveParentNode = $rootNode->createNode('parent-node'); $nodes = []; $nodes[1] = $liveParentNode->createNode('node001'); $nodes[1]->setIndex(1); $nodes[2] = $liveParentNode->createNode('node002'); $nodes[2]->setIndex(2); $nodes[3] = $liveParentNode->createNode('node003'); $nodes[3]->setIndex(4); $nodes[4] = $liveParentNode->createNode('node004'); $nodes[4]->setIndex(5); $this->nodeDataRepository->persistEntities(); $nodes[1]->moveAfter($nodes[2]); $nodes[3]->moveAfter($nodes[2]); $this->nodeDataRepository->persistEntities(); $actualChildNodes = $liveParentNode->getChildNodes(); $newNodeOrder = [$nodes[2], $nodes[3], $nodes[1], $nodes[4]]; $this->assertSameOrder($newNodeOrder, $actualChildNodes); }
/** * 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); }