/**
  * Helper method for creating a new node.
  *
  * @param NodeInterface $referenceNode
  * @param array $nodeData
  * @param string $position
  * @return NodeInterface
  * @throws \InvalidArgumentException
  */
 public function create(NodeInterface $referenceNode, array $nodeData, $position)
 {
     if (!in_array($position, array('before', 'into', 'after'), true)) {
         throw new \InvalidArgumentException('The position should be one of the following: "before", "into", "after".', 1347133640);
     }
     $nodeType = $this->nodeTypeManager->getNodeType($nodeData['nodeType']);
     if ($nodeType->isOfType('Neos.Neos:Document') && !isset($nodeData['properties']['uriPathSegment']) && isset($nodeData['properties']['title'])) {
         $nodeData['properties']['uriPathSegment'] = $this->nodeUriPathSegmentGenerator->generateUriPathSegment($referenceNode, $nodeData['properties']['title']);
     }
     $proposedNodeName = isset($nodeData['nodeName']) ? $nodeData['nodeName'] : null;
     $nodeData['nodeName'] = $this->nodeService->generateUniqueNodeName($this->getDesignatedParentNode($referenceNode, $position)->getPath(), $proposedNodeName);
     if ($position === 'into') {
         $newNode = $referenceNode->createNode($nodeData['nodeName'], $nodeType);
     } else {
         $parentNode = $referenceNode->getParent();
         $newNode = $parentNode->createNode($nodeData['nodeName'], $nodeType);
         if ($position === 'before') {
             $newNode->moveBefore($referenceNode);
         } else {
             $newNode->moveAfter($referenceNode);
         }
     }
     if (isset($nodeData['properties']) && is_array($nodeData['properties'])) {
         foreach ($nodeData['properties'] as $propertyName => $propertyValue) {
             $newNode->setProperty($propertyName, $propertyValue);
         }
     }
     return $newNode;
 }
 /**
  * Repair inconsistent nodes
  *
  * This command analyzes and repairs the node tree structure and individual nodes
  * based on the current node type configuration.
  *
  * It is possible to execute only one or more specific checks by providing the <b>--skip</b>
  * or <b>--only</b> option. See the full description of checks further below for possible check
  * identifiers.
  *
  * The following checks will be performed:
  *
  * {pluginDescriptions}
  * <b>Examples:</b>
  *
  * ./flow node:repair
  *
  * ./flow node:repair --node-type Neos.NodeTypes:Page
  *
  * ./flow node:repair --workspace user-robert --only removeOrphanNodes,removeNodesWithInvalidDimensions
  *
  * ./flow node:repair --skip removeUndefinedProperties
  *
  * @param string $nodeType Node type name, if empty update all declared node types
  * @param string $workspace Workspace name, default is 'live'
  * @param boolean $dryRun Don't do anything, but report actions
  * @param boolean $cleanup If FALSE, cleanup tasks are skipped
  * @param string $skip Skip the given check or checks (comma separated)
  * @param string $only Only execute the given check or checks (comma separated)
  * @return void
  */
 public function repairCommand($nodeType = null, $workspace = 'live', $dryRun = false, $cleanup = true, $skip = null, $only = null)
 {
     $this->pluginConfigurations = self::detectPlugins($this->objectManager);
     if ($this->workspaceRepository->countByName($workspace) === 0) {
         $this->outputLine('Workspace "%s" does not exist', array($workspace));
         exit(1);
     }
     if ($nodeType !== null) {
         if ($this->nodeTypeManager->hasNodeType($nodeType)) {
             $nodeType = $this->nodeTypeManager->getNodeType($nodeType);
         } else {
             $this->outputLine('Node type "%s" does not exist', array($nodeType));
             exit(1);
         }
     }
     if ($dryRun) {
         $this->outputLine('Dry run, not committing any changes.');
     }
     if (!$cleanup) {
         $this->outputLine('Omitting cleanup tasks.');
     }
     foreach ($this->pluginConfigurations as $pluginConfiguration) {
         /** @var NodeCommandControllerPluginInterface $plugin */
         $plugin = $pluginConfiguration['object'];
         $this->outputLine('<b>' . $plugin->getSubCommandShortDescription('repair') . '</b>');
         $this->outputLine();
         $plugin->invokeSubCommand('repair', $this->output, $nodeType, $workspace, $dryRun, $cleanup, $skip, $only);
         $this->outputLine();
     }
     $this->outputLine('Node repair finished.');
 }
 /**
  * Returns the node types that the currently authenticated user is *denied* to create within the given $referenceNode
  *
  * @param NodeInterface $referenceNode
  * @return string[] Array of granted node type names
  */
 public function getNodeTypeNamesDeniedForCreation(NodeInterface $referenceNode)
 {
     $privilegeSubject = new CreateNodePrivilegeSubject($referenceNode);
     $allNodeTypes = $this->nodeTypeManager->getNodeTypes();
     $deniedCreationNodeTypes = array();
     $grantedCreationNodeTypes = array();
     $abstainedCreationNodeTypes = array();
     foreach ($this->securityContext->getRoles() as $role) {
         /** @var CreateNodePrivilege $createNodePrivilege */
         foreach ($role->getPrivilegesByType(CreateNodePrivilege::class) as $createNodePrivilege) {
             if (!$createNodePrivilege->matchesSubject($privilegeSubject)) {
                 continue;
             }
             $affectedNodeTypes = $createNodePrivilege->getCreationNodeTypes() !== array() ? $createNodePrivilege->getCreationNodeTypes() : $allNodeTypes;
             if ($createNodePrivilege->isGranted()) {
                 $grantedCreationNodeTypes = array_merge($grantedCreationNodeTypes, $affectedNodeTypes);
             } elseif ($createNodePrivilege->isDenied()) {
                 $deniedCreationNodeTypes = array_merge($deniedCreationNodeTypes, $affectedNodeTypes);
             } else {
                 $abstainedCreationNodeTypes = array_merge($abstainedCreationNodeTypes, $affectedNodeTypes);
             }
         }
     }
     $implicitlyDeniedNodeTypes = array_diff($abstainedCreationNodeTypes, $grantedCreationNodeTypes);
     return array_merge($implicitlyDeniedNodeTypes, $deniedCreationNodeTypes);
 }
 /**
  * Converts the nodes types to a fully structured array
  * in the same structure as the schema to be created.
  *
  * The schema also includes abstract node types for the full inheritance information in VIE.
  *
  * @return object
  */
 public function generateVieSchema()
 {
     if ($this->configuration !== null) {
         return $this->configuration;
     }
     $nodeTypes = $this->nodeTypeManager->getNodeTypes();
     foreach ($nodeTypes as $nodeTypeName => $nodeType) {
         $this->readNodeTypeConfiguration($nodeTypeName, $nodeType);
     }
     unset($this->types['typo3:unstructured']);
     foreach ($this->types as $nodeTypeName => $nodeTypeDefinition) {
         $this->types[$nodeTypeName]->subtypes = $this->getAllSubtypes($nodeTypeName);
         $this->types[$nodeTypeName]->ancestors = $this->getAllAncestors($nodeTypeName);
         $this->removeUndeclaredTypes($this->types[$nodeTypeName]->supertypes);
         $this->removeUndeclaredTypes($this->types[$nodeTypeName]->ancestors);
     }
     foreach ($this->properties as $property => $propertyConfiguration) {
         if (isset($propertyConfiguration->domains) && is_array($propertyConfiguration->domains)) {
             foreach ($propertyConfiguration->domains as $domain) {
                 if (preg_match('/TYPO3\\.Neos\\.NodeTypes:.*Column/', $domain)) {
                     $this->properties[$property]->ranges = array_keys($this->types);
                 }
             }
         }
     }
     // Convert the Neos.Neos:ContentCollection element to support content-collection
     // TODO Move to node type definition
     if (isset($this->types['typo3:Neos.Neos:ContentCollection'])) {
         $this->addProperty('typo3:Neos.Neos:ContentCollection', 'typo3:content-collection', array());
         $this->types['typo3:Neos.Neos:ContentCollection']->specific_properties[] = 'typo3:content-collection';
         $this->properties['typo3:content-collection']->ranges = array_keys($this->types);
     }
     $this->configuration = (object) array('types' => (object) $this->types, 'properties' => (object) $this->properties);
     return $this->configuration;
 }
 /**
  * @test
  */
 public function readNodeTypeConfigurationFillsTypeAndPropertyConfiguration()
 {
     $this->assertEquals($this->vieSchemaBuilder->_get('superTypeConfiguration'), array());
     $this->assertEquals($this->vieSchemaBuilder->_get('types'), array());
     $this->assertEquals($this->vieSchemaBuilder->_get('properties'), array());
     $this->vieSchemaBuilder->_call('readNodeTypeConfiguration', 'Neos.Neos:TextWithImage', $this->nodeTypeManager->getNodeType('Neos.Neos:TextWithImage'));
     $this->assertEquals(array('typo3:Neos.Neos:TextWithImage' => array('typo3:Neos.Neos:Text')), $this->vieSchemaBuilder->_get('superTypeConfiguration'));
     $this->arrayHasKey('typo3:Neos.Neos:TextWithImage', $this->vieSchemaBuilder->_get('types'));
     $this->assertEquals(4, count($this->vieSchemaBuilder->_get('properties')));
 }
 public function setUp()
 {
     $this->mockWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock();
     $this->nodeData = $this->getAccessibleMock(NodeData::class, array('addOrUpdate'), array('/foo/bar', $this->mockWorkspace));
     $this->mockNodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->getMock();
     $this->mockNodeTypeManager = $this->getMockBuilder(NodeTypeManager::class)->disableOriginalConstructor()->getMock();
     $this->mockNodeTypeManager->expects($this->any())->method('getNodeType')->will($this->returnValue($this->mockNodeType));
     $this->mockNodeTypeManager->expects($this->any())->method('hasNodeType')->will($this->returnValue(true));
     $this->inject($this->nodeData, 'nodeTypeManager', $this->mockNodeTypeManager);
     $this->mockNodeDataRepository = $this->getMockBuilder(NodeDataRepository::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->nodeData, 'nodeDataRepository', $this->mockNodeDataRepository);
 }
 /**
  * @param QueryInterface $query
  * @param $nodeTypeFilter
  * @return array
  */
 protected function getNodeTypeFilterConstraints(QueryInterface $query, $nodeTypeFilter)
 {
     $includeNodeTypeConstraints = [];
     $excludeNodeTypeConstraints = [];
     $nodeTypeFilterParts = Arrays::trimExplode(',', $nodeTypeFilter);
     foreach ($nodeTypeFilterParts as $nodeTypeFilterPart) {
         $nodeTypeFilterPart = trim($nodeTypeFilterPart);
         if (strpos($nodeTypeFilterPart, '!') === 0) {
             $negate = true;
             $nodeTypeFilterPart = substr($nodeTypeFilterPart, 1);
         } else {
             $negate = false;
         }
         $nodeTypeFilterPartSubTypes = array_merge([$nodeTypeFilterPart], $this->nodeTypeManager->getSubNodeTypes($nodeTypeFilterPart, false));
         foreach ($nodeTypeFilterPartSubTypes as $nodeTypeFilterPartSubType) {
             if ($negate === true) {
                 $excludeNodeTypeConstraints[] = $query->logicalNot($query->equals('nodeType', $nodeTypeFilterPartSubType));
             } else {
                 $includeNodeTypeConstraints[] = $query->equals('nodeType', $nodeTypeFilterPartSubType);
             }
         }
     }
     $constraints = $excludeNodeTypeConstraints;
     if (count($includeNodeTypeConstraints) > 0) {
         $constraints[] = $query->logicalOr($includeNodeTypeConstraints);
     }
     return $constraints;
 }
 /**
  * Create a new empty site.
  *
  * @param string $packageKey Package Name to create
  * @param string $siteName Site Name to create
  * @param string $nodeType NodeType name for the root node to create
  * @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator")
  * @return void
  */
 public function createSiteNodeAction($packageKey, $siteName, $nodeType)
 {
     $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $siteName);
     if ($this->siteRepository->findOneByNodeName($nodeName)) {
         $this->addFlashMessage('Error:A site with siteNodeName "%s" already exists', Message::SEVERITY_ERROR, [$nodeName], 1412372375);
         $this->redirect('createSiteNode');
     }
     $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
     if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') {
         $this->addFlashMessage('Error: The given node type "%s" was not found', 'Import error', Message::SEVERITY_ERROR, [$nodeType], 1412372375);
         $this->redirect('createSiteNode');
     }
     if ($siteNodeType->isOfType('Neos.Neos:Document') === false) {
         $this->addFlashMessage('Error: The given node type "%s" is not based on the superType "%s"', Message::SEVERITY_ERROR, [$nodeType, 'Neos.Neos:Document'], 1412372375);
         $this->redirect('createSiteNode');
     }
     $rootNode = $this->nodeContextFactory->create()->getRootNode();
     // We fetch the workspace to be sure it's known to the persistence manager and persist all
     // so the workspace and site node are persisted before we import any nodes to it.
     $rootNode->getContext()->getWorkspace();
     $this->persistenceManager->persistAll();
     $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH);
     if ($sitesNode === null) {
         $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH));
     }
     $siteNode = $sitesNode->createNode($nodeName, $siteNodeType);
     $siteNode->setProperty('title', $siteName);
     $site = new Site($nodeName);
     $site->setSiteResourcesPackageKey($packageKey);
     $site->setState(Site::STATE_ONLINE);
     $site->setName($siteName);
     $this->siteRepository->add($site);
     $this->addFlashMessage('Successfully created site "%s" with siteNode "%s", type "%s" and packageKey "%s"', '', null, [$siteName, $nodeName, $nodeType, $packageKey], 1412372266);
     $this->unsetLastVisitedNodeAndRedirect('index');
 }
 /**
  * @test
  */
 public function inheritanceBasedConstraintsWork()
 {
     $testingNodeTypeWithSubnodes = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithSubnodes');
     $testingNodeTypeThatInheritsFromDocumentType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Page');
     $nodeWithChildNode = $this->rootNode->createNode('node-with-child-node', $testingNodeTypeWithSubnodes);
     $nodeWithChildNode->createNode('page', $testingNodeTypeThatInheritsFromDocumentType);
     $this->assertCount(2, $nodeWithChildNode->getChildNodes());
 }
 /**
  * Render the label for the given $nodeTypeName
  *
  * @param string $nodeTypeName
  * @throws NodeTypeNotFoundException
  * @return string
  */
 public function labelForNodeType($nodeTypeName)
 {
     if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
         $explodedNodeTypeName = explode(':', $nodeTypeName);
         return end($explodedNodeTypeName);
     }
     $nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
     return $nodeType->getLabel();
 }
 /**
  * @test
  */
 public function getChildNodesWithNodeTypeFilterWorks()
 {
     $documentNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Document');
     $headlineNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Headline');
     $imageNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Image');
     $node = $this->context->getRootNode()->createNode('node-with-child-node', $documentNodeType);
     $node->createNode('headline', $headlineNodeType);
     $node->createNode('text', $imageNodeType);
     $this->assertCount(1, $node->getChildNodes('Neos.ContentRepository.Testing:Headline'));
 }
 /**
  * Search a page, needed for internal links.
  *
  * @deprecated will be removed with 3.0, use Service/NodesController->indexAction() instead
  * @param string $query
  * @return void
  */
 public function searchPageAction($query)
 {
     $searchResult = array();
     $documentNodeTypes = $this->nodeTypeManager->getSubNodeTypes('Neos.Neos:Document');
     /** @var NodeInterface $node */
     foreach ($this->nodeSearchService->findByProperties($query, $documentNodeTypes, $this->createContext('live')) as $node) {
         $searchResult[$node->getPath()] = $this->processNodeForEditorPlugins($node);
     }
     $this->view->assign('value', array('searchResult' => $searchResult, 'success' => true));
 }
 /**
  * @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException
  */
 protected function createNodesForNodeSearchTest()
 {
     $rootNode = $this->context->getRootNode();
     $newNode1 = $rootNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType'));
     $newNode1->setProperty('test1', 'simpleTestValue');
     $newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType'));
     $newNode2->setProperty('test2', 'simpleTestValue');
     $newNode2 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType'));
     $newNode2->setProperty('test1', 'otherValue');
     $this->persistenceManager->persistAll();
 }
 /**
  * @param string|array $nodeTypes
  * @return PropertyConditionGenerator
  */
 public function nodeIsOfType($nodeTypes)
 {
     $propertyConditionGenerator = new PropertyConditionGenerator('nodeType');
     if (!is_array($nodeTypes)) {
         $nodeTypes = array($nodeTypes);
     }
     $expandedNodeTypeNames = array();
     foreach ($nodeTypes as $nodeTypeName) {
         $subNodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeTypeName, false);
         $expandedNodeTypeNames = array_merge($expandedNodeTypeNames, array($nodeTypeName), array_keys($subNodeTypes));
     }
     return $propertyConditionGenerator->in(array_unique($expandedNodeTypeNames));
 }
 /**
  * @test
  */
 public function aSingleNodeExportedWithNodeDataExportCanBeImportedWithNodeDataImport()
 {
     $originalNode = $this->rootNode->createNode('foo', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:ImportExport'));
     $originalNode->setProperty('description', 'Some node with a property');
     $originalNode->setProperty('someDate', new \DateTime());
     $this->persistenceManager->persistAll();
     $exportService = new NodeExportService();
     $xml = $exportService->export('/')->outputMemory();
     $this->nodeDataRepository->removeAll();
     $this->workspaceRepository->removeAll();
     $this->saveNodesAndTearDownRootNodeAndRepository();
     $this->setUpRootNodeAndRepository();
     $importService = new NodeImportService();
     $reader = new \XMLReader();
     $reader->XML($xml);
     $importService->import($reader, '/');
     $importedNode = $this->rootNode->getNode('foo');
     $this->assertNotNull($importedNode, 'Expected node not found');
     $this->assertSame($originalNode->getIdentifier(), $importedNode->getIdentifier());
     $this->assertSame($originalNode->getProperty('description'), $importedNode->getProperty('description'));
     $this->assertEquals($originalNode->getProperty('someDate'), $importedNode->getProperty('someDate'));
 }
 /**
  * Return an array with child nodes which should be automatically created
  *
  * @return array the key of this array is the name of the child, and the value its NodeType.
  * @api
  */
 public function getAutoCreatedChildNodes()
 {
     $this->initialize();
     if (!isset($this->fullConfiguration['childNodes'])) {
         return array();
     }
     $autoCreatedChildNodes = array();
     foreach ($this->fullConfiguration['childNodes'] as $childNodeName => $childNodeConfiguration) {
         if (isset($childNodeConfiguration['type'])) {
             $autoCreatedChildNodes[Utility::renderValidNodeName($childNodeName)] = $this->nodeTypeManager->getNodeType($childNodeConfiguration['type']);
         }
     }
     return $autoCreatedChildNodes;
 }
 /**
  * Shows a list of nodes
  *
  * @param string $searchTerm An optional search term used for filtering the list of nodes
  * @param array $nodeIdentifiers An optional list of node identifiers
  * @param string $workspaceName Name of the workspace to search in, "live" by default
  * @param array $dimensions Optional list of dimensions and their values which should be used for querying
  * @param array $nodeTypes A list of node types the list should be filtered by
  * @param NodeInterface $contextNode a node to use as context for the search
  * @return string
  */
 public function indexAction($searchTerm = '', array $nodeIdentifiers = array(), $workspaceName = 'live', array $dimensions = array(), array $nodeTypes = array('Neos.Neos:Document'), NodeInterface $contextNode = null)
 {
     $searchableNodeTypeNames = array();
     foreach ($nodeTypes as $nodeTypeName) {
         if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
             $this->throwStatus(400, sprintf('Unknown node type "%s"', $nodeTypeName));
         }
         $searchableNodeTypeNames[$nodeTypeName] = $nodeTypeName;
         /** @var NodeType $subNodeType */
         foreach ($this->nodeTypeManager->getSubNodeTypes($nodeTypeName, false) as $subNodeTypeName => $subNodeType) {
             $searchableNodeTypeNames[$subNodeTypeName] = $subNodeTypeName;
         }
     }
     $contentContext = $this->createContentContext($workspaceName, $dimensions);
     if ($nodeIdentifiers === array()) {
         $nodes = $this->nodeSearchService->findByProperties($searchTerm, $searchableNodeTypeNames, $contentContext, $contextNode);
     } else {
         $nodes = array_map(function ($identifier) use($contentContext) {
             return $contentContext->getNodeByIdentifier($identifier);
         }, $nodeIdentifiers);
     }
     $this->view->assign('nodes', $nodes);
 }
 /**
  * Detects the requested node type and returns a corresponding NodeType instance.
  *
  * @param string $targetType
  * @param array $source
  * @return NodeType
  */
 protected function extractNodeType($targetType, array $source)
 {
     if (isset($source['__nodeType'])) {
         $nodeTypeName = $source['__nodeType'];
     } else {
         $matches = array();
         preg_match(self::EXTRACT_CONTENT_TYPE_PATTERN, $targetType, $matches);
         if (isset($matches['nodeType'])) {
             $nodeTypeName = $matches['nodeType'];
         } else {
             $nodeTypeName = 'unstructured';
         }
     }
     return $this->nodeTypeManager->getNodeType($nodeTypeName);
 }
 /**
  * Reorder child nodes for the given node type
  *
  * @param string $workspaceName
  * @param boolean $dryRun
  * @param NodeType $nodeType
  * @return void
  */
 protected function reorderChildNodesByNodeType($workspaceName, $dryRun, NodeType $nodeType)
 {
     $nodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false);
     $nodeTypes[$nodeType->getName()] = $nodeType;
     if ($this->nodeTypeManager->hasNodeType((string) $nodeType)) {
         $nodeType = $this->nodeTypeManager->getNodeType((string) $nodeType);
         $nodeTypeNames[$nodeType->getName()] = $nodeType;
     } else {
         $this->output->outputLine('Node type "%s" does not exist', array((string) $nodeType));
         exit(1);
     }
     /** @var $nodeType NodeType */
     foreach ($nodeTypes as $nodeTypeName => $nodeType) {
         $childNodes = $nodeType->getAutoCreatedChildNodes();
         if ($childNodes === array()) {
             continue;
         }
         foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) {
             /** @var NodeInterface $childNodeBefore */
             $childNodeBefore = null;
             $context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
             $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
             if (!$node instanceof NodeInterface) {
                 continue;
             }
             foreach ($childNodes as $childNodeName => $childNodeType) {
                 $childNode = $node->getNode($childNodeName);
                 if ($childNode) {
                     if ($childNodeBefore) {
                         if ($dryRun === false) {
                             if ($childNodeBefore->getIndex() >= $childNode->getIndex()) {
                                 $childNode->moveAfter($childNodeBefore);
                                 $this->output->outputLine('Moved node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
                             }
                         } else {
                             $this->output->outputLine('Should move node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
                         }
                     }
                 } else {
                     $this->output->outputLine('Missing child node named "%s" in "%s".', array($childNodeName, $node->getPath()));
                 }
                 $childNodeBefore = $childNode;
             }
         }
     }
 }
 /**
  * @Then /^I should get the list of all available node types as denied node types for this node from the node authorization service$/
  */
 public function iShouldGetTheListOfAllAvailableNodeTypesAsDeniedNodeTypesForThisNodeFromTheNodeAuthorizationService()
 {
     if ($this->isolated === true) {
         $this->callStepInSubProcess(__METHOD__);
     } else {
         $availableNodeTypes = $this->nodeTypeManager->getNodeTypes();
         $deniedNodeTypeNames = $this->nodeAuthorizationService->getNodeTypeNamesDeniedForCreation($this->currentNodes[0]);
         if (count($availableNodeTypes) !== count($deniedNodeTypeNames)) {
             Assert::fail('The node authorization service did not return the expected amount of node type names! Got: ' . implode(', ', $deniedNodeTypeNames));
         }
         foreach ($availableNodeTypes as $nodeType) {
             if (in_array($nodeType, $deniedNodeTypeNames) === false) {
                 Assert::fail('The following node type name has not been returned by the node authorization service: ' . $nodeType);
             }
         }
     }
 }
 /**
  * Fetch a PluginView definition that matches the specified controller and action combination
  *
  * @param string $controllerObjectName
  * @param string $actionName
  * @return PluginViewDefinition
  * @throws Neos\Exception if more than one PluginView matches the given controller/action pair
  */
 public function getPluginViewDefinitionByAction($controllerObjectName, $actionName)
 {
     $pluginNodeTypes = $this->nodeTypeManager->getSubNodeTypes('Neos.Neos:Plugin', false);
     $matchingPluginViewDefinitions = [];
     foreach ($pluginNodeTypes as $pluginNodeType) {
         /** @var $pluginViewDefinition PluginViewDefinition */
         foreach ($this->getPluginViewDefinitionsByPluginNodeType($pluginNodeType) as $pluginViewDefinition) {
             if ($pluginViewDefinition->matchesControllerActionPair($controllerObjectName, $actionName) !== true) {
                 continue;
             }
             $matchingPluginViewDefinitions[] = $pluginViewDefinition;
         }
     }
     if (count($matchingPluginViewDefinitions) > 1) {
         throw new Neos\Exception(sprintf('More than one PluginViewDefinition found for controller "%s", action "%s":%s', $controllerObjectName, $actionName, chr(10) . implode(chr(10), $matchingPluginViewDefinitions)), 1377597671);
     }
     return count($matchingPluginViewDefinitions) > 0 ? current($matchingPluginViewDefinitions) : null;
 }
Example #22
0
 /**
  * Return child nodes of specified node for usage in a TreeLoader based on filter
  *
  * @param Node $node The node to find child nodes for
  * @param string $term
  * @param string $nodeType
  * @return void
  */
 public function filterChildNodesForTreeAction(Node $node, $term, $nodeType)
 {
     $nodeTypes = strlen($nodeType) > 0 ? array($nodeType) : array_keys($this->nodeTypeManager->getSubNodeTypes('Neos.Neos:Document', false));
     $context = $node->getContext();
     if ($term !== '') {
         $nodes = $this->nodeSearchService->findByProperties($term, $nodeTypes, $context, $node);
     } else {
         $nodes = array();
         $nodeDataRecords = $this->nodeDataRepository->findByParentAndNodeTypeRecursively($node->getPath(), implode(',', $nodeTypes), $context->getWorkspace(), $context->getDimensions());
         foreach ($nodeDataRecords as $nodeData) {
             $matchedNode = $this->nodeFactory->createFromNodeData($nodeData, $context);
             if ($matchedNode !== null) {
                 $nodes[$matchedNode->getPath()] = $matchedNode;
             }
         }
     }
     $this->view->assignFilteredChildNodes($node, $nodes);
 }
 /**
  * Converts the specified $source into a Node.
  *
  * If $source is a UUID it is expected to refer to the identifier of a NodeData record of the "live" workspace
  *
  * Otherwise $source has to be a valid node path:
  *
  * The node path must be an absolute context node path and can be specified as a string or as an array item with the
  * key "__contextNodePath". The latter case is for updating existing nodes.
  *
  * This conversion method does not support / allow creation of new nodes because new nodes should be created through
  * the createNode() method of an existing reference node.
  *
  * Also note that the context's "current node" is not affected by this object converter, you will need to set it to
  * whatever node your "current" node is, if any.
  *
  * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated
  * by this converter.
  *
  * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node
  * object.
  *
  * All other elements, not being prefixed with underscore, are properties of the node.
  *
  * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin"
  * @param string $targetType not used
  * @param array $subProperties not used
  * @param PropertyMappingConfigurationInterface $configuration
  * @return mixed An object or \Neos\Error\Messages\Error if the input format is not supported or could not be converted for other reasons
  * @throws NodeException
  */
 public function convertFrom($source, $targetType = null, array $subProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
 {
     if (is_string($source)) {
         $source = array('__contextNodePath' => $source);
     }
     if (!is_array($source) || !isset($source['__contextNodePath'])) {
         return new Error('Could not convert ' . gettype($source) . ' to Node object, a valid absolute context node path as a string or array is expected.', 1302879936);
     }
     try {
         $nodePathAndContext = NodePaths::explodeContextPath($source['__contextNodePath']);
         $nodePath = $nodePathAndContext['nodePath'];
         $workspaceName = $nodePathAndContext['workspaceName'];
         $dimensions = $nodePathAndContext['dimensions'];
     } catch (\InvalidArgumentException $exception) {
         return new Error('Could not convert array to Node object because the node path was invalid.', 1285162903);
     }
     $context = $this->contextFactory->create($this->prepareContextProperties($workspaceName, $configuration, $dimensions));
     $workspace = $context->getWorkspace(false);
     if (!$workspace) {
         return new Error(sprintf('Could not convert the given source to Node object because the workspace "%s" as specified in the context node path does not exist.', $workspaceName), 1383577859);
     }
     $node = $context->getNode($nodePath);
     if (!$node) {
         return new Error(sprintf('Could not convert array to Node object because the node "%s" does not exist.', $nodePath), 1370502328);
     }
     if (isset($source['_nodeType']) && $source['_nodeType'] !== $node->getNodeType()->getName()) {
         if ($context->getWorkspace()->getName() === 'live') {
             throw new NodeException('Could not convert the node type in live workspace', 1429989736);
         }
         $oldNodeType = $node->getNodeType();
         $targetNodeType = $this->nodeTypeManager->getNodeType($source['_nodeType']);
         $node->setNodeType($targetNodeType);
         $this->nodeService->setDefaultValues($node);
         $this->nodeService->cleanUpAutoCreatedChildNodes($node, $oldNodeType);
         $this->nodeService->createChildNodes($node);
     }
     unset($source['_nodeType']);
     $this->setNodeProperties($node, $node->getNodeType(), $source, $context, $configuration);
     return $node;
 }
 /**
  * Create a new site
  *
  * This command allows to create a blank site with just a single empty document in the default dimension.
  * The name of the site, the packageKey must be specified.
  *
  * If no ``nodeType`` option is specified the command will use `Neos.Neos.NodeTypes:Page` as fallback. The node type
  * must already exists and have the superType ``Neos.Neos:Document``.
  *
  * If no ``nodeName` option is specified the command will create a unique node-name from the name of the site.
  * If a node name is given it has to be unique for the setup.
  *
  * If the flag ``activate` is set to false new site will not be activated.
  *
  * @param string $name The name of the site
  * @param string $packageKey The site package
  * @param string $nodeType The node type to use for the site node. (Default = Neos.Neos.NodeTypes:Page)
  * @param string $nodeName The name of the site node. If no nodeName is given it will be determined from the siteName.
  * @param boolean $inactive The new site is not activated immediately (default = false).
  * @return void
  */
 public function createCommand($name, $packageKey, $nodeType = 'Neos.Neos.NodeTypes:Page', $nodeName = null, $inactive = false)
 {
     if ($nodeName === null) {
         $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $name);
     }
     if ($this->siteRepository->findOneByNodeName($nodeName)) {
         $this->outputLine('<error>A site with siteNodeName "%s" already exists</error>', [$nodeName]);
         $this->quit(1);
     }
     if ($this->packageManager->isPackageAvailable($packageKey) === false) {
         $this->outputLine('<error>Could not find package "%s"</error>', [$packageKey]);
         $this->quit(1);
     }
     $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType);
     if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') {
         $this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]);
         $this->quit(1);
     }
     if ($siteNodeType->isOfType('Neos.Neos:Document') === false) {
         $this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'Neos.Neos:Document']);
         $this->quit(1);
     }
     $rootNode = $this->nodeContextFactory->create()->getRootNode();
     // We fetch the workspace to be sure it's known to the persistence manager and persist all
     // so the workspace and site node are persisted before we import any nodes to it.
     $rootNode->getContext()->getWorkspace();
     $this->persistenceManager->persistAll();
     $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH);
     if ($sitesNode === null) {
         $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH));
     }
     $siteNode = $sitesNode->createNode($nodeName, $siteNodeType);
     $siteNode->setProperty('title', $name);
     $site = new Site($nodeName);
     $site->setSiteResourcesPackageKey($packageKey);
     $site->setState($inactive ? Site::STATE_OFFLINE : Site::STATE_ONLINE);
     $site->setName($name);
     $this->siteRepository->add($site);
     $this->outputLine('Successfully created site "%s" with siteNode "%s", type "%s", packageKey "%s" and state "%s"', [$name, $nodeName, $nodeType, $packageKey, $inactive ? 'offline' : 'online']);
 }
 /**
  * Generate the list of allowed sub-node-types per parent-node-type and child-node-name.
  *
  * @return array constraints
  */
 protected function generateConstraints()
 {
     $constraints = array();
     $nodeTypes = $this->nodeTypeManager->getNodeTypes(true);
     /** @var NodeType $nodeType */
     foreach ($nodeTypes as $nodeTypeName => $nodeType) {
         $constraints[$nodeTypeName] = array('nodeTypes' => array(), 'childNodes' => array());
         foreach ($nodeTypes as $innerNodeTypeName => $innerNodeType) {
             if ($nodeType->allowsChildNodeType($innerNodeType)) {
                 $constraints[$nodeTypeName]['nodeTypes'][$innerNodeTypeName] = true;
             }
         }
         foreach ($nodeType->getAutoCreatedChildNodes() as $key => $_x) {
             foreach ($nodeTypes as $innerNodeTypeName => $innerNodeType) {
                 if ($nodeType->allowsGrandchildNodeType($key, $innerNodeType)) {
                     $constraints[$nodeTypeName]['childNodes'][$key]['nodeTypes'][$innerNodeTypeName] = true;
                 }
             }
         }
     }
     return $constraints;
 }
Example #26
0
 /**
  * Generate TypoScript prototype definitions for all node types
  *
  * Only fully qualified node types (e.g. MyVendor.MyPackage:NodeType) will be considered.
  *
  * @return string
  */
 protected function generateNodeTypeDefinitions()
 {
     $code = '';
     /** @var NodeType $nodeType */
     foreach ($this->nodeTypeManager->getNodeTypes(false) as $nodeType) {
         $code .= $this->generateTypoScriptForNodeType($nodeType);
     }
     return $code;
 }
 /**
  * Returns the node type of this node.
  *
  * @return \Neos\ContentRepository\Domain\Model\NodeType
  */
 public function getNodeType()
 {
     return $this->nodeTypeManager->getNodeType($this->nodeType);
 }
 /**
  * @test
  * @expectedException \Neos\ContentRepository\Exception\NodeTypeIsFinalException
  */
 public function getNodeTypeThrowsExceptionIfFinalNodeTypeIsSubclassed()
 {
     $nodeTypesFixture = array('Neos.ContentRepository.Testing:Base' => array('final' => true), 'Neos.ContentRepository.Testing:Sub' => array('superTypes' => array('Neos.ContentRepository.Testing:Base' => true)));
     $this->prepareNodeTypeManager($nodeTypesFixture);
     $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Sub');
 }
 /**
  * Change the Node Type on the given node.
  *
  * @param NodeData $node
  * @return void
  */
 public function execute(NodeData $node)
 {
     $nodeType = $this->nodeTypeManager->getNodeType($this->newType);
     $node->setNodeType($nodeType);
 }