/** * Creates a new Content Context object. * * NOTE: This is for internal use only, you should use the ContextFactory for creating Context instances. * * @param string $workspaceName Name of the current workspace * @param \DateTimeInterface $currentDateTime The current date and time * @param array $dimensions Array of dimensions with array of ordered values * @param array $targetDimensions Array of dimensions used when creating / modifying content * @param boolean $invisibleContentShown If invisible content should be returned in query results * @param boolean $removedContentShown If removed content should be returned in query results * @param boolean $inaccessibleContentShown If inaccessible content should be returned in query results * @param Site $currentSite The current Site object * @param Domain $currentDomain The current Domain object * @see ContextFactoryInterface */ public function __construct($workspaceName, \DateTimeInterface $currentDateTime, array $dimensions, array $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown, Site $currentSite = null, Domain $currentDomain = null) { parent::__construct($workspaceName, $currentDateTime, $dimensions, $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown); $this->currentSite = $currentSite; $this->currentDomain = $currentDomain; $this->targetDimensions = $targetDimensions; }
/** * Search all properties for given $term * * TODO: Implement a better search when Flow offer the possibility * * @param string|array $term search term * @param array $searchNodeTypes * @param Context $context * @param NodeInterface $startingPoint * @return array <\Neos\ContentRepository\Domain\Model\NodeInterface> */ public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null) { if (empty($term)) { throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285); } $searchResult = array(); $nodeTypeFilter = implode(',', $searchNodeTypes); $nodeDataRecords = $this->nodeDataRepository->findByProperties($term, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $startingPoint ? $startingPoint->getPath() : null); foreach ($nodeDataRecords as $nodeData) { $node = $this->nodeFactory->createFromNodeData($nodeData, $context); if ($node !== null) { $searchResult[$node->getPath()] = $node; } } return $searchResult; }
/** * Internal method * * The dimension value of this node has to match the current target dimension value (must be higher in priority or equal) * * @return boolean */ public function dimensionsAreMatchingTargetDimensionValues() { $dimensions = $this->getDimensions(); $contextDimensions = $this->context->getDimensions(); foreach ($this->context->getTargetDimensions() as $dimensionName => $targetDimensionValue) { if (!isset($dimensions[$dimensionName])) { if ($targetDimensionValue === null) { continue; } else { return false; } } elseif ($targetDimensionValue === null && $dimensions[$dimensionName] === array()) { continue; } elseif (!in_array($targetDimensionValue, $dimensions[$dimensionName], true)) { $contextDimensionValues = $contextDimensions[$dimensionName]; $targetPositionInContext = array_search($targetDimensionValue, $contextDimensionValues, true); $nodePositionInContext = min(array_map(function ($value) use($contextDimensionValues) { return array_search($value, $contextDimensionValues, true); }, $dimensions[$dimensionName])); $val = $targetPositionInContext !== false && $nodePositionInContext !== false && $targetPositionInContext >= $nodePositionInContext; if ($val === false) { return false; } } } return true; }
/** * @test */ public function sortByDateTimeDescending() { $nodesToSort = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array())]; $correctOrder = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array())]; $flowQuery = new \Neos\Eel\FlowQuery\FlowQuery($nodesToSort); $operation = new SortOperation(); $operation->evaluate($flowQuery, ['_lastPublicationDateTime', 'DESC']); $this->assertEquals($correctOrder, $flowQuery->getContext()); }
/** * @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')); }
/** * @test */ public function createNodeFromTemplateUsesWorkspacesOfContext() { $nodeTemplate = $this->generateBasicNodeTemplate(); $userWorkspace = new Workspace('user1', $this->liveWorkspace); $this->workspaceRepository->add($userWorkspace); $this->context = $this->contextFactory->create(array('workspaceName' => 'user1')); $rootNode = $this->context->getNode('/'); $node = $rootNode->createNodeFromTemplate($nodeTemplate, 'just-a-node'); $workspace = $node->getWorkspace(); $this->assertEquals('user1', $workspace->getName(), 'Node should be created in workspace of context'); }
/** * @return void */ protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get(ContextFactory::class); $this->context = $this->contextFactory->create(array('workspaceName' => 'live')); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add(new Workspace('live')); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->rootNode = $this->context->getNode('/'); $this->persistenceManager->persistAll(); }
/** * @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(); }
public function setUp() { $this->convertUrisImplementation = $this->getAccessibleMock(ConvertUrisImplementation::class, array('tsValue'), array(), '', false); $this->mockWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock(); $this->mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->mockContext->expects($this->any())->method('getWorkspace')->will($this->returnValue($this->mockWorkspace)); $this->mockNode = $this->getMockBuilder(NodeInterface::class)->getMock(); $this->mockNode->expects($this->any())->method('getContext')->will($this->returnValue($this->mockContext)); $this->mockHttpUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); $this->mockHttpUri->expects($this->any())->method('getHost')->will($this->returnValue('localhost')); $this->mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockHttpUri)); $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest)); $this->mockControllerContext = $this->getMockBuilder(ControllerContext::class)->disableOriginalConstructor()->getMock(); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockActionRequest)); $this->mockLinkingService = $this->createMock(LinkingService::class); $this->convertUrisImplementation->_set('linkingService', $this->mockLinkingService); $this->mockTsRuntime = $this->getMockBuilder(Runtime::class)->disableOriginalConstructor()->getMock(); $this->mockTsRuntime->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->convertUrisImplementation->_set('tsRuntime', $this->mockTsRuntime); }
/** * @test */ public function nodeWithRelatedEntitiesWillTakeCareOfAddingToPersistence() { $identifier = Algorithms::generateUUID(); $template = new NodeTemplate(); $template->setName('new-node'); $template->setIdentifier($identifier); $newEntity = new Fixtures\RelatedEntity(); $newEntity->setFavoritePlace('Reykjavik'); $anotherNewEntity = new Fixtures\RelatedEntity(); $anotherNewEntity->setFavoritePlace('Japan'); $template->setProperty('entity', array($newEntity, $anotherNewEntity)); $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNodeFromTemplate($template); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->inject($this->contextFactory, 'contextInstances', array()); $newLiveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $newNodeAgain = $newLiveContext->getNode('/new-node'); $entityArray = $newNodeAgain->getProperty('entity'); $this->assertCount(2, $entityArray); $this->assertEquals('Japan', $entityArray[1]->getFavoritePlace()); }
/** * Filter a node by the current context. * Will either return the node or NULL if it is not permitted in current context. * * @param NodeInterface $node * @param Context $context * @return NodeInterface|NULL */ protected function filterNodeByContext(NodeInterface $node, Context $context) { $this->securityContext->withoutAuthorizationChecks(function () use(&$node, $context) { if (!$context->isRemovedContentShown() && $node->isRemoved()) { $node = null; return; } if (!$context->isInvisibleContentShown() && !$node->isVisible()) { $node = null; return; } if (!$context->isInaccessibleContentShown() && !$node->isAccessible()) { $node = null; } }); return $node; }
/** * * * @param NodeInterface $node * @param Context $context * @param $recursive * @return void */ public function beforeAdoptNode(NodeInterface $node, Context $context, $recursive) { if (!$this->eventEmittingService->isEnabled()) { return; } $this->initializeAccountIdentifier(); if ($this->currentlyAdopting === 0) { /* @var $nodeEvent NodeEvent */ $nodeEvent = $this->eventEmittingService->emit(self::NODE_ADOPT, array('targetWorkspace' => $context->getWorkspaceName(), 'targetDimensions' => $context->getTargetDimensions(), 'recursive' => $recursive), NodeEvent::class); $nodeEvent->setNode($node); $this->eventEmittingService->pushContext(); } $this->currentlyAdopting++; }
/** * Finds a single node by its parent and (optionally) by its node type * * @param string $parentPath Absolute path of the parent node * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text" or NULL) * @param Context $context The containing context * @return NodeData The node found or NULL */ public function findFirstByParentAndNodeTypeInContext($parentPath, $nodeTypeFilter, Context $context) { $firstNode = $this->findFirstByParentAndNodeType($parentPath, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $context->isRemovedContentShown() ? null : false); if ($firstNode !== null) { $firstNode = $this->nodeFactory->createFromNodeData($firstNode, $context); } return $firstNode; }
/** * Iterates through the given $properties setting them on the specified $node using the appropriate TypeConverters. * * @param object $nodeLike * @param NodeType $nodeType * @param array $properties * @param TYPO3CRContext $context * @param PropertyMappingConfigurationInterface $configuration * @return void * @throws TypeConverterException */ protected function setNodeProperties($nodeLike, NodeType $nodeType, array $properties, TYPO3CRContext $context, PropertyMappingConfigurationInterface $configuration = null) { $nodeTypeProperties = $nodeType->getProperties(); unset($properties['_lastPublicationDateTime']); foreach ($properties as $nodePropertyName => $nodePropertyValue) { if (substr($nodePropertyName, 0, 2) === '__') { continue; } $nodePropertyType = isset($nodeTypeProperties[$nodePropertyName]['type']) ? $nodeTypeProperties[$nodePropertyName]['type'] : null; switch ($nodePropertyType) { case 'reference': $nodePropertyValue = $context->getNodeByIdentifier($nodePropertyValue); break; case 'references': $nodeIdentifiers = json_decode($nodePropertyValue); $nodePropertyValue = array(); if (is_array($nodeIdentifiers)) { foreach ($nodeIdentifiers as $nodeIdentifier) { $referencedNode = $context->getNodeByIdentifier($nodeIdentifier); if ($referencedNode !== null) { $nodePropertyValue[] = $referencedNode; } } } elseif ($nodeIdentifiers !== null) { throw new TypeConverterException(sprintf('node type "%s" expects an array of identifiers for its property "%s"', $nodeType->getName(), $nodePropertyName), 1383587419); } break; case 'DateTime': if ($nodePropertyValue !== '' && ($nodePropertyValue = \DateTime::createFromFormat(\DateTime::W3C, $nodePropertyValue)) !== false) { $nodePropertyValue->setTimezone(new \DateTimeZone(date_default_timezone_get())); } else { $nodePropertyValue = null; } break; case 'integer': $nodePropertyValue = intval($nodePropertyValue); break; case 'boolean': if (is_string($nodePropertyValue)) { $nodePropertyValue = $nodePropertyValue === 'true' ? true : false; } break; case 'array': $nodePropertyValue = json_decode($nodePropertyValue, true); break; } if (substr($nodePropertyName, 0, 1) === '_') { $nodePropertyName = substr($nodePropertyName, 1); ObjectAccess::setProperty($nodeLike, $nodePropertyName, $nodePropertyValue); continue; } if (!isset($nodeTypeProperties[$nodePropertyName])) { if ($configuration !== null && $configuration->shouldSkipUnknownProperties()) { continue; } else { throw new TypeConverterException(sprintf('Node type "%s" does not have a property "%s" according to the schema', $nodeType->getName(), $nodePropertyName), 1359552744); } } $innerType = $nodePropertyType; if ($nodePropertyType !== null) { try { $parsedType = TypeHandling::parseType($nodePropertyType); $innerType = $parsedType['elementType'] ?: $parsedType['type']; } catch (InvalidTypeException $exception) { } } if (is_string($nodePropertyValue) && $this->objectManager->isRegistered($innerType) && $nodePropertyValue !== '') { $nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, true), $nodePropertyType, $configuration); } $nodeLike->setProperty($nodePropertyName, $nodePropertyValue); } }