/** * Find all nodes of a specific node type * * @param string $nodeType * @param ContentContext $context current content context, see class doc comment for details * @return array<NodeInterface> all nodes of type $nodeType in the current $context */ protected function getNodes($nodeType, ContentContext $context) { $nodes = array(); $siteNode = $context->getCurrentSiteNode(); foreach ($this->nodeDataRepository->findByParentAndNodeTypeRecursively($siteNode->getPath(), $nodeType, $context->getWorkspace()) as $nodeData) { $nodes[] = $this->nodeFactory->createFromNodeData($nodeData, $context); } return $nodes; }
/** * @test */ public function findByParentAndNodeTypeRecursivelyCallsGetNodeDataForParentAndNodeTypeWithRecursiveFlag() { $parentPath = 'some/parent/path'; $nodeTypeFilter = 'Some.Package:SomeNodeType'; $mockWorkspace = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace')->disableOriginalConstructor()->getMock(); $dimensions = array('persona' => array('everybody'), 'language' => array('de_DE', 'mul_ZZ')); $removedNodesFlag = TRUE; $recursiveFlag = TRUE; $this->nodeDataRepository->expects($this->once())->method('getNodeDataForParentAndNodeType')->with($parentPath, $nodeTypeFilter, $mockWorkspace, $dimensions, $removedNodesFlag, $recursiveFlag)->will($this->returnValue(array())); $this->nodeDataRepository->findByParentAndNodeTypeRecursively($parentPath, $nodeTypeFilter, $mockWorkspace, $dimensions, TRUE); }
/** * 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('TYPO3.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); }
/** * Remove broken entity references * * This removes references from nodes to entities which don't exist anymore. * * @param string $workspaceName * @param boolean $dryRun * @return void */ public function removeBrokenEntityReferences($workspaceName, $dryRun) { $this->output->outputLine('Checking for broken entity references ...'); /** @var \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace */ $workspace = $this->workspaceRepository->findByIdentifier($workspaceName); $nodeTypesWithEntityReferences = array(); foreach ($this->nodeTypeManager->getNodeTypes() as $nodeType) { /** @var NodeType $nodeType */ foreach (array_keys($nodeType->getProperties()) as $propertyName) { $propertyType = $nodeType->getPropertyType($propertyName); if (strpos($propertyType, '\\') !== false) { if (!isset($nodeTypesWithEntityReferences[$nodeType->getName()])) { $nodeTypesWithEntityReferences[$nodeType->getName()] = array(); } $nodeTypesWithEntityReferences[$nodeType->getName()][$propertyName] = $propertyType; } } } $nodesWithBrokenEntityReferences = array(); $brokenReferencesCount = 0; foreach ($nodeTypesWithEntityReferences as $nodeTypeName => $properties) { $nodeDatas = $this->nodeDataRepository->findByParentAndNodeTypeRecursively('/', $nodeTypeName, $workspace); foreach ($nodeDatas as $nodeData) { /** @var NodeData $nodeData */ foreach ($properties as $propertyName => $propertyType) { $propertyValue = $nodeData->getProperty($propertyName); $convertedProperty = null; if (is_object($propertyValue)) { $convertedProperty = $propertyValue; } if (is_string($propertyValue) && strlen($propertyValue) === 36) { $convertedProperty = $this->propertyMapper->convert($propertyValue, $propertyType); if ($convertedProperty === null) { $nodesWithBrokenEntityReferences[$nodeData->getIdentifier()][$propertyName] = $nodeData; $this->output->outputLine('Broken reference in "%s", property "%s" (%s) referring to %s.', array($nodeData->getPath(), $nodeData->getIdentifier(), $propertyName, $propertyType, $propertyValue)); $brokenReferencesCount++; } } if ($convertedProperty instanceof \Doctrine\ORM\Proxy\Proxy) { try { $convertedProperty->__load(); } catch (EntityNotFoundException $e) { $nodesWithBrokenEntityReferences[$nodeData->getIdentifier()][$propertyName] = $nodeData; $this->output->outputLine('Broken reference in "%s", property "%s" (%s) referring to %s.', array($nodeData->getPath(), $nodeData->getIdentifier(), $propertyName, $propertyType, $propertyValue)); $brokenReferencesCount++; } } } } } if ($brokenReferencesCount > 0) { $this->output->outputLine(); if (!$dryRun) { $self = $this; $this->askBeforeExecutingTask('Do you want to remove the broken entity references?', function () use($self, $nodesWithBrokenEntityReferences, $brokenReferencesCount, $workspaceName, $dryRun) { foreach ($nodesWithBrokenEntityReferences as $nodeIdentifier => $properties) { foreach ($properties as $propertyName => $nodeData) { /** @var NodeData $nodeData */ $nodeData->setProperty($propertyName, null); } } $self->output->outputLine('Removed %s broken entity reference%s.', array($brokenReferencesCount, $brokenReferencesCount > 1 ? 's' : '')); }); } else { $this->output->outputLine('Found %s broken entity reference%s to be removed.', array($brokenReferencesCount, $brokenReferencesCount > 1 ? 's' : '')); } $this->output->outputLine(); } }
/** * 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()))); }