/** * Returns node by the specified node type * * @param string $nodeType Type of node to be searched. * @param array $ignoreNodes Array of node paths which need to be ignored. * @return \TYPO3\Flow\Persistence\QueryResultInterface */ public function findByNodeTypeAndCurrentSite($nodeType, $ignoreNodes = NULL) { if ($ignoreNodes === NULL) { $ignoreNodes[] = ''; } $query = $this->nodeDataRepository->createQuery(); $constraints = array($query->equals('nodeType', $nodeType), $query->logicalNot($query->in('path', $ignoreNodes))); return $query->matching($query->logicalAnd($constraints))->execute(); }
/** * Remove all nodes, workspaces, domains and sites. * * @return void */ public function pruneAll() { $sites = $this->siteRepository->findAll(); $this->nodeDataRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->domainRepository->removeAll(); $this->siteRepository->removeAll(); foreach ($sites as $site) { $this->emitSitePruned($site); } }
/** * Execute the migration * * @return void */ public function execute() { foreach ($this->nodeDataRepository->findAll() as $node) { foreach ($this->configuration as $migrationDescription) { if ($this->nodeFilterService->matchFilters($node, $migrationDescription['filters'])) { $this->nodeTransformationService->execute($node, $migrationDescription['transformations']); if (!$this->nodeDataRepository->isInRemovedNodes($node)) { $this->nodeDataRepository->update($node); } } } } }
protected function saveNodesAndTearDownRootNodeAndRepository() { if ($this->nodeDataRepository !== NULL) { $this->nodeDataRepository->flushNodeRegistry(); } /** @var \TYPO3\TYPO3CR\Domain\Factory\NodeFactory $nodeFactory */ $nodeFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Factory\\NodeFactory'); $nodeFactory->reset(); $this->contextFactory->reset(); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->nodeDataRepository = NULL; $this->rootNode = NULL; }
/** * Remove given site all nodes for that site and all domains associated. * * @param Site $site * @return void */ public function pruneSite(Site $site) { $siteNodePath = NodePaths::addNodePathSegment(static::SITES_ROOT_PATH, $site->getNodeName()); $this->nodeDataRepository->removeAllInPath($siteNodePath); $siteNodes = $this->nodeDataRepository->findByPath($siteNodePath); foreach ($siteNodes as $siteNode) { $this->nodeDataRepository->remove($siteNode); } $domainsForSite = $this->domainRepository->findBySite($site); foreach ($domainsForSite as $domain) { $this->domainRepository->remove($domain); } $this->siteRepository->remove($site); $this->emitSitePruned($site); }
/** * @param \TYPO3\Form\Core\Model\FinisherContext $finisherContext * @return void * @throws \TYPO3\Setup\Exception */ public function importSite(\TYPO3\Form\Core\Model\FinisherContext $finisherContext) { $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues(); if (isset($formValues['prune']) && intval($formValues['prune']) === 1) { $this->nodeDataRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->domainRepository->removeAll(); $this->siteRepository->removeAll(); $this->persistenceManager->persistAll(); } if (!empty($formValues['packageKey'])) { if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) { throw new \TYPO3\Setup\Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486); } $packageKey = $formValues['packageKey']; $siteName = $formValues['siteName']; $generatorService = $this->objectManager->get('TYPO3\\Neos\\Kickstarter\\Service\\GeneratorService'); $generatorService->generateSitePackage($packageKey, $siteName); } elseif (!empty($formValues['site'])) { $packageKey = $formValues['site']; } $this->deactivateOtherSitePackages($packageKey); $this->packageManager->activatePackage($packageKey); if (!empty($packageKey)) { try { $contentContext = $this->contextFactory->create(array('workspaceName' => 'live')); $this->siteImportService->importFromPackage($packageKey, $contentContext); } catch (\Exception $exception) { $finisherContext->cancel(); $this->systemLogger->logException($exception); throw new SetupException(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage()), 1351000864); } } }
/** * Remove dimensions on nodes "/" and "/sites" * * This empties the content dimensions on those nodes, so when traversing via the Node API from the root node, * the nodes below "/sites" are always reachable. * * @param string $workspaceName * @param boolean $dryRun * @return void */ public function removeContentDimensionsFromRootAndSitesNode($workspaceName, $dryRun) { $workspace = $this->workspaceRepository->findByIdentifier($workspaceName); $rootNodes = $this->nodeDataRepository->findByPath('/', $workspace); $sitesNodes = $this->nodeDataRepository->findByPath('/sites', $workspace); $this->output->outputLine('Checking for root and site nodes with content dimensions set ...'); /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $rootNode */ foreach ($rootNodes as $rootNode) { if ($rootNode->getDimensionValues() !== []) { if ($dryRun === false) { $rootNode->setDimensions([]); $this->nodeDataRepository->update($rootNode); $this->output->outputLine('Removed content dimensions from root node'); } else { $this->output->outputLine('Found root node with content dimensions set.'); } } } /** @var \TYPO3\TYPO3CR\Domain\Model\NodeData $sitesNode */ foreach ($sitesNodes as $sitesNode) { if ($sitesNode->getDimensionValues() !== []) { if ($dryRun === false) { $sitesNode->setDimensions([]); $this->nodeDataRepository->update($sitesNode); $this->output->outputLine('Removed content dimensions from node "/sites"'); } else { $this->output->outputLine('Found node "/sites"'); } } } }
/** * @test */ public function findNodesByPropertyKeyAndValue() { $this->createNodesForNodeSearchTest(); $result = $this->nodeDataRepository->findByProperties(array('test2' => 'simpleTestValue'), 'TYPO3.TYPO3CR.Testing:NodeType', $this->liveWorkspace, $this->context->getDimensions()); $this->assertCount(1, $result); $this->assertEquals('test-node-2', array_shift($result)->getName()); }
/** * Search all properties for given $term * * TODO: Implement a better search when Flow offer the possibility * * @param string $term * @param array $searchNodeTypes * @param Context $context * @param NodeInterface $startingPoint * @return array <\TYPO3\TYPO3CR\Domain\Model\NodeInterface> */ public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null) { if (strlen($term) === 0) { 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; }
/** * Method which does the actual work of discarding, includes a protection against endless recursions and * multiple discarding of the same node. * * @param NodeInterface $node The node to discard * @param array &$alreadyDiscardedNodeIdentifiers List of node identifiers which already have been discarded during one discardNode() run * @return void * @throws \TYPO3\TYPO3CR\Exception\WorkspaceException */ protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = []) { if ($node->getWorkspace()->getBaseWorkspace() === null) { throw new WorkspaceException('Nodes in a in a workspace without a base workspace cannot be discarded.', 1395841899); } if ($node->getPath() === '/') { return; } if (array_search($node->getIdentifier(), $alreadyDiscardedNodeIdentifiers) !== false) { return; } $alreadyDiscardedNodeIdentifiers[] = $node->getIdentifier(); $possibleShadowNodeData = $this->nodeDataRepository->findOneByMovedTo($node->getNodeData()); if ($possibleShadowNodeData instanceof NodeData) { if ($possibleShadowNodeData->getMovedTo() !== null) { $parentBasePath = $node->getPath(); $affectedChildNodeDataInSameWorkspace = $this->nodeDataRepository->findByParentAndNodeType($parentBasePath, null, $node->getWorkspace(), null, false, true); foreach ($affectedChildNodeDataInSameWorkspace as $affectedChildNodeData) { /** @var NodeData $affectedChildNodeData */ $affectedChildNode = $this->nodeFactory->createFromNodeData($affectedChildNodeData, $node->getContext()); $this->doDiscardNode($affectedChildNode, $alreadyDiscardedNodeIdentifiers); } } $this->nodeDataRepository->remove($possibleShadowNodeData); } $this->nodeDataRepository->remove($node); $this->emitNodeDiscarded($node); }
/** * Removes unused ImageVariants after a Node property changes to a different ImageVariant. * This is triggered via the nodePropertyChanged event. * * Note: This method it triggered by the "nodePropertyChanged" signal, @see \TYPO3\TYPO3CR\Domain\Model\Node::emitNodePropertyChanged() * * @param NodeInterface $node the affected node * @param string $propertyName name of the property that has been changed/added * @param mixed $oldValue the property value before it was changed or NULL if the property is new * @param mixed $value the new property value * @return void */ public function removeUnusedImageVariant(NodeInterface $node, $propertyName, $oldValue, $value) { if ($oldValue === $value || !$oldValue instanceof ImageVariant) { return; } $identifier = $this->persistenceManager->getIdentifierByObject($oldValue); $results = $this->nodeDataRepository->findNodesByRelatedEntities(array(ImageVariant::class => [$identifier])); // This case shouldn't happen as the query will usually find at least the node that triggered this call, still if there is no relation we can remove the ImageVariant. if ($results === []) { $this->assetRepository->remove($oldValue); return; } // If the result contains exactly the node that got a new ImageVariant assigned then we are safe to remove the asset here. if ($results === [$node->getNodeData()]) { $this->assetRepository->remove($oldValue); } }
/** * @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 \TYPO3\Eel\FlowQuery\FlowQuery($nodesToSort); $operation = new SortOperation(); $operation->evaluate($flowQuery, ['_lastPublicationDateTime', 'DESC']); $this->assertEquals($correctOrder, $flowQuery->getContext()); }
/** * 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; }
/** * Given a context a new node is returned that is like this node, but * lives in the new context. * * @param \TYPO3\TYPO3CR\Domain\Service\Context $context * @return NodeInterface */ public function createVariantForContext($context) { $nodeData = clone $this->nodeData; $nodeData->adjustToContext($context); $this->nodeDataRepository->add($nodeData); $node = $this->nodeFactory->createFromNodeData($nodeData, $context); $this->context->getFirstLevelNodeCache()->flush(); $this->emitNodeAdded($node); return $node; }
/** * @Flow\Around("method(TYPO3\Flow\Mvc\Routing\Router->resolve())") * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point * @return mixed */ public function addTargetNodeToArguments(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { if (!isset($this->settings['targetNodeMappings']) || !is_array($this->settings['targetNodeMappings'])) { return $joinPoint->getAdviceChain()->proceed($joinPoint); } $arguments = $joinPoint->getMethodArgument('routeValues'); foreach ($this->settings['targetNodeMappings'] as $pluginNamespace => $pluginTargetNodeMappings) { $pluginNamespace = '--' . $pluginNamespace; if (!isset($arguments[$pluginNamespace]) || !is_array($arguments[$pluginNamespace])) { continue; } $pluginArguments = $arguments[$pluginNamespace]; foreach ($pluginTargetNodeMappings as $pluginTargetNodeMapping) { if (isset($pluginTargetNodeMapping['package']) && (!isset($pluginArguments['@package']) || strtolower($pluginArguments['@package']) !== strtolower($pluginTargetNodeMapping['package']))) { continue; } if (isset($pluginTargetNodeMapping['controller']) && (!isset($pluginArguments['@controller']) || strtolower($pluginArguments['@controller']) !== strtolower($pluginTargetNodeMapping['controller']))) { continue; } if (isset($pluginTargetNodeMapping['action']) && (!isset($pluginArguments['@action']) || strtolower($pluginArguments['@action']) !== strtolower($pluginTargetNodeMapping['action']))) { continue; } if (isset($pluginTargetNodeMapping['targetNamespace'])) { unset($arguments[$pluginNamespace]); $arguments['--' . $pluginTargetNodeMapping['targetNamespace']] = $pluginArguments; } $nodeIdentifier = $pluginTargetNodeMapping['targetNode']; $node = $this->nodeDataRepository->findOneByIdentifier($nodeIdentifier, $this->createContext()->getWorkspace()); if ($node === NULL) { throw new \TYPO3\Flow\Exception('no node with identifier "' . $nodeIdentifier . '" found', 1334172725); } $arguments['node'] = $node->getContextPath(); $arguments['@package'] = 'TYPO3.Neos'; $arguments['@controller'] = 'Frontend\\Node'; $arguments['@format'] = 'html'; $arguments['@action'] = 'show'; $joinPoint->setMethodArgument('routeValues', $arguments); return $joinPoint->getAdviceChain()->proceed($joinPoint); } } return $joinPoint->getAdviceChain()->proceed($joinPoint); }
/** * Performs checks for orphan nodes removes them if found. * * @param NodeType $nodeType Only for this node type, if specified * @param string $workspaceName * @param boolean $dryRun Simulate? * @return void */ public function removeUndefinedProperties(NodeType $nodeType = NULL, $workspaceName, $dryRun) { $this->output->outputLine('Checking for undefined properties ...'); /** @var \TYPO3\TYPO3CR\Domain\Model\Workspace $workspace */ $workspace = $this->workspaceRepository->findByIdentifier($workspaceName); $nodesWithUndefinedPropertiesNodes = array(); $undefinedPropertiesCount = 0; $nodes = $nodeType !== NULL ? $this->getNodeDataByNodeTypeAndWorkspace($nodeType, $workspaceName) : $this->nodeDataRepository->findByWorkspace($workspace); foreach ($nodes as $nodeData) { try { /** @var NodeData $nodeData */ if ($nodeData->getNodeType()->getName() === 'unstructured') { continue; } $context = $this->nodeFactory->createContextMatchingNodeData($nodeData); $node = $this->nodeFactory->createFromNodeData($nodeData, $context); if (!$node instanceof NodeInterface) { continue; } $nodeType = $node->getNodeType(); $undefinedProperties = array_diff(array_keys($node->getProperties()), array_keys($nodeType->getProperties())); if ($undefinedProperties !== array()) { $nodesWithUndefinedPropertiesNodes[$node->getIdentifier()] = array('node' => $node, 'undefinedProperties' => $undefinedProperties); foreach ($undefinedProperties as $undefinedProperty) { $undefinedPropertiesCount++; $this->output->outputLine('Found undefined property named "%s" in "%s" (%s)', array($undefinedProperty, $node->getPath(), $node->getNodeType()->getName())); } } } catch (NodeTypeNotFoundException $exception) { $this->output->outputLine('Skipped undefined node type in "%s"', array($nodeData->getPath())); } } if ($undefinedPropertiesCount > 0) { $this->output->outputLine(); if (!$dryRun) { $self = $this; $this->askBeforeExecutingTask('Do you want to remove undefined node properties?', function () use($self, $nodesWithUndefinedPropertiesNodes, $undefinedPropertiesCount, $workspaceName, $dryRun) { foreach ($nodesWithUndefinedPropertiesNodes as $nodesWithUndefinedPropertiesNode) { /** @var NodeInterface $node */ $node = $nodesWithUndefinedPropertiesNode['node']; foreach ($nodesWithUndefinedPropertiesNode['undefinedProperties'] as $undefinedProperty) { if ($node->hasProperty($undefinedProperty)) { $node->removeProperty($undefinedProperty); } } } $self->output->outputLine('Removed %s undefined propert%s.', array($undefinedPropertiesCount, $undefinedPropertiesCount > 1 ? 'ies' : 'y')); }); } else { $this->output->outputLine('Found %s undefined propert%s to be removed.', array($undefinedPropertiesCount, $undefinedPropertiesCount > 1 ? 'ies' : 'y')); } $this->output->outputLine(); } }
/** * Checks if the given node path can be used for the given node. * * @param string $nodePath * @param NodeInterface $node * @return boolean */ public function nodePathAvailableForNode($nodePath, NodeInterface $node) { /** @var NodeData $existingNodeData */ $existingNodeDataObjects = $this->nodeDataRepository->findByPathWithoutReduce($nodePath, $node->getWorkspace(), true); foreach ($existingNodeDataObjects as $existingNodeData) { if ($existingNodeData->getMovedTo() !== null && $existingNodeData->getMovedTo() === $node->getNodeData()) { return true; } } return !$this->nodePathExistsInAnyContext($nodePath); }
/** * 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; }
/** * @test */ public function findNodesByRelatedEntitiesFindsExistingNodeWithMatchingEntityProperty() { $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNode('test', $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeTypeWithEntities')); $testImage = new Image(); $this->persistenceManager->add($testImage); $newNode->setProperty('image', $testImage); $this->persistenceManager->persistAll(); $relationMap = array('TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\Image' => array($this->persistenceManager->getIdentifierByObject($testImage))); $result = $this->nodeDataRepository->findNodesByRelatedEntities($relationMap); $this->assertCount(1, $result); }
/** * getRandomProducts * * @param Context $context * @param NodeInterface $startingPointProducts * * @return array */ private function getRandomProducts(Context $context, NodeInterface $startingPointProducts) { $searchResult = array(); $randomProducts = $this->nodeDataRepository->findByParentAndNodeTypeInContext($startingPointProducts->getPath(), 'Egobude.Products:Product', $context, TRUE); if (!empty($randomProducts)) { foreach ($randomProducts as $node) { /* @var $node \TYPO3\TYPO3CR\Domain\Model\NodeInterface */ $searchResult[] = $node->getIdentifier(); } shuffle($searchResult); $searchResult = array_slice($searchResult, mt_rand(1, count($searchResult))); } return $searchResult; }
/** * Finds all nodes lying on the path specified by (and including) the given * starting point and end point. * * @param mixed $startingPoint Either an absolute path or an actual node specifying the starting point, for example /sites/mysite.com/ * @param mixed $endPoint Either an absolute path or an actual node specifying the end point, for example /sites/mysite.com/homepage/subpage * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeInterface> The nodes found between and including the given paths or an empty array of none were found * @api */ public function getNodesOnPath($startingPoint, $endPoint) { $startingPointPath = $startingPoint instanceof \TYPO3\TYPO3CR\Domain\Model\NodeInterface ? $startingPoint->getPath() : $startingPoint; $endPointPath = $endPoint instanceof \TYPO3\TYPO3CR\Domain\Model\NodeInterface ? $endPoint->getPath() : $endPoint; $nodeDataElements = $this->nodeDataRepository->findOnPath($startingPointPath, $endPointPath, $this->getWorkspace(), $this->getDimensions(), $this->isRemovedContentShown()); $nodes = array(); foreach ($nodeDataElements as $nodeData) { $node = $this->nodeFactory->createFromNodeData($nodeData, $this); if ($node !== NULL) { $nodes[] = $node; } } return $nodes; }
/** * Delete an asset * * @param \TYPO3\Media\Domain\Model\Asset $asset * @return void */ public function deleteAction(\TYPO3\Media\Domain\Model\Asset $asset) { $relationMap = []; $relationMap[TypeHandling::getTypeForValue($asset)] = array($this->persistenceManager->getIdentifierByObject($asset)); if ($asset instanceof \TYPO3\Media\Domain\Model\Image) { foreach ($asset->getVariants() as $variant) { $type = TypeHandling::getTypeForValue($variant); if (!isset($relationMap[$type])) { $relationMap[$type] = []; } $relationMap[$type][] = $this->persistenceManager->getIdentifierByObject($variant); } } $relatedNodes = $this->nodeDataRepository->findNodesByRelatedEntities($relationMap); if (count($relatedNodes) > 0) { $this->addFlashMessage('Asset could not be deleted, because there are still Nodes using it.', '', Message::SEVERITY_WARNING, array(), 1412422767); $this->redirect('index'); } // FIXME: Resources are not deleted, because we cannot be sure that the resource isn't used anywhere else. $this->assetRepository->remove($asset); $this->addFlashMessage(sprintf('Asset "%s" has been deleted.', $asset->getLabel()), null, null, array(), 1412375050); $this->redirect('index'); }
protected function saveNodesAndTearDownRootNodeAndRepository() { if ($this->nodeDataRepository !== null) { $this->nodeDataRepository->flushNodeRegistry(); } /** @var NodeFactory $nodeFactory */ $nodeFactory = $this->objectManager->get(NodeFactory::class); $nodeFactory->reset(); $this->contextFactory->reset(); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->nodeDataRepository = null; $this->rootNode = null; }
/** * @test */ public function findByParentAndNodeTypeRemovesRemovedNodeInRepositoryAndRespectsWorkspaceAndDimensions() { $liveWorkspace = new Workspace('live'); $nodeData = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData')->disableOriginalConstructor()->getMock(); $nodeData->expects($this->any())->method('getIdentifier')->will($this->returnValue('abcd-efgh-ijkl-mnop')); $nodeData->expects($this->any())->method('getPath')->will($this->returnValue('/foo/bar')); $nodeData->expects($this->any())->method('getDepth')->will($this->returnValue(2)); $this->nodeDataRepository->remove($nodeData); $dimensions = array('persona' => array('everybody'), 'language' => array('de_DE', 'mul_ZZ')); $nodeData->expects($this->atLeastOnce())->method('matchesWorkspaceAndDimensions')->with($liveWorkspace, $dimensions)->will($this->returnValue(TRUE)); $this->nodeDataRepository->expects($this->any())->method('getNodeDataForParentAndNodeType')->will($this->returnValue(array('abcd-efgh-ijkl-mnop' => $nodeData))); $result = $this->nodeDataRepository->findByParentAndNodeType('/foo', NULL, $liveWorkspace, $dimensions); $this->assertCount(0, $result); }
/** * Discards the given node. * * @param NodeInterface $node * @return void * @throws \TYPO3\TYPO3CR\Exception\WorkspaceException * @api */ public function discardNode(NodeInterface $node) { if ($node->getWorkspace()->getBaseWorkspace() === NULL) { throw new WorkspaceException('Nodes in a in a workspace without a base workspace cannot be discarded.', 1395841899); } $possibleShadowNodeData = $this->nodeDataRepository->findOneByMovedTo($node->getNodeData()); if ($possibleShadowNodeData !== NULL) { $this->nodeDataRepository->remove($possibleShadowNodeData); } if ($node->getPath() !== '/') { $this->nodeDataRepository->remove($node); $this->emitNodeDiscarded($node); } }
/** * Remove all nodes, workspaces, domains and sites. * * @param boolean $confirmation * @return void */ public function pruneCommand($confirmation = FALSE) { if ($confirmation === FALSE) { $this->outputLine('Please confirm that you really want to remove all content from the database.'); $this->outputLine(''); $this->outputLine('Syntax:'); $this->outputLine(' ./flow facets:prune --confirmation TRUE'); exit; } $this->nodeDataRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->domainRepository->removeAll(); $this->siteRepository->removeAll(); $this->outputLine('Database cleared'); }
/** * @param \TYPO3\Media\Domain\Model\Asset $asset * @return array */ protected function getRelatedNodes(\TYPO3\Media\Domain\Model\Asset $asset) { $relationMap = []; $relationMap[TypeHandling::getTypeForValue($asset)] = [$this->persistenceManager->getIdentifierByObject($asset)]; if ($asset instanceof \TYPO3\Media\Domain\Model\Image) { foreach ($asset->getVariants() as $variant) { $type = TypeHandling::getTypeForValue($variant); if (!isset($relationMap[$type])) { $relationMap[$type] = []; } $relationMap[$type][] = $this->persistenceManager->getIdentifierByObject($variant); } } return $this->nodeDataRepository->findNodesByRelatedEntities($relationMap); }
/** * Finds all nodes lying on the path specified by (and including) the given * starting point and end point. * * @param mixed $startingPoint Either an absolute path or an actual node specifying the starting point, for example /sites/mysitecom * @param mixed $endPoint Either an absolute path or an actual node specifying the end point, for example /sites/mysitecom/homepage/subpage * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeInterface> The nodes found between and including the given paths or an empty array of none were found * @api */ public function getNodesOnPath($startingPoint, $endPoint) { $startingPointPath = $startingPoint instanceof NodeInterface ? $startingPoint->getPath() : $startingPoint; $endPointPath = $endPoint instanceof NodeInterface ? $endPoint->getPath() : $endPoint; $nodeDataElements = $this->nodeDataRepository->findOnPath($startingPointPath, $endPointPath, $this->getWorkspace(), $this->getDimensions(), $this->isRemovedContentShown()); $nodes = array(); foreach ($nodeDataElements as $nodeData) { $node = $this->nodeFactory->createFromNodeData($nodeData, $this); if ($node !== null) { $nodes[] = $node; $this->firstLevelNodeCache->setByPath($node->getPath(), $node); } } return $nodes; }
/** * Materializes the original node data (of a different workspace) into the current * workspace. * * @return void */ protected function materializeNodeData() { $dimensions = $this->context->getTargetDimensionValues(); $newNodeData = new NodeData($this->nodeData->getPath(), $this->context->getWorkspace(), $this->nodeData->getIdentifier(), $dimensions); $this->nodeDataRepository->add($newNodeData); $newNodeData->similarize($this->nodeData); $this->nodeData = $newNodeData; $this->nodeDataIsMatchingContext = true; $nodeType = $this->getNodeType(); foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) { $childNode = $this->getNode($childNodeName); if ($childNode instanceof Node && !$childNode->isNodeDataMatchingContext()) { $childNode->materializeNodeData(); } } }
/** * Find all nodes of the specified workspace lying below the path specified by * (and including) the given starting point. * * @param string $pathStartingPoint Absolute path specifying the starting point * @param string $workspace The containing workspace * @param string $nodeTypeFilter * @return array an array of node-data in array format. */ protected function findNodeDataListToExport($pathStartingPoint, $workspace = 'live', $nodeTypeFilter = null) { /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */ $queryBuilder = $this->entityManager->createQueryBuilder(); $queryBuilder->select('n.path AS path,' . ' n.identifier AS identifier,' . ' n.index AS sortingIndex,' . ' n.properties AS properties, ' . ' n.nodeType AS nodeType,' . ' n.removed AS removed,' . ' n.hidden,' . ' n.hiddenBeforeDateTime AS hiddenBeforeDateTime,' . ' n.hiddenAfterDateTime AS hiddenAfterDateTime,' . ' n.creationDateTime AS creationDateTime,' . ' n.lastModificationDateTime AS lastModificationDateTime,' . ' n.lastPublicationDateTime AS lastPublicationDateTime,' . ' n.hiddenInIndex AS hiddenInIndex,' . ' n.accessRoles AS accessRoles,' . ' n.version AS version,' . ' n.parentPath AS parentPath,' . ' n.pathHash AS pathHash,' . ' n.dimensionsHash AS dimensionsHash,' . ' n.parentPathHash AS parentPathHash,' . ' n.dimensionValues AS dimensionValues,' . ' w.name AS workspace')->distinct()->from('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', 'n')->innerJoin('n.workspace', 'w', 'WITH', 'n.workspace=w.name')->where('n.workspace = :workspace')->setParameter('workspace', $workspace)->andWhere('n.path = :pathPrefix OR n.path LIKE :pathPrefixMatch')->setParameter('pathPrefix', $pathStartingPoint)->setParameter('pathPrefixMatch', $pathStartingPoint === '/' ? '%' : $pathStartingPoint . '/%')->orderBy('n.identifier', 'ASC')->orderBy('n.path', 'ASC'); if ($nodeTypeFilter) { $this->nodeDataRepository->addNodeTypeFilterConstraintsToQueryBuilder($queryBuilder, $nodeTypeFilter); } $nodeDataList = $queryBuilder->getQuery()->getResult(); // Sort nodeDataList by path, replacing "/" with "!" (the first visible ASCII character) // because there may be characters like "-" in the node path // that would break the sorting order usort($nodeDataList, function ($node1, $node2) { return strcmp(str_replace("/", "!", $node1['path']), str_replace("/", "!", $node2['path'])); }); return $nodeDataList; }