@param DeleteNode $command
@param Pbjx       $pbjx

@return NodeDeleted
547125
protected function createNodeDeleted(DeleteNode $command, Pbjx $pbjx): NodeDeleted
    {
        /** @var NodeDeleted $event */
        $event = $this->createEventFromCommand($command, 'deleted');
        return $event;
    }
617416
public function deleteNode( $id = null )
	{
		$node = $this->getNode( $id, MW_Tree_Manager_Abstract::LEVEL_ONE );

		$conn = $this->_dbm->acquire( $this->_dbname );

		try
		{
			$stmt = $conn->create( $this->_config['delete'] );
			$stmt->bind( 1, $node->left, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 2, $node->right, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->execute()->finish();

			$diff = $node->right - $node->left + 1;

			$stmt = $conn->create( $this->_config['move-left'] );
			$stmt->bind( 1, -$diff, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 2, 0, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 3, $node->right + 1, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 4, 0x7FFFFFFF, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->execute()->finish();

			$stmt = $conn->create( $this->_config['move-right'] );
			$stmt->bind( 1, -$diff, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 2, $node->right + 1, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->bind( 3, 0x7FFFFFFF, MW_DB_Statement_Abstract::PARAM_INT );
			$stmt->execute()->finish();

			$this->_dbm->release( $conn, $this->_dbname );
		}
		catch( Exception $e )
		{
			$this->_dbm->release( $conn, $this->_dbname );
			throw $e;
		}
	}
334896
private void rightDeleteWithSuccessor(
                                         GBSNode           p,
                                         GBSNode           l,
                                         Object            deleteKey,
                                         DeleteNode        point)
    {
        java.util.Comparator comp = p.deleteComparator();
        int xcc = comp.compare(deleteKey, l.leftMostKey());

        if (xcc == 0)                /* Target key IS low key of successor    */
        {
            /* Migrate up high key of current (delete key)
                into low key of successor (target key)                  */
            point.setDelete(p, p.rightMostIndex());
            point.setTarget(l, 0, DeleteNode.OVERLAY_LEFT);
        }
        else if (xcc < 0)            /* Less than left most key of successor  */
        {
            /* Target is in right of current         */
            int ix = p.findDeleteInRight(deleteKey);
            if (ix >= 0)
                point.setDelete(p, ix);
        }
        else                        /* Greater than left most of successor   */
        {
            /* Target is in left of successor        */
            int ix = l.findDeleteInLeft(deleteKey);
            if (ix >= 0)
            {
                /* Migrate up high key of current (delete key) into
                    low key of successor (hole left after keys moved)           */
                point.setDelete(p, p.rightMostIndex());
                point.setTarget(l, ix, DeleteNode.ADD_LEFT);
            }
        }
    }
332066
protected function ensureSlugIsAvailable(PbjxEvent $pbjxEvent, NodeRef $nodeRef, string $slug): void
    {
        $pbjx = $pbjxEvent::getPbjx();
        $command = $pbjxEvent->getMessage();

        try {
            $request = $this->createGetNodeRequest($command, $nodeRef, $pbjx)
                ->set('consistent_read', true)
                ->set('qname', $nodeRef->getQName()->toString())
                ->set('slug', $slug);

            $response = $pbjx->copyContext($command, $request)->request($request);
        } catch (RequestHandlingFailed $e) {
            if (Code::NOT_FOUND === $e->getResponse()->get('error_code')) {
                // this is what we want
                return;
            }

            throw $e;
        } catch (\Throwable $t) {
            throw $t;
        }

        /** @var Node $node */
        $node = $response->get('node');

        if ($nodeRef->getId() === (string)$node->get('_id')) {
            // this is the same node.
            return;
        }

        throw new NodeAlreadyExists(
            sprintf(
                'The [%s] with slug [%s] already exists so [%s] cannot continue.',
                $node::schema()->getCurie()->getMessage(),
                $slug,
                $command->generateMessageRef()
            )
        );
    }
1231121
protected function _commandDeleteLocation($command)
    {
        $location = $this->getController()->getItem();
        $locatable = $command->locatable;

        $command->setAttribute('data-action', 'deleteLocation')
        ->setAttribute('data-location', $location->id)
        ->href($locatable->getURL());

        $command->label = translate('LIB-AN-ACTION-DELETE');
    }
342367
protected function createExpireNode(Node $node, Event $event, Pbjx $pbjx): ExpireNode
    {
        $curie = $node::schema()->getCurie();
        $commandCurie = "{$curie->getVendor()}:{$curie->getPackage()}:command:expire-{$curie->getMessage()}";

        /** @var ExpireNode $class */
        $class = MessageResolver::resolveCurie(SchemaCurie::fromString($commandCurie));
        return $class::create();
    }
1097278
private function handleDelete(DeleteCommand $command)
    {
        $this->state = ORMInterface::STATE_DELETED;
        $this->dispatch('deleted', new RecordEvent($this, $command));
    }
935103
private void rightDeleteNoSuccessor(
                                       GBSNode           p,
                                       Object            deleteKey,
                                       DeleteNode        point)
    {
        int idx = p.findDeleteInRight(deleteKey);
        if (idx >= 0)
            point.setDelete(p, idx);
    }
38352
public static function deleteElementsByXpath($node, $xpath_query, $namespaces = array())
    {
        if(is_a($node, 'DOMDocument'))
        {
            $xpath = new DOMXPath($node);
        }
        elseif(is_a($node, 'DOMNode'))
        {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        else
        {
            return false;
        }

        foreach($namespaces as $prefix => $namespaceURI)
        {
            $xpath->registerNamespace($prefix, $namespaceURI);
        }

        $node_list = $xpath->query($xpath_query, $node);

        if($node_list->length > 0)
        {
            foreach($node_list as $node_to_delete)
            {
                if(isset($node_to_delete->parentNode))
                {
                    $node_to_delete->parentNode->removeChild($node_to_delete);
                }
            }
        }
    }
137174
static function processRemoveNodePlacement( &$node )
    {
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $nodeChildren =& $node[1];
            for ( $i = 0; $i < count( $nodeChildren ); ++$i )
            {
                $nodeChild =& $nodeChildren[$i];
                eZTemplateCompiler::processRemoveNodePlacement( $nodeChild );
            }
        }
        else if ( $nodeType == eZTemplate::NODE_TEXT )
        {
            $node[3] = false;
        }
        else if ( $nodeType == eZTemplate::NODE_VARIABLE )
        {
            $node[3] = false;
        }
        else if ( $nodeType == eZTemplate::NODE_FUNCTION )
        {
            $node[4] = false;
            $nodeChildren =& $node[1];
            if ( $nodeChildren )
            {
                for ( $i = 0; $i < count( $nodeChildren ); ++$i )
                {
                    $nodeChild =& $nodeChildren[$i];
                    eZTemplateCompiler::processRemoveNodePlacement( $nodeChild );
                }
            }
        }
        else if ( $nodeType == eZTemplate::NODE_OPERATOR )
        {
        }
    }
666911
public static void deleteNode(DbConn cnx, int id)
    {
        int countRunning = cnx.runSelectSingle("ji_select_count_by_node", Integer.class, id);
        if (countRunning > 0)
        {
            cnx.setRollbackOnly();
            throw new JqmAdminApiUserException(
                    "cannot delete a node with running instances. Disable it, wait for the end of all running instances, then retry.");
        }

        try
        {
            Node n = Node.select_single(cnx, "node_select_by_id", id);
            Calendar limit = Calendar.getInstance();
            limit.add(Calendar.MINUTE, -10);
            if (n.getLastSeenAlive() != null && n.getLastSeenAlive().after(limit))
            {
                cnx.setRollbackOnly();
                throw new JqmAdminApiUserException(
                        "Can only remove a node either properly shut down or that has crashed more than 10 minutes ago.");
            }
        }
        catch (NoResultException e)
        {
            throw new JqmAdminApiUserException("no item with ID " + id);
        }

        cnx.runUpdate("dp_delete_for_node", id);
        QueryResult qr = cnx.runUpdate("node_delete_by_id", id);
        if (qr.nbUpdated != 1)
        {
            cnx.setRollbackOnly();
            throw new JqmAdminApiUserException("no item with ID " + id);
        }
    }
679877
public function delete(ResourceNode $resourceNode, $force = false, $softDelete = false)
    {
        $this->log('Removing '.$resourceNode->getName().'['.$resourceNode->getResourceType()->getName().':id:'.$resourceNode->getId().']');

        if (null === $resourceNode->getParent() && !$force) {
            throw new \LogicException('Root directory cannot be removed');
        }

        $workspace = $resourceNode->getWorkspace();
        $nodes = $this->getDescendants($resourceNode);
        $nodes[] = $resourceNode;
        $this->om->startFlushSuite();
        $this->log('Looping through '.count($nodes).' children...');

        foreach ($nodes as $node) {
            $eventSoftDelete = false;
            $this->log('Removing '.$node->getName().'['.$node->getResourceType()->getName().':id:'.$node->getId().']');
            $resource = $this->getResourceFromNode($node);
            /*
             * resChild can be null if a shortcut was removed
             *
             * activities must be ignored atm
             */

            $ignore = ['activity'];

            if (null !== $resource) {
                if (!$softDelete && !in_array($node->getResourceType()->getName(), $ignore)) {
                    $event = $this->dispatcher->dispatch(
                        "delete_{$node->getResourceType()->getName()}",
                        'Resource\DeleteResource',
                        [$resource, $softDelete]
                    );
                    $eventSoftDelete = $event->isSoftDelete();

                    foreach ($event->getFiles() as $file) {
                        if ($softDelete) {
                            $parts = explode(
                                $this->filesDirectory.DIRECTORY_SEPARATOR,
                                $file
                            );

                            if (2 === count($parts)) {
                                $deleteDir = $this->filesDirectory.
                                    DIRECTORY_SEPARATOR.
                                    'DELETED_FILES';
                                $dest = $deleteDir.
                                    DIRECTORY_SEPARATOR.
                                    $parts[1];
                                $additionalDirs = explode(DIRECTORY_SEPARATOR, $parts[1]);

                                for ($i = 0; $i < count($additionalDirs) - 1; ++$i) {
                                    $deleteDir .= DIRECTORY_SEPARATOR.$additionalDirs[$i];
                                }

                                if (!is_dir($deleteDir)) {
                                    mkdir($deleteDir, 0777, true);
                                }
                                rename($file, $dest);
                            }
                        } else {
                            unlink($file);
                        }

                        //It won't work if a resource has no workspace for a reason or an other. This could be a source of bug.
                        $dir = $this->filesDirectory.
                            DIRECTORY_SEPARATOR.
                            'WORKSPACE_'.
                            $workspace->getId();

                        if (is_dir($dir) && $this->isDirectoryEmpty($dir)) {
                            rmdir($dir);
                        }
                    }
                } elseif ($softDelete && !in_array($node->getResourceType()->getName(), $ignore)) {
                    $this->dispatcher->dispatch(
                        "resource.{$node->getResourceType()->getName()}.soft_delete",
                        'Resource\SoftDeleteResource',
                        [$resource]
                    );
                }

                if ($softDelete || $eventSoftDelete) {
                    $node->setActive(false);
                    // Rename node to allow future nodes have the same name
                    $node->setName($node->getName().uniqid('_'));
                    $this->om->persist($node);
                } else {
                    //what is it ?
                    $this->dispatcher->dispatch(
                        'claroline_resources_delete',
                        'GenericData',
                        [[$node]]
                    );

                    /*
                     * If the child isn't removed here aswell, doctrine will fail to remove $resChild
                     * because it still has $resChild in its UnitOfWork or something (I have no idea
                     * how doctrine works tbh). So if you remove this line the suppression will
                     * not work for directory containing children.
                     */
                    $this->om->remove($resource);
                    $this->om->remove($node);
                }

                $this->dispatcher->dispatch(
                    'log',
                    'Log\LogResourceDelete',
                    [$node]
                );
            } else {
                if ($softDelete || $eventSoftDelete) {
                    $node->setActive(false);
                    // Rename node to allow future nodes have the same name
                    $node->setName($node->getName().uniqid('_'));
                    $this->om->persist($node);
                } else {
                    //what is it ?
                    $this->dispatcher->dispatch(
                        'claroline_resources_delete',
                        'GenericData',
                        [[$node]]
                    );

                    $this->om->remove($node);
                }

                $this->dispatcher->dispatch(
                    'log',
                    'Log\LogResourceDelete',
                    [$node]
                );
            }
        }

        $this->om->endFlushSuite();
    }
1246411
public function validateCreateNode(PbjxEvent $pbjxEvent): void
    {
        $command = $pbjxEvent->getMessage();
        if (!$command->has('node')) {
            return;
        }

        /** @var Node $node */
        $node = $command->get('node');
        if ($this->shouldIgnoreNode($node)) {
            return;
        }

        /** @var CacheItemInterface[] $cacheItems */
        $cacheItems = $this->cache->getItems($this->getIdempotencyKeys($node));

        foreach ($cacheItems as $cacheItem) {
            if (!$cacheItem->isHit()) {
                continue;
            }

            throw new NodeAlreadyExists(
                sprintf(
                    'A similar [%s] was just created moments ago so [%s] cannot continue.',
                    $node::schema()->getCurie()->getMessage(),
                    $command->generateMessageRef()
                )
            );
        }
    }
1022003
public function deleteNode($nodeId)
    {
        $node = $this->getNode($nodeId);

        $operation = new Operations\Delete($node, $this->config, $this);
        $operation->run();
    }
91741
public function deleteAction($nodeId)
    {
        $siteId = $this->get('open_orchestra_backoffice.context_backoffice_manager')->getSiteId();
        $nodeRepository = $this->get('open_orchestra_model.repository.node');

        $node = $nodeRepository->findOneByNodeAndSite($nodeId, $siteId);
        $this->denyAccessUnlessGranted(ContributionActionInterface::DELETE, $node);

        if (!$this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $node)) {
            throw new NodeNotDeletableException();
        }

        $nodeRepository->softDeleteNode($nodeId, $siteId);
        $this->dispatchEvent(NodeEvents::NODE_DELETE, new NodeDeleteEvent($nodeId, $siteId));

        return array();
    }
885159
protected function callBrowser($command)
    {
        $setNodePathCommand     = "NODE_PATH=`{$this->npmBinary} root -g`";
        $binPath                = dirname(dirname(__DIR__)).'/bin/browser.js';
        $fullCommand            = "sudo ".$setIncludePathCommand.' '.$setNodePathCommand.' '.$this->nodeBinary.' '.escapeshellarg($binPath).' '.escapeshellarg(json_encode($command));
        $process                = (new Process($fullCommand))->setTimeout($this->timeout);
        $process->run();
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }
        $response = json_decode($process->getOutput());
        if(!$response && !isset($response->response))
            return false;
        if(isset($response->response->error))
            throw new \Exception($response->response->error);
        return $response;
    }
447147
protected function handle(GetNodeBatchRequest $request, Pbjx $pbjx): GetNodeBatchResponse
    {
        $response = $this->createGetNodeBatchResponse($request, $pbjx);
        $nodeRefs = $request->get('node_refs');

        if (empty($nodeRefs)) {
            return $response;
        }

        $context = $this->createNcrContext($request);
        $nodes = $this->ncr->getNodes($nodeRefs, $request->get('consistent_read'), $context);
        foreach ($nodes as $nodeRef => $node) {
            $this->assertIsNodeSupported($node);
            $response->addToMap('nodes', $nodeRef, $node);
        }

        $missing = array_keys(array_diff_key(array_flip(array_map('strval', $nodeRefs)), $nodes));
        $missing = array_map(function ($str) {
            return NodeRef::fromString($str);
        }, $missing);
        $response->addToSet('missing_node_refs', $missing);

        return $response;
    }