Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving methods are broken #15

Open
echo511 opened this issue Nov 4, 2011 · 1 comment
Open

Moving methods are broken #15

echo511 opened this issue Nov 4, 2011 · 1 comment

Comments

@echo511
Copy link

echo511 commented Nov 4, 2011

All of the methods for moving nodes can break the nested set. For instance let's have structure like this:

LFT name RGT

1 root 6
2 section 5
3 subsection 4

If I call method moveAsLastChildOf (section -> subsection) it will break the hierarchy instead of throw an exception. (issued by mlueft). For this problem I have found a simple fix:

public function moveAsLastChildOf(NodeWrapper $node)
{
    // Added ancestor check
    if($this->isAncestorOf($node) || $this == $node)
    {
        throw new \InvalidArgumentException('Cannot move node as a child of itself');
    }
    ...

Same for moveAsFirstChildOf().

The siblings methods however are more complicated especially moveAsPrevSiblingOf(subsection->section) which should be possible to do.

Any solutions?

@echo511
Copy link
Author

echo511 commented Nov 4, 2011

I just changed the first conditions of the methods to:

public function moveAsPrevSiblingOf(NodeWrapper $node)
{
    if($this->isAncestorOf($node) || $this->isRoot() || $node->isRoot() || $node == $this)
    {
        throw new \InvalidArgumentException('Cannot move node as a sibling of itself');
    }
...

So far it seems to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant