Neos\ContentRepository\Command\NodeCommandControllerPlugin::removeOrphanNodes PHP Метод

removeOrphanNodes() защищенный Метод

Performs checks for orphan nodes removes them if found.
protected removeOrphanNodes ( string $workspaceName, boolean $dryRun ) : void
$workspaceName string
$dryRun boolean Simulate?
Результат void
    protected function removeOrphanNodes($workspaceName, $dryRun)
    {
        $this->output->outputLine('Checking for orphan nodes ...');
        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();
        $workspaceList = array();
        /** @var \Neos\ContentRepository\Domain\Model\Workspace $workspace */
        $workspace = $this->workspaceRepository->findByIdentifier($workspaceName);
        while ($workspace !== null) {
            $workspaceList[] = $workspace->getName();
            $workspace = $workspace->getBaseWorkspace();
        }
        $nodes = $queryBuilder->select('n')->from(NodeData::class, 'n')->leftJoin(NodeData::class, 'n2', \Doctrine\ORM\Query\Expr\Join::WITH, 'n.parentPathHash = n2.pathHash AND n2.workspace IN (:workspaceList)')->where('n2.path IS NULL')->andWhere($queryBuilder->expr()->not('n.path = :slash'))->andWhere('n.workspace = :workspace')->setParameters(array('workspaceList' => $workspaceList, 'slash' => '/', 'workspace' => $workspaceName))->getQuery()->getArrayResult();
        $nodesToBeRemoved = count($nodes);
        if ($nodesToBeRemoved === 0) {
            return;
        }
        foreach ($nodes as $node) {
            $name = $node['path'] === '/' ? '' : substr($node['path'], strrpos($node['path'], '/') + 1);
            $this->output->outputLine('Found orphan node named "%s" (%s) in "%s"', array($name, $node['nodeType'], $node['path']));
        }
        $this->output->outputLine();
        if (!$dryRun) {
            $self = $this;
            $this->askBeforeExecutingTask('Do you want to remove all orphan nodes?', function () use($self, $nodes, $workspaceName, $nodesToBeRemoved) {
                foreach ($nodes as $node) {
                    $self->removeNodeAndChildNodesInWorkspaceByPath($node['path'], $workspaceName);
                }
                $self->output->outputLine('Removed %s orphan node%s.', array($nodesToBeRemoved, count($nodes) > 1 ? 's' : ''));
            });
        } else {
            $this->output->outputLine('Found %s orphan node%s to be removed.', array($nodesToBeRemoved, count($nodes) > 1 ? 's' : ''));
        }
        $this->output->outputLine();
    }