[PHPCR-34] replacing a document fails Created: 13/Nov/11  Updated: 22/Feb/12  Resolved: 22/Feb/12

Status: Resolved
Project: Doctrine PHPCR
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: David Buchmann Assignee: Jordi Boggiano
Resolution: Fixed Votes: 0
Labels: None


 Description   

when we have a saved document and remove that, then add a document at the same path without a flush in between, we get an exception. the reason is that persist already adds the phpcr node, but scheduleRemove does not remove the phpcrnode right away.

the fix looks like it should be:
UnitOfWork.php 504 remove phpcr node - 1022 do not remove here as it was removed before.

but this leads to a problem that is either in jackalope or the phpcr-odm about /functional/user/phpcr:class being not found.

1) Doctrine\Tests\ODM\PHPCR\Functional\BasicCrudTest::testRemoveAndInsert
PHPCR\ItemExistsException: This node already has a child named user.

/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/vendor/jackalope/src/Jackalope/Node.php:303
/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:763
/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:404
/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:386
/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/DocumentManager.php:312
/home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/tests/Doctrine/Tests/ODM/PHPCR/Functional/BasicCrudTest.php:152



 Comments   
Comment by Lukas Kahwe [ 17/Nov/11 ]

imho this is now fixed. it will throw an \InvalidArgumentException that the document is detached. I have added relevant tests.

i have also created a ticket to add something to the persistence interfaces to make it possible to ensure that a node is cleared back to defaults for all fields not being persisted: http://www.doctrine-project.org/jira/browse/DCOM-77

Comment by David Buchmann [ 23/Jan/12 ]

i still have a problem with this. doing

if ($old_node = $this->dm->find(null, $path))

{ $this->dm->remove($old_node); }

$menuitem = new MultilangMenuItem();
$menuitem->setPath($path);
$menuitem->setName($name);
$menuitem->setLabel($label);

$this->dm->persist($menuitem);
return $menuitem;

leads to an exception. but imo i should be able to do this? what if i want to change the type of document at this location?

InvalidArgumentException
Detached document passed to persist().

Exception trace:
() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:444
Doctrine\ODM\PHPCR\UnitOfWork->doScheduleInsert() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:414
Doctrine\ODM\PHPCR\UnitOfWork->scheduleInsert() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony-cmf/vendor/doctrine-phpcr-odm/lib/Doctrine/ODM/PHPCR/DocumentManager.php:447
Doctrine\ODM\PHPCR\DocumentManager->persist() at /home/david/liip/symfony-cmf/cmf-sandbox/src/Sandbox/MainBundle/Resources/data/fixtures/030_LoadMenuData.php:90
Symfony\Cmf\Bundle\MenuBundle\Resources\data\fixtures\LoadMenuData->createMenuItem() at /home/david/liip/symfony-cmf/cmf-sandbox/src/Sandbox/MainBundle/Resources/data/fixtures/030_LoadMenuData.php:43
Symfony\Cmf\Bundle\MenuBundle\Resources\data\fixtures\LoadMenuData->load() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/doctrine-data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php:94
Doctrine\Common\DataFixtures\Executor\AbstractExecutor->load() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/doctrine-data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php:55
Doctrine\Common\DataFixtures\Executor\PHPCRExecutor->execute() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/bundles/Doctrine/Bundle/PHPCRBundle/Command/LoadFixtureCommand.php:86
Doctrine\Bundle\PHPCRBundle\Command\LoadFixtureCommand->execute() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/src/Symfony/Component/Console/Command/Command.php:237
Symfony\Component\Console\Command\Command->run() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/src/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:75
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/src/Symfony/Component/Console/Application.php:106
Symfony\Component\Console\Application->run() at /home/david/liip/symfony-cmf/cmf-sandbox/app/console:16

Comment by Lukas Kahwe [ 02/Feb/12 ]

I guess this is related to adding DocumentManager::merge()
http://www.doctrine-project.org/jira/browse/PHPCR-13

Comment by Lukas Kahwe [ 22/Feb/12 ]

duplicate of http://www.doctrine-project.org/jira/browse/PHPCR-13

Generated at Fri Oct 31 11:36:59 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.