@param string          $errorNodeId
@param string          $siteId
@param DocumentManager $dm

@return int
559736
protected function countErrorNode($errorNodeId, $siteId, DocumentManager $dm)
    {
        $qb = $dm->createQueryBuilder(Node::class);
        $qb->field('deleted')->equals(false)
            ->field('siteId')->equals($siteId)
            ->field('nodeId')->equals($errorNodeId)
            ->field('nodeType')->equals(NodeInterface::TYPE_ERROR);

        return $qb->getQuery()->count();
    }
664174
public function getNodeAttributeInt($xPath,$atrName,$failReturn = -1){
        $val = $this->getNodeAttribute($xPath, $atrName);
        if ($val === NULL || $val === false || !is_numeric($val)){
            return $failReturn;
        }
        return (int) $val;
    }
959557
public function getDataBySiteIdAndEnv($siteId, $siteEnv) 
	{
	    $select = $this->tableGateway->getSql()->select();
	    
	    $select->columns(array('*'));
	    
	    $select->where(array("sdom_site_id" => $siteId, 'sdom_env' => $siteEnv));
	    $resultSet = $this->tableGateway->selectWith($select);
	    
	    return $resultSet;
	}
548015
private function deduplicate($nodeId, $siteId, $alias)
    {
        $dupFound   = false;
        $current    = $alias;
        $increment  = 0;

        do {
            $dupFound = (bool)$this
                ->database
                ->query(
                    "SELECT 1 FROM {ucms_seo_route} WHERE route = :route AND site_id = :site",
                    [':route' => $current, ':site' => $siteId]
                )
                ->fetchField()
            ;

            if ($dupFound) {
                $current = $alias . '-' . ($increment++);
            }

        } while ($dupFound);

        return $current;
    }
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();
    }
993895
public function initializeNode($parentId, $language, $siteId, $order = 0)
    {
        /** @var NodeInterface $node */
        $node = new $this->nodeClass();
        $node->setSiteId($siteId);
        $node->setLanguage($language);
        $node->setMaxAge(NodeInterface::MAX_AGE);
        $node->setParentId($parentId);
        $node->setOrder($order);
        $node->setVersion($this->uniqueIdGenerator->generateUniqueId());
        $node->setCreatedBy($this->tokenStorage->getToken()->getUser()->getUsername());

        $parentNode = $this->nodeRepository->findInLastVersion($parentId, $language, $siteId);
        $status = $this->statusRepository->findOneByInitial();
        $node->setStatus($status);
        $nodeType = NodeInterface::TYPE_DEFAULT;
        if ($parentNode instanceof NodeInterface) {
            $nodeType = $parentNode->getNodeType();
            $node->setPath($parentNode->getPath());
        } else {
            $node->setNodeId(NodeInterface::ROOT_NODE_ID);
        }
        $node->setNodeType($nodeType);

        return $node;
    }
1161681
public function getPerimeterConfiguration($siteId)
    {
        $treeFolders = $this->folderRepository->findFolderTree($siteId);

        return $this->getTreePerimeterConfiguration($treeFolders);
    }
81748
public function getByNodeId($nodeId)
    {
        foreach ($this->siterootManager->findAll() as $siteroot) {
            $tree = $this->getBySiteRootId($siteroot->getId());

            if ($tree->has($nodeId)) {
                return $tree;
            }
        }

        throw new NodeNotFoundException("Tree for node ID $nodeId not found.");
    }
111764
private boolean verifyNodeRegistration(DatanodeRegistration nodeReg, String ipAddr)
    throws IOException {
    assert (hasWriteLock());
    return inHostsList(nodeReg, ipAddr);
  }
272701
public function deleteReferenceBulkFromSite($siteId, $nodeIdList)
    {
        if (!$nodeIdList) {
            return;
        }

        $this
            ->db
            ->delete('ucms_site_node')
            ->condition('nid', $nodeIdList)
            ->condition('site_id', $siteId)
            ->execute()
        ;

        $this
            ->entityManager
            ->getStorage('node')
            ->resetCache($nodeIdList)
        ;

        $this->eventDispatcher->dispatch(NodeEvents::ACCESS_CHANGE, new ResourceEvent('node', $nodeIdList));
        $this->eventDispatcher->dispatch(SiteEvents::EVENT_DETACH, new SiteAttachEvent($siteId, $nodeIdList));
    }
218871
@Override
    @RequirePOST
    public HttpResponse doDoDelete() throws IOException {
        checkPermission(DELETE);
        try {
            T node = getNode();
            if (node != null) { // No need to terminate nodes again
                node.terminate();
            }
            return new HttpRedirect("..");
        } catch (InterruptedException e) {
            return HttpResponses.error(500,e);
        }
    }
1139105
public function serialize(DAV\Server $server, \DOMElement $errorNode)
    {
        if ($this->header) {
            $prop = $errorNode->ownerDocument->createElement('s:header');
            $prop->nodeValue = $this->header;
            $errorNode->appendChild($prop);
        }
    }
1174554
@Override
    public String findNodeId(XPathExpression xpathExpression) throws PortalException {
        try {
            return xpathExpression.evaluate(this.layout);
        } catch (XPathExpressionException e) {
            throw new PortalException(
                    "Exception while executing XPathExpression: " + xpathExpression, e);
        }
    }
663785
public function isValid($siteId, $pageName, $pageType = PageTypes::NORMAL)
    {
        $isValidQueryBuilder = $this->_em->createQueryBuilder();
        $isValidQueryBuilder->select('page.pageId')
            ->from(\Rcm\Entity\Page::class, 'page')
            ->where('page.name = :pageName')
            ->andWhere('page.pageType = :pageType')
            ->andWhere('page.site = :siteId')
            ->setParameter('pageName', $pageName)
            ->setParameter('pageType', $pageType)
            ->setParameter('siteId', $siteId);

        $result = $isValidQueryBuilder->getQuery()->getScalarResult();

        if (!empty($result)) {
            return true;
        }

        return false;
    }
691492
private function computeAndStorePathAlias($nodeId, $siteId, $outdated = null)
    {
        $transaction = null;

        try {
            $transaction = $this->database->startTransaction();
            $computed = $this->computePathAlias($nodeId, $siteId);

            // In all cases, delete outdated item if exists and backup
            // it into the {ucms_seo_redirect} table with an expire. Not
            // for self, and for all people still using MySQL, RETURNING
            // clause would have been great here.
            $this
                ->database
                ->query(
                    "DELETE FROM {ucms_seo_route} WHERE node_id = :node AND site_id = :site",
                    [':node' => $nodeId, ':site' => $siteId]
                )
            ;

            // @todo ucms_seo_redirect does not handle duplicates at all
            //   and will let you insert pretty much everything, we'll see
            //   later for this; but this is bad, we cannot deduplicate what
            //   are old sites urls and expired urls from us
            if ($outdated) {
                $this
                    ->database
                    ->insert('ucms_seo_redirect')
                    ->fields([
                        'nid'     => $nodeId,
                        'site_id' => $siteId,
                        'path'    => '/' . $outdated,
                        'expires' => (new \DateTime(self::DEFAULT_EXPIRE))->format('Y-m-d H:i:s'),
                    ])
                    ->execute()
                ;
            }

            if ($computed) {
                $computed = $this->deduplicate($nodeId, $siteId, $computed);

                $this
                    ->database
                    ->insert('ucms_seo_route')
                    ->fields([
                        'node_id'       => $nodeId,
                        'site_id'       => $siteId,
                        'route'         => $computed,
                        'is_protected'  => 0,
                        'is_outdated'   => 0,
                    ])
                    ->execute()
                ;
            }

            // Explicit commit
            unset($transaction);

            return $computed;

        } catch (\PDOException $e) {
            try {
                if ($transaction) {
                    $transaction->rollback();
                }
            } catch (\Exception $e2) {
                // You are fucked.
                watchdog_exception(__FUNCTION__, $e2);
            }

            throw $e;
        }
    }
1293375
private function findLinkNodes($siteRootId, $language, array $elementtypeIds)
    {
        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');

        $iconResolver = $this->get('phlexible_element.icon_resolver');
        $db = $this->get('doctrine.dbal.default_connection');

        $qb = $db->createQueryBuilder();

        $qbElementtypeIds = array_map(function($id) use ($qb) {
            return $qb->expr()->literal($id);
        }, $elementtypeIds);

        $qb
            ->select('t.id')
            ->from('tree', 't')
            ->join('t', 'element', 'e', 't.type_id = e.eid')
            ->where($qb->expr()->eq('t.siteroot_id', $qb->expr()->literal($siteRootId)))
            ->andWhere($qb->expr()->in('e.elementtype_id', $qbElementtypeIds))
            ->orderBy('t.sort', 'ASC');

        $treeIds = array_column($db->fetchAll($qb->getSQL()), 'id');

        $data = [];

        $rootTreeId = null;

        foreach ($treeIds as $treeId) {
            $tree = $treeManager->getByNodeId($treeId);
            $node = $tree->get($treeId);

            $element = $elementService->findelement($node->getTypeId());
            $elementVersion = $elementService->findLatestElementVersion($element);

            if (!isset($data[$treeId])) {
                $data[$node->getId()] = [
                    'id' => $node->getId(),
                    'eid' => $node->getTypeId(),
                    'text' => $elementVersion->getBackendTitle($language, $element->getMasterLanguage()).' ['.$node->getId().']',
                    'icon' => $iconResolver->resolveElement($element),
                    'children' => [],
                    'leaf' => true,
                    'expanded' => false,
                    'disabled' => !in_array($element->getElementtypeId(), $elementtypeIds),
                ];
            }

            do {
                $parentNode = $tree->getParent($node);

                if (!$parentNode) {
                    $rootTreeId = $node->getId();
                    break;
                }

                if (!isset($data[$parentNode->getId()])) {
                    $element = $elementService->findElement($parentNode->getTypeId());
                    $elementVersion = $elementService->findLatestElementVersion($element);

                    $data[$parentNode->getId()] = [
                        'id' => $parentNode->getId(),
                        'eid' => $parentNode->getTypeId(),
                        'text' => $elementVersion->getBackendTitle($language, $element->getMasterLanguage()).' ['.$parentNode->getId().']',
                        'icon' => $iconResolver->resolveTreeNode($parentNode, $language),
                        'children' => [],
                        'leaf' => false,
                        'expanded' => false,
                        'disabled' => !in_array($element->getElementtypeId(), $elementtypeIds),
                    ];
                } else {
                    $data[$parentNode->getId()]['leaf'] = false;
                }

                $data[$parentNode->getId()]['children'][$node->getId()] = &$data[$node->getId()];

                $node = $parentNode;
            } while ($parentNode);
        }

        if (!count($data)) {
            return [];
        }

        $data = $this->stripLinkNodeKeys($data[$rootTreeId], $db);

        return $data['children'];
    }
543256
static public function moveNode( $nodeID, $objectID, $newParentNodeID )
    {
       if( !eZContentObjectTreeNodeOperations::move( $nodeID, $newParentNodeID ) )
       {
           eZDebug::writeError( "Failed to move node $nodeID as child of parent node $newParentNodeID",
                                __METHOD__ );

           return array( 'status' => false );
       }

       eZContentObject::fixReverseRelations( $objectID, 'move' );

        if ( !eZSearch::getEngine() instanceof eZSearchEngine )
        {
            eZContentOperationCollection::registerSearchObject( $objectID );
        }

       return array( 'status' => true );
    }