/** * @test */ public function findOneByPathFindsRemovedNodeInRepositoryAndRespectsWorkspaceAndDimensions() { $liveWorkspace = new Workspace('live'); $nodeData = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData')->disableOriginalConstructor()->getMock(); $nodeData->expects($this->any())->method('getPath')->will($this->returnValue('/foo')); $this->nodeDataRepository->remove($nodeData); $dimensions = array('persona' => array('everybody'), 'language' => array('de_DE', 'mul_ZZ')); $nodeData->expects($this->atLeastOnce())->method('matchesWorkspaceAndDimensions')->with($liveWorkspace, $dimensions)->will($this->returnValue(TRUE)); $result = $this->nodeDataRepository->findOneByPath('/foo', $liveWorkspace, $dimensions); $this->assertNull($result); }
/** * @test */ public function findOneByPathFindsAddedNodeInRepositoryAndRespectsWorkspaceAndDimensions() { $liveWorkspace = new Workspace('live'); $dimensions = ['persona' => ['everybody'], 'language' => ['de_DE', 'mul_ZZ']]; $nodeData = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock(); $nodeData->expects($this->any())->method('getPath')->will($this->returnValue('/foo')); $nodeData->expects($this->any())->method('getWorkspace')->will($this->returnValue($liveWorkspace)); $nodeData->expects($this->any())->method('getDimensionValues')->will($this->returnValue($dimensions)); $nodeData->expects($this->atLeastOnce())->method('matchesWorkspaceAndDimensions')->with($liveWorkspace, $dimensions)->will($this->returnValue(true)); $this->mockQuery->expects($this->any())->method('getResult')->will($this->returnValue([])); $this->nodeDataRepository->add($nodeData); $result = $this->nodeDataRepository->findOneByPath('/foo', $liveWorkspace, $dimensions); $this->assertSame($nodeData, $result); }
/** * Change the property on the given node. * * @param NodeData $node * @return NodeData */ public function execute(NodeData $node) { $reference = (string) $node->getProperty('plugin'); $workspace = $node->getWorkspace(); do { if ($this->reverse === false && preg_match(NodeInterface::MATCH_PATTERN_PATH, $reference)) { $pluginNode = $this->nodeDataRepository->findOneByPath($reference, $node->getWorkspace()); } else { $pluginNode = $this->nodeDataRepository->findOneByIdentifier($reference, $node->getWorkspace()); } if (isset($pluginNode)) { break; } $workspace = $workspace->getBaseWorkspace(); } while ($workspace && $workspace->getName() !== 'live'); if (isset($pluginNode)) { $node->setProperty('plugin', $this->reverse === false ? $pluginNode->getIdentifier() : $pluginNode->getPath()); } return $node; }
/** * 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'); }
/** * Collects all nodes with missing shadow nodes * * @param Workspace $workspace * @param boolean $dryRun * @param NodeType $nodeType * @return array */ protected function fixShadowNodesInWorkspace(Workspace $workspace, $dryRun, NodeType $nodeType = null) { $workspaces = array_merge([$workspace], $workspace->getBaseWorkspaces()); $fixedShadowNodes = 0; foreach ($workspaces as $workspace) { /** @var Workspace $workspace */ if ($workspace->getBaseWorkspace() === null) { continue; } /** @var QueryBuilder $queryBuilder */ $queryBuilder = $this->entityManager->createQueryBuilder(); $queryBuilder->select('n')->from(NodeData::class, 'n')->where('n.workspace = :workspace'); $queryBuilder->setParameter('workspace', $workspace->getName()); if ($nodeType !== null) { $queryBuilder->andWhere('n.nodeType = :nodeType'); $queryBuilder->setParameter('nodeType', $nodeType->getName()); } /** @var NodeData $nodeData */ foreach ($queryBuilder->getQuery()->getResult() as $nodeData) { $nodeDataSeenFromParentWorkspace = $this->nodeDataRepository->findOneByIdentifier($nodeData->getIdentifier(), $workspace->getBaseWorkspace(), $nodeData->getDimensionValues()); // This is the good case, either the node does not exist or was shadowed if ($nodeDataSeenFromParentWorkspace === null) { continue; } // Also good, the node was not moved at all. if ($nodeDataSeenFromParentWorkspace->getPath() === $nodeData->getPath()) { continue; } $nodeDataOnSamePath = $this->nodeDataRepository->findOneByPath($nodeData->getPath(), $workspace->getBaseWorkspace(), $nodeData->getDimensionValues(), null); // We cannot just put a shadow node in the path, something exists, but that should be fine. if ($nodeDataOnSamePath !== null) { continue; } if (!$dryRun) { $nodeData->createShadow($nodeDataSeenFromParentWorkspace->getPath()); } $fixedShadowNodes++; } } return $fixedShadowNodes; }
/** * Adjusts the path of $shadowNodeData to $path, if needed/possible. * * If the $path is occupied in $targetWorkspace, the shadow is removed. * * @param NodeData $shadowNodeData * @param $path * @param Workspace $targetWorkspace * @param array $dimensionValues * @return void */ protected function adjustShadowNodePath(NodeData $shadowNodeData, $path, Workspace $targetWorkspace, array $dimensionValues) { $nodeOnSamePathInTargetWorkspace = $this->nodeDataRepository->findOneByPath($path, $targetWorkspace, $dimensionValues); if ($nodeOnSamePathInTargetWorkspace === null || $nodeOnSamePathInTargetWorkspace->getWorkspace() !== $targetWorkspace) { $shadowNodeData->setPath($path, false); return; } // A node exists in that path, so no shadow node is needed/possible. $this->nodeDataRepository->remove($shadowNodeData); }
/** * Returns the form post values * * @param string $path Absolute path of the node * @return void */ public function listFormPostsAction($path) { $context = $this->contextFactory->create(array('workspaceName' => 'live')); $formNode = $this->nodeDataRepository->findOneByPath($path, $context->getWorkspace()); $this->view->assignMultiple(array('formIdentifier' => $formNode->getProperty('formIdentifier'), 'formPosts' => $this->nodeDataRepository->findByParentAndNodeTypeRecursively($formNode->getParentPath(), 'Lelesys.Plugin.ContactForm:FormPost', $context->getWorkspace()))); }
/** * Returns a node specified by the given relative path. * * @param string $path Path specifying the node, relative to this node * @return \TYPO3\TYPO3CR\Domain\Model\NodeData The specified node or NULL if no such node exists * * TODO This method should be removed, since it doesn't take the context into account correctly */ public function getNode($path) { return $this->nodeDataRepository->findOneByPath($this->normalizePath($path), $this->workspace); }