Skip to content

Issue with check when moving node to itself #65

@uxweb

Description

@uxweb

Thank you very much for the effort you are putting to solve the issues.

Here i have a new one.

I have this simple data:

id name _lft _rgt parent_id
1 NODE1 1 4 NULL
2 NODE2 2 3 1

Then i append node 2 to itself

$node  = Node::find(2);
$node2 = Node::find(2);
$node->appendTo($node2);

This is letting it happen, now the data looks like:

id name _lft _rgt parent_id
1 NODE1 1 4 NULL
2 NODE2 2 3 2

I made another test to debug the QueryBuilder moveNodemethod:

/**
     * Move a node to the new position.
     *
     * @param int $key
     * @param int $position
     *
     * @return int
     *
     * @throws \LogicException
     */
    public function moveNode($key, $position)
    {
        list($lft, $rgt) = $this->model->newServiceQuery()->getPlainNodeData($key, true);

        dd($lft, $position, $rgt); // To know what data is coming to the condition!

        if ($lft < $position && $position < $rgt)
        {
            throw new LogicException('Cannot move node into itself.');
        }

I reverted the data as the initial shape at the beginning and did the append to itself again, this is what i get from those 3 variables:

$lft = 2
$position = 3
$rgt = 3

With this data the condition is not met and the exception is not thrown.

I understand that position is set to the next of the node you are appending to, but as it is the same node it does not know that.

I think that a another condition can be done, something like:

if the node i want to append to is the same, then throw the exception.

What do you think?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions