/** * Performs checks for orphan nodes removes them if found. * * @param string $workspaceName * @param boolean $dryRun Simulate? * @param NodeType $nodeType Only for this node type, if specified * @return void */ public function removeUndefinedProperties($workspaceName, $dryRun, NodeType $nodeType = null) { $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(); } $this->persistenceManager->persistAll(); }
/** * Returns a list of nodes contained in the given workspace which are not yet published * * @param Workspace $workspace * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeInterface> * @api */ public function getUnpublishedNodes(Workspace $workspace) { if ($workspace->getBaseWorkspace() === NULL) { return array(); } $nodeData = $this->nodeDataRepository->findByWorkspace($workspace); $unpublishedNodes = array(); foreach ($nodeData as $singleNodeData) { /** @var NodeData $singleNodeData */ // Skip the root entry from the workspace as it can't be published if ($singleNodeData->getPath() === '/') { continue; } $node = $this->nodeFactory->createFromNodeData($singleNodeData, $this->createContext($workspace, $singleNodeData->getDimensionValues())); if ($node !== NULL) { $unpublishedNodes[] = $node; } } $unpublishedNodes = $this->sortNodesForPublishing($unpublishedNodes); return $unpublishedNodes; }