Neos.ContentRepository/Classes/Domain/Service/PublishingService.php
protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = [])
    {
        if ($node->getWorkspace()->getBaseWorkspace() === null) {
            throw new WorkspaceException('Nodes 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);
    }
protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = [])
    {
        if ($node->getWorkspace()->getBaseWorkspace() === null) {
            throw new WorkspaceException('Nodes 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);
    }
protected function doDiscardNode ( NodeInterface $ node , array & $ alreadyDiscardedNodeIdentifiers = [ ] ) { if ( $ node -> getWorkspace ( ) -> getBaseWorkspace ( ) === null ) { throw new WorkspaceException ( 'Nodes 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 ) ; }
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 \Neos\ContentRepository\Exception\WorkspaceException
Method which does the actual work of discarding includes a protection against endless recursions and multiple discarding of the same node .