findOneByPath() public method

Find a single node by exact path.
public findOneByPath ( string $path, Workspace $workspace, array $dimensions = null, boolean | null $removedNodes = false ) : NodeData
$path string Absolute path of the node
$workspace Neos\ContentRepository\Domain\Model\Workspace The containing workspace
$dimensions array An array of dimensions with array of ordered values to use for fallback matching
$removedNodes boolean | null Include removed nodes, NULL (all), FALSE (no removed nodes) or TRUE (only removed nodes)
return Neos\ContentRepository\Domain\Model\NodeData The matching node if found, otherwise NULL
 /**
  * @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="Neos.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');
 }
 /**
  * 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);
 }