protected function detachOrPersistNode(AbstractNestedNode $node)
    {
        if (null !== $refreshed = $this->find($node->getUid())) {
            return $this->detachFromTree($refreshed)
                            ->refreshExistingNode($node);
        }

        if (false === $this->_em->contains($node)) {
            $this->_em->persist($node);
        }

        return $this;
    }