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

refresh should not trigger a reload #321

Open
dbu opened this issue Dec 19, 2016 · 3 comments
Open

refresh should not trigger a reload #321

dbu opened this issue Dec 19, 2016 · 3 comments

Comments

@dbu
Copy link
Member

dbu commented Dec 19, 2016

reported in doctrine/DoctrinePHPCRBundle#265 we can get an exception during the clear. instead, clear should not trigger any state checks. (it should also not give you children that are gone, not sure if it does or not)

  [PHPCR\InvalidItemStateException]
  Item /cms/routes/krzysztof-krawczyk is deleted


Exception trace:
 () at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/jackalope/jackalope/src/Jackalope/Item.php:640
 Jackalope\Item->checkState() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/jackalope/jackalope/src/Jackalope/Node.php:835
 Jackalope\Node->getIdentifier() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/jackalope/jackalope/src/Jackalope/ObjectManager.php:1110
 Jackalope\ObjectManager->refresh() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/jackalope/jackalope/src/Jackalope/Session.php:463
 Jackalope\Session->refresh() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:3201
 Doctrine\ODM\PHPCR\UnitOfWork->clear() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/DocumentManager.php:883
 Doctrine\ODM\PHPCR\DocumentManager->clear() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/doctrine/phpcr-bundle/DoctrinePHPCRBundle.php:159
 Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle->clearDocumentManagers() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/doctrine/phpcr-bundle/DoctrinePHPCRBundle.php:141
 Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle->shutdown() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:152
 Symfony\Component\HttpKernel\Kernel->shutdown() at /Users/pamil/Projects/Lakion/SyliusCmsBundle/vendor/friends-of-behat/symfony-extension/src/Listener/KernelRebooter.php:47
@pamil
Copy link
Contributor

pamil commented Dec 19, 2016

Any idea how to fix it?

/** @var $node Node */
foreach ($this->objectsByPath['Node'] as $node) {
    if (! $keepChanges || ! ($node->isDeleted() || $node->isNew())) {
        // if we keep changes, do not restore a deleted item
        $this->objectsByUuid[$node->getIdentifier()] = $node->getPath();
        $node->setDirty($keepChanges);
    }
}

$node->getIdentifier() and $node->getPath() cause checking the state, can we remove that line and just set node as dirty instead? What approach will work the best here?

@dbu
Copy link
Member Author

dbu commented Dec 19, 2016

we should probably catch the exception at that point and rewrite history to match (e.g. set the node as deleted resp. make it a new addition if $keepChanges)

but also, we should not do any of this with a node that is not yet initialized or that is already dirty. being dirty with the same $keepChanges flag that we have. afaik the jackalope node has a (non phpcr-api) method to check if its dirty

@SalvatorePollaci
Copy link

It seems that $this->objectsByPath is modified during the foreach statement. A workaround could be to make sure that the current array element is still in $this->objectsByPath.

/** @var $node Node */
foreach ($this->objectsByPath[Node::class] as $key => $node) {
    if (!isset($this->objectsByPath[Node::class][$key]))
        continue;

    if (! $keepChanges || ! ($node->isDeleted() || $node->isNew())) {
        // if we keep changes, do not restore a deleted item
        $this->objectsByUuid[$node->getIdentifier()] = $node->getPath();
        $node->setDirty($keepChanges);
    }
}

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

3 participants