Neos.ContentRepository/Classes/Domain/Repository/NodeDataRepository.php
protected function openIndexSpace($parentPath, $referenceIndex)
    {
        $this->systemLogger->info(sprintf('Opening sortindex space after index %s at path %s.', $referenceIndex, $parentPath), LogEnvironment::fromMethodName(__METHOD__));

        /** @var Query $query */
        $query = $this->entityManager->createQuery('SELECT n.Persistence_Object_Identifier identifier, n.index, n.path FROM Neos\ContentRepository\Domain\Model\NodeData n WHERE n.parentPathHash = :parentPathHash ORDER BY n.index ASC');
        $query->setParameter('parentPathHash', md5($parentPath));

        $nodesOnLevel = [];
        /** @var $node NodeData */
        foreach ($query->getArrayResult() as $node) {
            $nodesOnLevel[] = [
                'identifier' => $node['identifier'],
                'path' => $node['path'],
                'index' => $node['index']
            ];
        }

        /** @var $node NodeData */
        foreach ($this->addedNodes as $node) {
            if ($node->getParentPath() === $parentPath) {
                $nodesOnLevel[] = [
                    'addedNode' => $node,
                    'path' => $node->getPath(),
                    'index' => $node->getIndex()
                ];
            }
        }

        $query = $this->entityManager->createQuery('UPDATE Neos\ContentRepository\Domain\Model\NodeData n SET n.index = :index WHERE n.Persistence_Object_Identifier = :identifier');
        foreach ($nodesOnLevel as $node) {
            if ($node['index'] < $referenceIndex) {
                continue;
            }
            $newIndex = $node['index'] + 100;
            if ($newIndex > self::INDEX_MAXIMUM) {
                throw new Exception\NodeException(sprintf('Reached maximum node index of %s while setting index of node %s.', $newIndex, $node['path']), 1317140402);
            }
            if (isset($node['addedNode'])) {
                $node['addedNode']->setIndex($newIndex);
            } else {
                if ($entity = $this->entityManager->getUnitOfWork()->tryGetById($node['identifier'], NodeData::class)) {
                    $entity->setIndex($newIndex);
                }
                $query->setParameter('index', $newIndex);
                $query->setParameter('identifier', $node['identifier']);
                $query->execute();
            }
        }
    }
protected function openIndexSpace($parentPath, $referenceIndex)
    {
        $this->systemLogger->info(sprintf('Opening sortindex space after index %s at path %s.', $referenceIndex, $parentPath), LogEnvironment::fromMethodName(__METHOD__));

        /** @var Query $query */
        $query = $this->entityManager->createQuery('SELECT n.Persistence_Object_Identifier identifier, n.index, n.path FROM Neos\ContentRepository\Domain\Model\NodeData n WHERE n.parentPathHash = :parentPathHash ORDER BY n.index ASC');
        $query->setParameter('parentPathHash', md5($parentPath));

        $nodesOnLevel = [];
        /** @var $node NodeData */
        foreach ($query->getArrayResult() as $node) {
            $nodesOnLevel[] = [
                'identifier' => $node['identifier'],
                'path' => $node['path'],
                'index' => $node['index']
            ];
        }

        /** @var $node NodeData */
        foreach ($this->addedNodes as $node) {
            if ($node->getParentPath() === $parentPath) {
                $nodesOnLevel[] = [
                    'addedNode' => $node,
                    'path' => $node->getPath(),
                    'index' => $node->getIndex()
                ];
            }
        }

        $query = $this->entityManager->createQuery('UPDATE Neos\ContentRepository\Domain\Model\NodeData n SET n.index = :index WHERE n.Persistence_Object_Identifier = :identifier');
        foreach ($nodesOnLevel as $node) {
            if ($node['index'] < $referenceIndex) {
                continue;
            }
            $newIndex = $node['index'] + 100;
            if ($newIndex > self::INDEX_MAXIMUM) {
                throw new Exception\NodeException(sprintf('Reached maximum node index of %s while setting index of node %s.', $newIndex, $node['path']), 1317140402);
            }
            if (isset($node['addedNode'])) {
                $node['addedNode']->setIndex($newIndex);
            } else {
                if ($entity = $this->entityManager->getUnitOfWork()->tryGetById($node['identifier'], NodeData::class)) {
                    $entity->setIndex($newIndex);
                }
                $query->setParameter('index', $newIndex);
                $query->setParameter('identifier', $node['identifier']);
                $query->execute();
            }
        }
    }
protected function openIndexSpace ( $ parentPath , $ referenceIndex ) { $ this -> systemLogger -> info ( sprintf ( 'Opening sortindex space after index %s at path %s.' , $ referenceIndex , $ parentPath ) , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; /** @var Query $query */ $ query = $ this -> entityManager -> createQuery ( 'SELECT n.Persistence_Object_Identifier identifier, n.index, n.path FROM Neos\ContentRepository\Domain\Model\NodeData n WHERE n.parentPathHash = :parentPathHash ORDER BY n.index ASC' ) ; $ query -> setParameter ( 'parentPathHash' , md5 ( $ parentPath ) ) ; $ nodesOnLevel = [ ] ; /** @var $node NodeData */ foreach ( $ query -> getArrayResult ( ) as $ node ) { $ nodesOnLevel [ ] = [ 'identifier' => $ node [ 'identifier' ] , 'path' => $ node [ 'path' ] , 'index' => $ node [ 'index' ] ] ; } /** @var $node NodeData */ foreach ( $ this -> addedNodes as $ node ) { if ( $ node -> getParentPath ( ) === $ parentPath ) { $ nodesOnLevel [ ] = [ 'addedNode' => $ node , 'path' => $ node -> getPath ( ) , 'index' => $ node -> getIndex ( ) ] ; } } $ query = $ this -> entityManager -> createQuery ( 'UPDATE Neos\ContentRepository\Domain\Model\NodeData n SET n.index = :index WHERE n.Persistence_Object_Identifier = :identifier' ) ; foreach ( $ nodesOnLevel as $ node ) { if ( $ node [ 'index' ] < $ referenceIndex ) { continue ; } $ newIndex = $ node [ 'index' ] + 100 ; if ( $ newIndex > self :: INDEX_MAXIMUM ) { throw new Exception \ NodeException ( sprintf ( 'Reached maximum node index of %s while setting index of node %s.' , $ newIndex , $ node [ 'path' ] ) , 1317140402 ) ; } if ( isset ( $ node [ 'addedNode' ] ) ) { $ node [ 'addedNode' ] -> setIndex ( $ newIndex ) ; } else { if ( $ entity = $ this -> entityManager -> getUnitOfWork ( ) -> tryGetById ( $ node [ 'identifier' ] , NodeData :: class ) ) { $ entity -> setIndex ( $ newIndex ) ; } $ query -> setParameter ( 'index' , $ newIndex ) ; $ query -> setParameter ( 'identifier' , $ node [ 'identifier' ] ) ; $ query -> execute ( ) ; } } }
Make room in the sortindex-index space of a given path in preparation to inserting a node.
All indices that are greater or equal to the given referenceIndex are incremented by 100

@param string $parentPath
@param integer $referenceIndex
@throws Exception\NodeException
Make room in the sortindex - index space of a given path in preparation to inserting a node . All indices that are greater or equal to the given referenceIndex are incremented by 100