8000 Update identityMap when entity gets managed again · symfonyaml/orm@bac6570 · GitHub
[go: up one dir, main page]

Skip to content

Commit bac6570

Browse files
nclavaudOcramius
authored andcommitted
Update identityMap when entity gets managed again
http://www.doctrine-project.org/jira/browse/DDC-3619 When using SoftDeleteable doctrine extension, an entity can be scheduled for deletion, then persisted before flushing. In such a case, the entity was removed from the unit of work identity map and no reference was hold. This could lead to spl_object_hash collisions, and prevent another, new entity to be persisted later. This fix makes sure the unit of work identity map holds a reference to the entity after it has been soft-deleted.
1 parent 18c8732 commit bac6570

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@ private function doPersist($entity, array &$visited)
16301630
case self::STATE_REMOVED:
16311631
// Entity becomes managed again
16321632
unset($this->entityDeletions[$oid]);
1633+
$this->addToIdentityMap($entity);
16331634

16341635
$this->entityStates[$oid] = self::STATE_MANAGED;
16351636
break;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Doctrine\Tests\ORM\Functional\Ticket;
4+
5+
class DDC3619Test extends \Doctrine\Tests\OrmFunctionalTestCase
6+
{
7+
protected function setup()
8+
{
9+
parent::setup();
10+
11+
$this->_schemaTool->createSchema(
12+
array(
13+
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC3619Entity'),
14+
)
15+
);
16+
}
17+
18+
public function testIssue()
19+
{
20+
$uow = $this->_em->getUnitOfWork();
21+
22+
$entity = new DDC3619Entity();
23+
$this->_em->persist($entity);
24+
$this->_em->flush();
25+
$this->assertTrue($uow->isInIdentityMap($entity));
26+
27+
$this->_em->remove($entity);
28+
$this->assertFalse($uow->isInIdentityMap($entity));
29+
30+
$this->_em->persist($entity);
31+
$this->assertTrue($uow->isInIdentityMap($entity));
32+
}
33+
}
34+
35+
/**
36+
* @Entity()
37+
*/
38+
class DDC3619Entity
39+
{
40+
/**
41+
* @Id
42+
* @Column(type="integer")
43+
* @GeneratedValue(strategy="IDENTITY")
44+
*/
45+
protected $id;
46+
}

0 commit comments

Comments
 (0)
0