getName() public method

Returns the name of this workspace
public getName ( ) : string
return string Name of this workspace
 /**
  * @test
  */
 public function aWorkspaceCanBeBasedOnAnotherWorkspace()
 {
     $baseWorkspace = new Workspace('BaseWorkspace');
     $workspace = new Workspace('MyWorkspace', $baseWorkspace);
     $this->assertSame('MyWorkspace', $workspace->getName());
     $this->assertSame($baseWorkspace, $workspace->getBaseWorkspace());
 }
 /**
  * @test
  */
 public function getUnpublishedNodesDoesNotReturnInvalidNodes()
 {
     $mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     $expectedContextProperties = array('workspaceName' => $this->mockWorkspace->getName(), 'inaccessibleContentShown' => true, 'invisibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => array());
     $this->mockContextFactory->expects($this->any())->method('create')->with($expectedContextProperties)->will($this->returnValue($mockContext));
     $mockNodeData1 = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
     $mockNodeData2 = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
     $mockNodeData1->expects($this->any())->method('getDimensionValues')->will($this->returnValue(array()));
     $mockNodeData2->expects($this->any())->method('getDimensionValues')->will($this->returnValue(array()));
     $mockNode1 = $this->getMockBuilder(NodeInterface::class)->getMock();
     $mockNode1->expects($this->any())->method('getNodeData')->will($this->returnValue($mockNodeData1));
     $mockNode1->expects($this->any())->method('getPath')->will($this->returnValue('/node1'));
     $this->mockNodeFactory->expects($this->at(0))->method('createFromNodeData')->with($mockNodeData1, $mockContext)->will($this->returnValue($mockNode1));
     $this->mockNodeFactory->expects($this->at(1))->method('createFromNodeData')->with($mockNodeData2, $mockContext)->will($this->returnValue(null));
     $this->mockNodeDataRepository->expects($this->atLeastOnce())->method('findByWorkspace')->with($this->mockWorkspace)->will($this->returnValue(array($mockNodeData1, $mockNodeData2)));
     $actualResult = $this->publishingService->getUnpublishedNodes($this->mockWorkspace);
     $this->assertSame($actualResult, array($mockNode1));
 }
 /**
  * {@inheritdoc}
  */
 public function createRedirectsForPublishedNode(NodeInterface $node, Workspace $targetWorkspace)
 {
     $nodeType = $node->getNodeType();
     if ($targetWorkspace->getName() !== 'live' || !$nodeType->isOfType('Neos.Neos:Document')) {
         return;
     }
     $context = $this->contextFactory->create(['workspaceName' => 'live', 'invisibleContentShown' => true, 'dimensions' => $node->getContext()->getDimensions()]);
     $targetNode = $context->getNodeByIdentifier($node->getIdentifier());
     if ($targetNode === null) {
         // The page has been added
         return;
     }
     $targetNodeUriPath = $this->buildUriPathForNodeContextPath($targetNode->getContextPath());
     if ($targetNodeUriPath === null) {
         throw new Exception('The target URI path of the node could not be resolved', 1451945358);
     }
     $hosts = $this->getHostnames($node->getContext());
     // The page has been removed
     if ($node->isRemoved()) {
         $this->flushRoutingCacheForNode($targetNode);
         $statusCode = (int) $this->defaultStatusCode['gone'];
         $this->redirectStorage->addRedirect($targetNodeUriPath, '', $statusCode, $hosts);
         return;
     }
     // compare the "old" node URI to the new one
     $nodeUriPath = $this->buildUriPathForNodeContextPath($node->getContextPath());
     // use the same regexp than the ContentContextBar Ember View
     $nodeUriPath = preg_replace('/@[A-Za-z0-9;&,\\-_=]+/', '', $nodeUriPath);
     if ($nodeUriPath === null || $nodeUriPath === $targetNodeUriPath) {
         // The page node path has not been changed
         return;
     }
     $this->flushRoutingCacheForNode($targetNode);
     $statusCode = (int) $this->defaultStatusCode['redirect'];
     $this->redirectStorage->addRedirect($targetNodeUriPath, $nodeUriPath, $statusCode, $hosts);
     $q = new FlowQuery([$node]);
     foreach ($q->children('[instanceof Neos.Neos:Document]') as $childrenNode) {
         $this->createRedirectsForPublishedNode($childrenNode, $targetWorkspace);
     }
 }
 /**
  * Move this NodeData to the given path and workspace.
  *
  * Basically 4 scenarios have to be covered here, depending on:
  *
  * - Does the NodeData have to be materialized (adapted to the workspace or target dimension)?
  * - Does a shadow node exist on the target path?
  *
  * Because unique key constraints and Doctrine ORM don't support arbitrary removal and update combinations,
  * existing NodeData instances are re-used and the metadata and content is swapped around.
  *
  * @param string $path
  * @param Workspace $workspace
  * @return NodeData If a shadow node was created this is the new NodeData object after the move.
  */
 public function move($path, $workspace)
 {
     $nodeData = $this;
     $originalPath = $this->path;
     if ($originalPath === $path) {
         return $this;
     }
     $targetPathShadowNodeData = $this->getExistingShadowNodeData($path, $workspace, $nodeData->getDimensionValues());
     if ($this->workspace->getName() !== $workspace->getName()) {
         if ($targetPathShadowNodeData === null) {
             // If there is no shadow node at the target path we need to materialize before moving and create a shadow node.
             $nodeData = $this->materializeToWorkspace($workspace);
             $nodeData->setPath($path, false);
             $movedNodeData = $nodeData;
         } else {
             // The existing shadow node on the target path will be used as the moved node. We don't need to materialize into the workspace.
             $movedNodeData = $targetPathShadowNodeData;
             $movedNodeData->setAsShadowOf(null);
             $movedNodeData->setIdentifier($nodeData->getIdentifier());
             $movedNodeData->similarize($nodeData);
             // A new shadow node will be created for the node data that references the recycled, existing shadow node
         }
         $movedNodeData->createShadow($originalPath);
     } else {
         $referencedShadowNode = $this->nodeDataRepository->findOneByMovedTo($nodeData);
         if ($targetPathShadowNodeData === null) {
             if ($referencedShadowNode === null) {
                 // There is no shadow node on the original or target path, so the current node data will be turned to a shadow node and a new node data will be created for the moved node.
                 // We cannot just create a new shadow node, since the order of Doctrine queries would cause unique key conflicts
                 $movedNodeData = new NodeData($path, $nodeData->getWorkspace(), $nodeData->getIdentifier(), $nodeData->getDimensionValues());
                 $movedNodeData->similarize($nodeData);
                 $this->addOrUpdate($movedNodeData);
                 $shadowNodeData = $nodeData;
                 $shadowNodeData->setAsShadowOf($movedNodeData);
             } else {
                 // A shadow node that references this node data already exists, so we just move the current node data
                 $movedNodeData = $nodeData;
                 $movedNodeData->setPath($path, false);
             }
         } else {
             if ($referencedShadowNode === null) {
                 // Turn the target path shadow node into the moved node (and adjust the identifier!)
                 // Do not reset the movedTo property to keep tracing the original move operation - TODO: Does that make sense if the identifier changes?
                 $movedNodeData = $targetPathShadowNodeData;
                 // Since the shadow node at the target path does not belong to the current node, we have to adjust the identifier
                 $movedNodeData->setRemoved(false);
                 $movedNodeData->setIdentifier($nodeData->getIdentifier());
                 $movedNodeData->similarize($nodeData);
                 // Create a shadow node from the current node that shadows the recycled node
                 $shadowNodeData = $nodeData;
                 $shadowNodeData->setAsShadowOf($movedNodeData);
             } else {
                 // If there is already shadow node on the target path, we need to make that shadow node the actual moved node and remove the current node data (which cannot be live).
                 // We cannot remove the shadow node and update the current node data, since the order of Doctrine queries would cause unique key conflicts.
                 $movedNodeData = $targetPathShadowNodeData;
                 $movedNodeData->setAsShadowOf(null);
                 $movedNodeData->similarize($nodeData);
                 $movedNodeData->setPath($path, false);
                 $this->nodeDataRepository->remove($nodeData);
             }
         }
     }
     return $movedNodeData;
 }
 /**
  * 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;
 }
 /**
  * Creates a new content context based on the given workspace and the NodeData object.
  *
  * @param Workspace $workspace Workspace for the new context
  * @param array $dimensionValues The dimension values for the new context
  * @param array $contextProperties Additional pre-defined context properties
  * @return Context
  */
 protected function createContext(Workspace $workspace, array $dimensionValues, array $contextProperties = array())
 {
     $presetsMatchingDimensionValues = $this->contentDimensionPresetSource->findPresetsByTargetValues($dimensionValues);
     $dimensions = array_map(function ($preset) {
         return $preset['values'];
     }, $presetsMatchingDimensionValues);
     $contextProperties += array('workspaceName' => $workspace->getName(), 'inaccessibleContentShown' => true, 'invisibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensions);
     return $this->contextFactory->create($contextProperties);
 }
 /**
  *
  *
  * @param NodeInterface $node
  * @param Workspace $targetWorkspace
  * @return void
  */
 public function afterNodePublishing(NodeInterface $node, Workspace $targetWorkspace)
 {
     if (!$this->eventEmittingService->isEnabled()) {
         return;
     }
     $documentNode = NodeEvent::getClosestAggregateNode($node);
     if ($documentNode === null) {
         return;
     }
     $this->scheduledNodeEventUpdates[$documentNode->getContextPath()] = array('workspaceName' => $node->getContext()->getWorkspaceName(), 'nestedNodeIdentifiersWhichArePublished' => array(), 'targetWorkspace' => $targetWorkspace->getName(), 'documentNode' => $documentNode);
     $this->scheduledNodeEventUpdates[$documentNode->getContextPath()]['nestedNodeIdentifiersWhichArePublished'][] = $node->getIdentifier();
 }
 /**
  * Checks if the current user may read the given workspace according to one the roles of the user's accounts
  *
  * In future versions, this logic may be implemented in Neos in a more generic way (for example, by means of an
  * ACL object), but for now, this method exists in order to at least centralize and encapsulate the required logic.
  *
  * @param Workspace $workspace The workspace
  * @return boolean
  */
 public function currentUserCanReadWorkspace(Workspace $workspace)
 {
     if ($workspace->getName() === 'live') {
         return true;
     }
     if ($workspace->getOwner() === $this->getCurrentUser() || $workspace->getOwner() === null) {
         return true;
     }
     return false;
 }
 /**
  * Update a workspace
  *
  * @param Workspace $workspace A workspace to update
  * @return void
  */
 public function updateAction(Workspace $workspace)
 {
     if ($workspace->getTitle() === '') {
         $workspace->setTitle($workspace->getName());
     }
     $this->workspaceRepository->update($workspace);
     $this->addFlashMessage($this->translator->translateById('workspaces.workspaceHasBeenUpdated', [$workspace->getTitle()], null, null, 'Modules', 'Neos.Neos'));
     $this->redirect('index');
 }
 /**
  * Checks if the specified workspace is a base workspace of this workspace
  * and if not, throws an exception
  *
  * @param Workspace $targetWorkspace The publishing target workspace
  * @return void
  * @throws WorkspaceException if the specified workspace is not a base workspace of this workspace
  */
 protected function verifyPublishingTargetWorkspace(Workspace $targetWorkspace)
 {
     $baseWorkspace = $this;
     while ($baseWorkspace === null || $targetWorkspace->getName() !== $baseWorkspace->getName()) {
         if ($baseWorkspace === null) {
             throw new WorkspaceException(sprintf('The specified workspace "%s" is not a base workspace of "%s".', $targetWorkspace->getName(), $this->getName()), 1289499117);
         }
         $baseWorkspace = $baseWorkspace->getBaseWorkspace();
     }
 }
示例#11
0
 /**
  * Sets the workspace of this node.
  *
  * This method is only for internal use by the content repository. Changing
  * the workspace of a node manually may lead to unexpected behavior.
  *
  * @param Workspace $workspace
  * @return void
  */
 public function setWorkspace(Workspace $workspace)
 {
     if (!$this->isNodeDataMatchingContext()) {
         $this->materializeNodeData();
     }
     if ($this->getWorkspace()->getName() === $workspace->getName()) {
         return;
     }
     $this->nodeData->setWorkspace($workspace);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeUpdated($this);
 }