Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByWorkspace PHP Method

findByWorkspace() public method

Shadow nodes are excluded, because they will be published when publishing the moved node.
public findByWorkspace ( Workspace $workspace ) : array
$workspace Neos\ContentRepository\Domain\Model\Workspace
return array
    public function findByWorkspace(Workspace $workspace)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();
        $queryBuilder->select('n')->from(NodeData::class, 'n')->where('n.workspace = :workspace')->andWhere('n.movedTo IS NULL OR n.removed = :removed')->orderBy('n.path', 'ASC')->setParameter('workspace', $workspace)->setParameter('removed', false, \PDO::PARAM_BOOL);
        return $queryBuilder->getQuery()->getResult();
    }

Usage Example

コード例 #1
0
 /**
  * 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 \Neos\ContentRepository\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();
 }
All Usage Examples Of Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByWorkspace