Discard nodes

@param array $nodeContextPaths
@return void
966346
public function discardAction(array $nodeContextPaths)
    {
        try {
            foreach ($nodeContextPaths as $contextPath) {
                $node = $this->nodeService->getNodeFromContextPath($contextPath, null, null, true);
                if ($node->isRemoved() === true) {
                    // When discarding node removal we should re-create it
                    $updateNodeInfo = new UpdateNodeInfo();
                    $updateNodeInfo->setNode($node);
                    $updateNodeInfo->recursive();

                    $updateParentNodeInfo = new UpdateNodeInfo();
                    $updateParentNodeInfo->setNode($node->getParent());

                    $this->feedbackCollection->add($updateNodeInfo);
                    $this->feedbackCollection->add($updateParentNodeInfo);

                    // Reload document for content node changes
                    // (as we can't RenderContentOutOfBand from here, we don't know dom addresses)
                    if (!$this->nodeService->isDocument($node)) {
                        $reloadDocument = new ReloadDocument();
                        $this->feedbackCollection->add($reloadDocument);
                    }
                } elseif (!$this->nodeService->nodeExistsInWorkspace($node, $node->getWorkSpace()->getBaseWorkspace())) {
                    // If the node doesn't exist in the target workspace, tell the UI to remove it
                    $removeNode = new RemoveNode();
                    $removeNode->setNode($node);
                    $this->feedbackCollection->add($removeNode);
                }

                $this->publishingService->discardNode($node);
            }

            $success = new Success();
            $success->setMessage(sprintf('Discarded %d node(s).', count($nodeContextPaths)));

            $this->updateWorkspaceInfo($nodeContextPaths[0]);
            $this->feedbackCollection->add($success);

            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
87630
protected function _clearAcoPaths()
    {
        $this->loadModel('User.Acos');
        $nodes = $this->Acos
            ->find()
            ->where(['plugin' => $this->params['plugin']])
            ->order(['lft' => 'ASC'])
            ->all();

        foreach ($nodes as $node) {
            $this->Acos->removeFromTree($node);
            $this->Acos->delete($node);
        }

        AcoManager::buildAcos(null, true); // clear anything else
    }
452687
public function discardNode(NodeInterface $node)
    {
        $nodes = [$node];
        $nodeType = $node->getNodeType();

        if ($nodeType->isOfType('Neos.Neos:Document') || $nodeType->hasConfiguration('childNodes')) {
            $nodes = array_filter(
                array_merge($nodes, $this->collectAllContentChildNodes($node)),
                function ($possiblyPublishableNode) use ($node) {
                    return $possiblyPublishableNode->getWorkspace()->getName() === $node->getWorkspace()->getName();
                }
            );
        }

        $this->discardNodes($nodes);
    }
233005
protected function filterNodeByContext(NodeInterface $node, Context $context)
    {
        $this->securityContext->withoutAuthorizationChecks(function () use (&$node, $context) {
            if (!$context->isRemovedContentShown() && $node->isRemoved()) {
                $node = null;
                return;
            }
            if (!$context->isInvisibleContentShown() && !$node->isVisible()) {
                $node = null;
                return;
            }
            if (!$context->isInaccessibleContentShown() && !$node->isAccessible()) {
                $node = null;
            }
        });
        return $node;
    }
338988
protected function reindex(array $nodes, int &$reindexed, SymfonyStyle $io, array $context, int $batch, bool $dryRun = false, bool $skipErrors = false): void
    {
        if ($dryRun) {
            $io->note(sprintf('DRY RUN - Would reindex node batch %d here.', $batch));
        } else {
            try {
                $this->ncrSearch->indexNodes($nodes, $context);
            } catch (\Throwable $e) {
                $io->error($e->getMessage());
                $io->note(sprintf('Failed to index batch %d.', $batch));
                $io->newLine(2);

                if (!$skipErrors) {
                    throw $e;
                }
            }
        }

        $reindexed += count($nodes);
    }
230560
protected function removeNodeAndChildNodesInWorkspaceByPath($nodePath, $workspaceName)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder
            ->resetDQLParts()
            ->delete(NodeData::class, 'n')
            ->where('n.path LIKE :path')
            ->orWhere('n.path LIKE :subpath')
            ->andWhere('n.workspace = :workspace')
            ->setParameters(['path' => $nodePath, 'subpath' => $nodePath . '/%', 'workspace' => $workspaceName])
            ->getQuery()
            ->execute();
    }
214099
private static LocationPath discardSelfNode(LocationPath path){
        int noOfNulls = 0;
        Step steps[] = path.steps;

        for(int i=steps.length-1; i>=0; --i){
            Step step = steps[i];
            if(step.axis==Axis.SELF && step.constraint.id==Constraint.ID_NODE && !step.predicateSet.hasPosition){
                if(step.predicateSet.getPredicate()==null){
                    steps[i] = null;
                    noOfNulls++;
                }else{
                    if(i!=0){
                        steps[i] = null;
                        steps[i-1].setPredicate(step);
                        noOfNulls++;
                    }
                }
            }
        }
        return noOfNulls>0 ? removeNullSteps(path, noOfNulls) : path;
    }
249295
protected function updateWorkspaceInfo(string $documentNodeContextPath)
    {
        $updateWorkspaceInfo = new UpdateWorkspaceInfo();
        $documentNode = $this->nodeService->getNodeFromContextPath($documentNodeContextPath, null, null, true);
        $updateWorkspaceInfo->setWorkspace(
            $documentNode->getContext()->getWorkspace()
        );

        $this->feedbackCollection->add($updateWorkspaceInfo);
    }
22494
public function serializeNodeRecursively(NodeInterface $node, ControllerContext $controllerContext)
    {
        $result = [
            $node->getContextPath() => $this->nodeInfoHelper->renderNodeWithPropertiesAndChildrenInformation($node, $controllerContext)
        ];

        if ($this->isRecursive === true) {
            foreach ($node->getChildNodes() as $childNode) {
                $result = array_merge($result, $this->serializeNodeRecursively($childNode, $controllerContext));
            }
        }

        return $result;
    }
131017
@Override
	public synchronized void removeContext(Context context) {

        if( log.isDebugEnabled() )
            log.debug("Removing context[" + context.getPath() + "]");

        boolean isContextExists = isContextExists(context);
        if(!isContextExists)
        	return;
        
        // Remove this Context from the associated Host
        if( log.isDebugEnabled() )
            log.debug(" Removing this Context");
        context.getParent().removeChild(context);

    }
1004170
private function deleteNode( $node ) {
		$this->deleteChildren( $node );
		$parent = $node->parentNode;
		$oldnode = $parent->removeChild( $node );
	}
1222266
public function remove( $contexts )
	{
		if ( is_string( $contexts ) )
		{
			unset( $this->contexts[ $contexts ] );
		}
		else if ( $contexts instanceof ContextsFilter )
		{
			$contexts = array_keys( $contexts->getContexts() );
		}

		if ( is_array( $contexts ) )
		{
			foreach ( $contexts as $context )
			{
				unset( $this->contexts[ $context ] );
			}
		}

		return $this;
	}
706563
public function removeNodes($path)
    {
        $nodesToRemove = $this->getNodes($path);
        if ($nodesToRemove) {
            for ($index = 0; $index < $nodesToRemove->length; $index++) {
                $nodeToRemove = $nodesToRemove->item($index);
                $nodeToRemove->parentNode->removeChild($nodeToRemove);
            }
        }
    }
1208484
public static function removeOrphan(array &$nodes = []) {
        do {
            $found = false;
            foreach ($nodes as $k => $v) {
                if (false === ($v instanceof AlphabeticalTreeNodeInterface) || null === $v->getAlphabeticalTreeNodeParent() || true === in_array($v->getAlphabeticalTreeNodeParent(), $nodes)) {
                    continue;
                }
                unset($nodes[$k]);
                $found = true;
            }
        } while (true === $found);
    }
780284
public static function delete_data_for_all_users_in_context(context $context) {
        global $DB;
        list($sql, $params) = static::get_sql_where_from_contexts([$context]);
        if (empty($sql)) {
            return;
        }
        $DB->delete_records_select('log', $sql, $params);
    }
907564
private void removePath( Collection<InternalWorkingMemory> wms, RuleRemovalContext context, Map<Integer, BaseNode> stillInUse, Collection<ObjectSource> alphas, PathEndNode endNode ) {
        LeftTupleNode[] nodes = endNode.getPathNodes();
        for (int i = endNode.getPositionInPath(); i >= 0; i--) {
            BaseNode node = (BaseNode) nodes[i];

            boolean removed = false;
            if ( NodeTypeEnums.isLeftTupleNode( node ) ) {
                removed = removeLeftTupleNode(wms, context, stillInUse, node);
            }

            if ( removed ) {
                // reteoo requires to call remove on the OTN for tuples cleanup
                if (NodeTypeEnums.isBetaNode(node) && !((BetaNode) node).isRightInputIsRiaNode()) {
                    alphas.add(((BetaNode) node).getRightInput());
                } else if (node.getType() == NodeTypeEnums.LeftInputAdapterNode) {
                    alphas.add(((LeftInputAdapterNode) node).getObjectSource());
                }
            }

            if (NodeTypeEnums.isBetaNode(node) && ((BetaNode) node).isRightInputIsRiaNode()) {
                endNode = (PathEndNode) ((BetaNode) node).getRightInput();
                removePath(wms, context, stillInUse, alphas, endNode);
                return;
            }
        }
    }
950097
public function delete($path)
    {
        $node = $this->getNodeForPath($path);
        $node->delete();

        list($parent) = Uri\split($path);
        $this->markDirty($parent);
    }