DDC-3208 - hotfix for DDC-3160 backported to 2.4.x
This commit is contained in:
parent
84f8ef5ca4
commit
42226dadd1
@ -925,12 +925,13 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($changeSet) {
|
if ($changeSet) {
|
||||||
$this->entityChangeSets[$oid] = (isset($this->entityChangeSets[$oid]))
|
if (isset($this->entityChangeSets[$oid])) {
|
||||||
? array_merge($this->entityChangeSets[$oid], $changeSet)
|
$this->entityChangeSets[$oid] = array_merge($this->entityChangeSets[$oid], $changeSet);
|
||||||
: $changeSet;
|
} else if ( ! isset($this->entityInsertions[$oid])) {
|
||||||
|
$this->entityChangeSets[$oid] = $changeSet;
|
||||||
|
$this->entityUpdates[$oid] = $entity;
|
||||||
|
}
|
||||||
$this->originalEntityData[$oid] = $actualData;
|
$this->originalEntityData[$oid] = $actualData;
|
||||||
$this->entityUpdates[$oid] = $entity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2499,7 +2500,7 @@ class UnitOfWork implements PropertyChangedListener
|
|||||||
|
|
||||||
$id = array($class->identifier[0] => $id);
|
$id = array($class->identifier[0] => $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$idHash = implode(' ', $id);
|
$idHash = implode(' ', $id);
|
||||||
|
|
||||||
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
|
||||||
|
70
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php
Normal file
70
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3160Test.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||||
|
use Doctrine\ORM\Event\OnFlushEventArgs;
|
||||||
|
use Doctrine\ORM\Events;
|
||||||
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FlushEventTest
|
||||||
|
*
|
||||||
|
* @author robo
|
||||||
|
*/
|
||||||
|
class DDC3160Test extends OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
protected function setUp() {
|
||||||
|
$this->useModelSet('cms');
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-3160
|
||||||
|
*/
|
||||||
|
public function testNoUpdateOnInsert()
|
||||||
|
{
|
||||||
|
$listener = new DDC3160OnFlushListener();
|
||||||
|
$this->_em->getEventManager()->addEventListener(Events::onFlush, $listener);
|
||||||
|
|
||||||
|
$user = new CmsUser;
|
||||||
|
$user->username = 'romanb';
|
||||||
|
$user->name = 'Roman';
|
||||||
|
$user->status = 'Dev';
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->flush();
|
||||||
|
|
||||||
|
$this->_em->refresh($user);
|
||||||
|
|
||||||
|
$this->assertEquals('romanc', $user->username);
|
||||||
|
$this->assertEquals(1, $listener->inserts);
|
||||||
|
$this->assertEquals(0, $listener->updates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DDC3160OnFlushListener
|
||||||
|
{
|
||||||
|
public $inserts = 0;
|
||||||
|
public $updates = 0;
|
||||||
|
|
||||||
|
public function onFlush(OnFlushEventArgs $args)
|
||||||
|
{
|
||||||
|
$em = $args->getEntityManager();
|
||||||
|
$uow = $em->getUnitOfWork();
|
||||||
|
|
||||||
|
foreach ($uow->getScheduledEntityInsertions() as $entity) {
|
||||||
|
$this->inserts++;
|
||||||
|
if ($entity instanceof CmsUser) {
|
||||||
|
$entity->username = 'romanc';
|
||||||
|
$cm = $em->getClassMetadata(get_class($entity));
|
||||||
|
$uow->recomputeSingleEntityChangeSet($cm, $entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($uow->getScheduledEntityUpdates() as $entity) {
|
||||||
|
$this->updates++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user