Move the current node as previous sibling of the node passed
@param NodeInterface $beforeNode
@return NodeAbstraction
@nestedSetMethod
324732
public function moveAsPrevSiblingOf(NodeInterface $beforeNode)
	{
		$pos = $beforeNode->getLeftValue();
		$level = $beforeNode->getLevel();
		$this->move($pos, $level);
		
		return $this;
	}
1302798
public function moveAsLastChildOf(NodeWrapper $node)
    {
        if($node == $this)
        {
            throw new \InvalidArgumentException('Cannot move node as a child of itself');
        }

        $em = $this->getManager()->getEntityManager();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            if($this->hasManyRoots() && $this->getRootValue() !== $node->getRootValue())
            {
                $this->moveBetweenTrees($node, $node->getRightValue(), __FUNCTION__);
            }
            else
            {
                $this->updateNode($node->getRightValue());
            }

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction
    }
786620
public function move($nodeName, $newParentName, $prepend = false)
    {
        if (!$this->nodes->hasKey($nodeName)) {
            throw new NodeNotFoundException();
        }
        $node = $this->nodes->get($nodeName);
        $this->remove($nodeName);
        $this->add($newParentName, $nodeName, $node, $prepend);

        return $this;
    }
898859
public function setNodeSegment(NodeInterface $node, string $segment, ?string $previous = null) : void
    {
        if ($this->isNodeBlacklisted($node)) {
            return;
        }

        if (!$previous) {
            $previous = $this->getNodeSegment($node);
        }
        if (empty($segment)) {
            $segment = null;
        }

        if ($previous === $segment) {
            return; // Nothing to do
        }

        $this
            ->database
            ->merge('ucms_seo_node')
            ->key(['nid' => $node->id()])
            ->fields(['alias_segment' => $segment])
            ->execute()
        ;

        if (empty($segment)) {
            $this->onAliasChange([$node->id()]);
        } else {
            $this->onAliasChange([$node->id()]);
        }
    }
47794
public function addNode(NodeInterface $node): NodeInterface
    {
        $this->_nodes[$node->getId()] = $node;

        if ($this->getParent()) {
            $this->getParent()->addNode($node);
        }

        return $this;
    }
591098
def node_insert_before(self, node, new_node):
        """"""

        assert(not self.node_is_on_list(new_node))
        assert(node is not new_node)

        prev = self.node_prev(node)
        assert(prev is not None)
        self.node_set_prev(node, new_node)
        self.node_set_next(new_node, node)

        self.node_set_prev(new_node, prev)
        self.node_set_next(prev, new_node)
926831
public function beforeNodeCreate()
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = $this->eventEmittingService->generate(self::NODE_ADDED, [], NodeEvent::class);
        $this->currentNodeAddEvents[] = $nodeEvent;
        $this->eventEmittingService->pushContext($nodeEvent);
    }
1240234
public function checkMove(Node $newParent)
    {
        $result = null;
        if ($this->getTreeNodeParentID() != $newParent->getTreeNodeID()) {
            if ($this->getTreeNodeID() == $newParent->getTreeNodeID()) {
                $result = new MoveException(t("It's not possible to move a node under itself"));
            } else {
                foreach ($newParent->getTreeNodeParentArray() as $newParentAncestor) {
                    if ($newParentAncestor->getTreeNodeID() == $this->getTreeNodeID()) {
                        $result = MoveException(t("It's not possible to move a node under one of its descending nodes"));
                        break;
                    }
                }
            }
        }

        return $result;
    }
111374
public static void insertBefore(Element newElement, Element before) {
        before.parentNode.insertBefore(newElement, before);
    }
539805
public function moveNode(Node $node, Node $parent)
    {
        $node->setParent($parent)->updateId();
        $this->idList[$node->id] = $node;

        return $this;
    }
1335853
protected function moveNode(Node\NodeInterface $item, $moveLeft, $moveRight, $moveLevel)
	{
//		$newLeft = $item->getLeftValue() + (int) $moveLeft;
//		$newRight = $item->getRightValue() + (int) $moveRight;
//		$newLevel = $item->getLevel() + (int) $moveLevel;
//
// Call original local move method for items not in the database yet
		parent::moveNode($item, $moveLeft, $moveRight, $moveLevel);

// In case of entity update, make the new nested set values to be ignored
		$insert = $this->entityManager->getUnitOfWork()->isScheduledForInsert($item);
		if ( ! $insert) {
			$oid = spl_object_hash($item);
			$this->entityManager->getUnitOfWork()->setOriginalEntityProperty($oid, 'level', $item->getLevel());
			$this->entityManager->getUnitOfWork()->setOriginalEntityProperty($oid, 'right', $item->getRightValue());
			$this->entityManager->getUnitOfWork()->setOriginalEntityProperty($oid, 'left', $item->getLeftValue());
		}

//
//		if ($insert) {
//			// Call original local move method for items not in the database yet
//			parent::moveNode($item, $moveLeft, $moveRight, $moveLevel);
//		} else {
//			// Refresh so additional UPDATE-s are not executed on the server
//			$this->entityManager->refresh($item);
//		}
//		// Double check the values, should not happen
//		if ($item->getLeftValue() != $newLeft) {
//			$item->setLeftValue($newLeft);
//		}
//		if ($item->getRightValue() != $newRight) {
//			$item->setRightValue($newRight);
//		}
//		if ($item->getLevel() != $newLevel) {
//			$item->setLevel($newLevel);
//		}
	}
807427
public function add(navigation_node $node, $beforekey=null) {
        global $CFG;
        $key = $node->key;
        $type = $node->type;

        // First check we have a 2nd dimension for this type
        if (!array_key_exists($type, $this->orderedcollection)) {
            $this->orderedcollection[$type] = array();
        }
        // Check for a collision and report if debugging is turned on
        if ($CFG->debug && array_key_exists($key, $this->orderedcollection[$type])) {
            debugging('Navigation node intersect: Adding a node that already exists '.$key, DEBUG_DEVELOPER);
        }

        // Find the key to add before
        $newindex = $this->count;
        $last = true;
        if ($beforekey !== null) {
            foreach ($this->collection as $index => $othernode) {
                if ($othernode->key === $beforekey) {
                    $newindex = $index;
                    $last = false;
                    break;
                }
            }
            if ($newindex === $this->count) {
                debugging('Navigation node add_before: Reference node not found ' . $beforekey .
                        ', options: ' . implode(' ', $this->get_key_list()), DEBUG_DEVELOPER);
            }
        }

        // Add the node to the appropriate place in the by-type structure (which
        // is not ordered, despite the variable name)
        $this->orderedcollection[$type][$key] = $node;
        if (!$last) {
            // Update existing references in the ordered collection (which is the
            // one that isn't called 'ordered') to shuffle them along if required
            for ($oldindex = $this->count; $oldindex > $newindex; $oldindex--) {
                $this->collection[$oldindex] = $this->collection[$oldindex - 1];
            }
        }
        // Add a reference to the node to the progressive collection.
        $this->collection[$newindex] = $this->orderedcollection[$type][$key];
        // Update the last property to a reference to this new node.
        $this->last = $this->orderedcollection[$type][$key];

        // Reorder the array by index if needed
        if (!$last) {
            ksort($this->collection);
        }
        $this->count++;
        // Return the reference to the now added node
        return $node;
    }
1150500
public static function move_category(int $id, int $beforeid) {
        $params = self::validate_parameters(self::move_category_parameters(),
            ['id' => $id, 'beforeid' => $beforeid]);
        $category = core_customfield\category_controller::create($id);
        $handler = $category->get_handler();
        self::validate_context($handler->get_configuration_context());
        if (!$handler->can_configure()) {
            throw new moodle_exception('nopermissionconfigure', 'core_customfield');
        }
        $handler->move_category($category, $params['beforeid']);
    }
1082614
private function removeOldEvents($beforeId)
    {
        $oldEvents = $this->eventCollection
            ->addFieldToFilter('event_id', ['lteq' => $beforeId]);

        $oldEvents->walk('delete');

        return $this;
    }
320525
public function beforeNodeCopy(NodeInterface $sourceNode, NodeInterface $targetParentNode)
    {
        if (!$this->eventEmittingService->isEnabled()) {
            return;
        }

        if ($this->currentlyCopying) {
            throw new \Exception('TODO: already copying...');
        }

        $this->currentlyCopying = true;

        /* @var $nodeEvent NodeEvent */
        $nodeEvent = $this->eventEmittingService->emit(self::NODE_COPY, [
            'copiedInto' => $targetParentNode->getContextPath()
        ], NodeEvent::class);
        $nodeEvent->setNode($sourceNode);
        $this->eventEmittingService->pushContext();
    }
631705
function insertTo(root, node, before) {
  if (!root) return
  root.insertBefore(before, node)
  root.removeChild(node)
}
1033512
public function apply()
    {
        if ($this->canApply()) {
            $before = self::cloneNodeWithNodeData($this->getSubject());
            $parent = $before->getParent();

            if ($this->nodeNameAvailableBelowNode($this->getSiblingNode()->getParent(), $this->getSubject())) {
                $this->getSubject()->moveAfter($this->getSiblingNode());
            } else {
                $nodeName = $this->generateUniqueNodeName($this->getSiblingNode()->getParent());
                $this->getSubject()->moveAfter($this->getSiblingNode(), $nodeName);
            }

            $updateParentNodeInfo = new UpdateNodeInfo();
            $updateParentNodeInfo->setNode($parent);

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

            $this->finish($before);
        }
    }