Neos.ContentRepository/Classes/Command/NodeCommandControllerPlugin.php
protected function removeDisallowedChildNodes($workspaceName)
    {
        $this->dispatch(self::EVENT_NOTICE, 'Checking for disallowed child nodes ...');

        /** @var \Neos\ContentRepository\Domain\Model\Workspace $workspace */
        $workspace = $this->workspaceRepository->findByIdentifier($workspaceName);

        $nodes = [];
        $nodeExceptionCount = 0;
        $removeDisallowedChildNodes = function (NodeInterface $node) use (&$removeDisallowedChildNodes, &$nodes, &$nodeExceptionCount) {
            try {
                foreach ($node->getChildNodes() as $childNode) {
                    /** @var $childNode NodeInterface */
                    if (!$childNode->isAutoCreated() && !$node->isNodeTypeAllowedAsChildNode($childNode->getNodeType())) {
                        $nodes[] = $childNode;
                        $parent = $node->isAutoCreated() ? $node->getParent() : $node;
                        $this->dispatch(self::EVENT_NOTICE, sprintf('Found disallowed node named "<i>%s</i>" (<i>%s</i>) in "<i>%s</i>", child of node "<i>%s</i>" (<i>%s</i>)', $childNode->getName(), $childNode->getNodeType()->getName(), $childNode->getPath(), $parent->getName(), $parent->getNodeType()->getName()));
                    } else {
                        $removeDisallowedChildNodes($childNode);
                    }
                }
            } catch (\Exception $exception) {
                $this->dispatch(self::EVENT_WARNING, sprintf('Error while traversing child nodes of node <i>%s</i>: %s (%s)', $node->getIdentifier(), $exception->getMessage(), $exception->getCode()));
                $nodeExceptionCount++;
            }
        };

        // TODO: Performance could be improved by a search for all child node data instead of looping over all contexts
        foreach ($this->contentDimensionCombinator->getAllAllowedCombinations() as $dimensionConfiguration) {
            $context = $this->createContext($workspace->getName(), $dimensionConfiguration);
            $removeDisallowedChildNodes($context->getRootNode());
            $context->getFirstLevelNodeCache()->flush();
            $this->nodeFactory->reset();
        }

        $disallowedChildNodesCount = count($nodes);
        if ($disallowedChildNodesCount > 0) {
            $taskDescription = sprintf('Remove <i>%d</i> disallowed node%s.', $disallowedChildNodesCount, $disallowedChildNodesCount > 1 ? 's' : '');
            $taskClosure = function () use ($nodes, $workspaceName) {
                foreach ($nodes as $node) {
                    $this->removeNodeAndChildNodesInWorkspaceByPath($node->getPath(), $workspaceName);
                }
            };
            $taskRequiresConfirmation = true;
            $this->dispatch(self::EVENT_TASK, $taskDescription, $taskClosure, $taskRequiresConfirmation);

            if ($nodeExceptionCount > 0) {
                $this->dispatch(self::EVENT_NOTICE, '<i>%d</i> error%s occurred during child node traversing.', $nodeExceptionCount, $nodeExceptionCount > 1 ? 's' : '');
            }
        }
    }
protected function removeDisallowedChildNodes($workspaceName)
    {
        $this->dispatch(self::EVENT_NOTICE, 'Checking for disallowed child nodes ...');

        /** @var \Neos\ContentRepository\Domain\Model\Workspace $workspace */
        $workspace = $this->workspaceRepository->findByIdentifier($workspaceName);

        $nodes = [];
        $nodeExceptionCount = 0;
        $removeDisallowedChildNodes = function (NodeInterface $node) use (&$removeDisallowedChildNodes, &$nodes, &$nodeExceptionCount) {
            try {
                foreach ($node->getChildNodes() as $childNode) {
                    /** @var $childNode NodeInterface */
                    if (!$childNode->isAutoCreated() && !$node->isNodeTypeAllowedAsChildNode($childNode->getNodeType())) {
                        $nodes[] = $childNode;
                        $parent = $node->isAutoCreated() ? $node->getParent() : $node;
                        $this->dispatch(self::EVENT_NOTICE, sprintf('Found disallowed node named "<i>%s</i>" (<i>%s</i>) in "<i>%s</i>", child of node "<i>%s</i>" (<i>%s</i>)', $childNode->getName(), $childNode->getNodeType()->getName(), $childNode->getPath(), $parent->getName(), $parent->getNodeType()->getName()));
                    } else {
                        $removeDisallowedChildNodes($childNode);
                    }
                }
            } catch (\Exception $exception) {
                $this->dispatch(self::EVENT_WARNING, sprintf('Error while traversing child nodes of node <i>%s</i>: %s (%s)', $node->getIdentifier(), $exception->getMessage(), $exception->getCode()));
                $nodeExceptionCount++;
            }
        };

        // TODO: Performance could be improved by a search for all child node data instead of looping over all contexts
        foreach ($this->contentDimensionCombinator->getAllAllowedCombinations() as $dimensionConfiguration) {
            $context = $this->createContext($workspace->getName(), $dimensionConfiguration);
            $removeDisallowedChildNodes($context->getRootNode());
            $context->getFirstLevelNodeCache()->flush();
            $this->nodeFactory->reset();
        }

        $disallowedChildNodesCount = count($nodes);
        if ($disallowedChildNodesCount > 0) {
            $taskDescription = sprintf('Remove <i>%d</i> disallowed node%s.', $disallowedChildNodesCount, $disallowedChildNodesCount > 1 ? 's' : '');
            $taskClosure = function () use ($nodes, $workspaceName) {
                foreach ($nodes as $node) {
                    $this->removeNodeAndChildNodesInWorkspaceByPath($node->getPath(), $workspaceName);
                }
            };
            $taskRequiresConfirmation = true;
            $this->dispatch(self::EVENT_TASK, $taskDescription, $taskClosure, $taskRequiresConfirmation);

            if ($nodeExceptionCount > 0) {
                $this->dispatch(self::EVENT_NOTICE, '<i>%d</i> error%s occurred during child node traversing.', $nodeExceptionCount, $nodeExceptionCount > 1 ? 's' : '');
            }
        }
    }
protected function removeDisallowedChildNodes ( $ workspaceName ) { $ this -> dispatch ( self :: EVENT_NOTICE , 'Checking for disallowed child nodes ...' ) ; /** @var \Neos\ContentRepository\Domain\Model\Workspace $workspace */ $ workspace = $ this -> workspaceRepository -> findByIdentifier ( $ workspaceName ) ; $ nodes = [ ] ; $ nodeExceptionCount = 0 ; $ removeDisallowedChildNodes = function ( NodeInterface $ node ) use ( & $ removeDisallowedChildNodes , & $ nodes , & $ nodeExceptionCount ) { try { foreach ( $ node -> getChildNodes ( ) as $ childNode ) { /** @var $childNode NodeInterface */ if ( ! $ childNode -> isAutoCreated ( ) && ! $ node -> isNodeTypeAllowedAsChildNode ( $ childNode -> getNodeType ( ) ) ) { $ nodes [ ] = $ childNode ; $ parent = $ node -> isAutoCreated ( ) ? $ node -> getParent ( ) : $ node ; $ this -> dispatch ( self :: EVENT_NOTICE , sprintf ( 'Found disallowed node named "<i>%s</i>" (<i>%s</i>) in "<i>%s</i>", child of node "<i>%s</i>" (<i>%s</i>)' , $ childNode -> getName ( ) , $ childNode -> getNodeType ( ) -> getName ( ) , $ childNode -> getPath ( ) , $ parent -> getName ( ) , $ parent -> getNodeType ( ) -> getName ( ) ) ) ; } else { $ removeDisallowedChildNodes ( $ childNode ) ; } } } catch ( \ Exception $ exception ) { $ this -> dispatch ( self :: EVENT_WARNING , sprintf ( 'Error while traversing child nodes of node <i>%s</i>: %s (%s)' , $ node -> getIdentifier ( ) , $ exception -> getMessage ( ) , $ exception -> getCode ( ) ) ) ; $ nodeExceptionCount ++ ; } } ; // TODO: Performance could be improved by a search for all child node data instead of looping over all contexts foreach ( $ this -> contentDimensionCombinator -> getAllAllowedCombinations ( ) as $ dimensionConfiguration ) { $ context = $ this -> createContext ( $ workspace -> getName ( ) , $ dimensionConfiguration ) ; $ removeDisallowedChildNodes ( $ context -> getRootNode ( ) ) ; $ context -> getFirstLevelNodeCache ( ) -> flush ( ) ; $ this -> nodeFactory -> reset ( ) ; } $ disallowedChildNodesCount = count ( $ nodes ) ; if ( $ disallowedChildNodesCount > 0 ) { $ taskDescription = sprintf ( 'Remove <i>%d</i> disallowed node%s.' , $ disallowedChildNodesCount , $ disallowedChildNodesCount > 1 ? 's' : '' ) ; $ taskClosure = function ( ) use ( $ nodes , $ workspaceName ) { foreach ( $ nodes as $ node ) { $ this -> removeNodeAndChildNodesInWorkspaceByPath ( $ node -> getPath ( ) , $ workspaceName ) ; } } ; $ taskRequiresConfirmation = true ; $ this -> dispatch ( self :: EVENT_TASK , $ taskDescription , $ taskClosure , $ taskRequiresConfirmation ) ; if ( $ nodeExceptionCount > 0 ) { $ this -> dispatch ( self :: EVENT_NOTICE , '<i>%d</i> error%s occurred during child node traversing.' , $ nodeExceptionCount , $ nodeExceptionCount > 1 ? 's' : '' ) ; } } }
Performs checks for disallowed child nodes according to the node's auto-create configuration and constraints
and removes them if found.

@param string $workspaceName
@return void
Performs checks for disallowed child nodes according to the node s auto - create configuration and constraints and removes them if found .