Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
|
2014-11-12 19:03:31 +03:00
|
|
|
use Doctrine\ORM\Proxy\Proxy;
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
use Doctrine\ORM\Tools\ToolsException;
|
|
|
|
|
|
|
|
class MergeUninitializedProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase {
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->_schemaTool->createSchema(array(
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\MUPFile'),
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\MUPPicture'),
|
|
|
|
));
|
|
|
|
} catch (ToolsException $ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-16 23:14:13 +03:00
|
|
|
public function testMergeDetachedUnInitializedProxy()
|
|
|
|
{
|
|
|
|
$detachedUninitialized = $this->_em->getReference(MUPFile::CLASSNAME, 123);
|
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$managed = $this->_em->getReference(MUPFile::CLASSNAME, 123);
|
|
|
|
|
|
|
|
$this->assertSame($managed, $this->_em->merge($detachedUninitialized));
|
|
|
|
|
|
|
|
$this->assertFalse($managed->__isInitialized());
|
|
|
|
$this->assertFalse($detachedUninitialized->__isInitialized());
|
|
|
|
}
|
|
|
|
|
2015-01-16 23:09:53 +03:00
|
|
|
public function testMergeUnserializedUnInitializedProxy()
|
|
|
|
{
|
|
|
|
$detachedUninitialized = $this->_em->getReference(MUPFile::CLASSNAME, 123);
|
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2015-01-16 23:14:13 +03:00
|
|
|
$managed = $this->_em->getReference(MUPFile::CLASSNAME, 123);
|
|
|
|
|
2015-01-16 23:09:53 +03:00
|
|
|
$this->assertSame(
|
2015-01-16 23:14:13 +03:00
|
|
|
$managed,
|
|
|
|
$this->_em->merge(unserialize(serialize($this->_em->merge($detachedUninitialized))))
|
2015-01-16 23:09:53 +03:00
|
|
|
);
|
2015-01-16 23:14:13 +03:00
|
|
|
|
|
|
|
$this->assertFalse($managed->__isInitialized());
|
|
|
|
$this->assertFalse($detachedUninitialized->__isInitialized());
|
2015-01-16 23:09:53 +03:00
|
|
|
}
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
public function testMergeUnserializedIntoEntity() {
|
|
|
|
|
|
|
|
$file = new MUPFile;
|
|
|
|
|
|
|
|
$picture = new MUPPicture;
|
|
|
|
$picture->file = $file;
|
|
|
|
|
|
|
|
$em = $this->_em;
|
|
|
|
$em->persist($picture);
|
|
|
|
$em->flush();
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$fileId = $file->fileId;
|
|
|
|
$pictureId = $picture->pictureId;
|
|
|
|
|
|
|
|
$picture = $em->find(__NAMESPACE__ . '\MUPPicture', $pictureId);
|
|
|
|
$serializedPicture = serialize($picture);
|
|
|
|
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$file = $em->find(__NAMESPACE__ . '\MUPFile', $fileId);
|
|
|
|
$picture = unserialize($serializedPicture);
|
2014-11-12 19:03:31 +03:00
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$picture = $em->merge($picture);
|
|
|
|
|
|
|
|
$this->assertEquals($file, $picture->file, "Unserialized proxy was not merged into managed entity");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMergeDetachedIntoEntity() {
|
|
|
|
|
|
|
|
$file = new MUPFile;
|
|
|
|
|
|
|
|
$picture = new MUPPicture;
|
|
|
|
$picture->file = $file;
|
|
|
|
|
|
|
|
$em = $this->_em;
|
|
|
|
$em->persist($picture);
|
|
|
|
$em->flush();
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$fileId = $file->fileId;
|
|
|
|
$pictureId = $picture->pictureId;
|
|
|
|
|
|
|
|
$picture = $em->find(__NAMESPACE__ . '\MUPPicture', $pictureId);
|
|
|
|
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$file = $em->find(__NAMESPACE__ . '\MUPFile', $fileId);
|
2014-11-12 19:03:31 +03:00
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$picture = $em->merge($picture);
|
|
|
|
|
|
|
|
$this->assertEquals($file, $picture->file, "Detached proxy was not merged into managed entity");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMergeUnserializedIntoProxy() {
|
|
|
|
|
|
|
|
$file = new MUPFile;
|
|
|
|
|
|
|
|
$picture = new MUPPicture;
|
|
|
|
$picture->file = $file;
|
|
|
|
|
|
|
|
$picture2 = new MUPPicture;
|
|
|
|
$picture2->file = $file;
|
|
|
|
|
|
|
|
$em = $this->_em;
|
|
|
|
$em->persist($picture);
|
|
|
|
$em->persist($picture2);
|
|
|
|
$em->flush();
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$pictureId = $picture->pictureId;
|
|
|
|
$picture2Id = $picture2->pictureId;
|
|
|
|
|
|
|
|
$picture = $em->find(__NAMESPACE__ . '\MUPPicture', $pictureId);
|
|
|
|
$serializedPicture = serialize($picture);
|
|
|
|
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$picture2 = $em->find(__NAMESPACE__ . '\MUPPicture', $picture2Id);
|
2014-11-12 19:03:31 +03:00
|
|
|
$this->assertFalse($picture->file->__isInitialized());
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$picture = unserialize($serializedPicture);
|
2014-11-12 19:03:31 +03:00
|
|
|
|
|
|
|
$this->assertTrue($picture->file instanceof Proxy);
|
|
|
|
$this->assertFalse($picture->file->__isInitialized());
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$picture = $em->merge($picture);
|
|
|
|
|
2014-11-12 19:03:31 +03:00
|
|
|
$this->assertTrue($picture->file instanceof Proxy);
|
|
|
|
$this->assertFalse($picture->file->__isInitialized(), 'Proxy has been initialized during merge.');
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$this->assertEquals($picture2->file, $picture->file, "Unserialized proxy was not merged into managed proxy");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMergeDetachedIntoProxy() {
|
|
|
|
|
|
|
|
$file = new MUPFile;
|
|
|
|
|
|
|
|
$picture = new MUPPicture;
|
|
|
|
$picture->file = $file;
|
|
|
|
|
|
|
|
$picture2 = new MUPPicture;
|
|
|
|
$picture2->file = $file;
|
|
|
|
|
|
|
|
$em = $this->_em;
|
|
|
|
$em->persist($picture);
|
|
|
|
$em->persist($picture2);
|
|
|
|
$em->flush();
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$pictureId = $picture->pictureId;
|
|
|
|
$picture2Id = $picture2->pictureId;
|
|
|
|
|
|
|
|
$picture = $em->find(__NAMESPACE__ . '\MUPPicture', $pictureId);
|
|
|
|
|
|
|
|
$em->clear();
|
|
|
|
|
|
|
|
$picture2 = $em->find(__NAMESPACE__ . '\MUPPicture', $picture2Id);
|
2014-11-12 19:03:31 +03:00
|
|
|
|
|
|
|
$this->assertTrue($picture->file instanceof Proxy);
|
|
|
|
$this->assertFalse($picture->file->__isInitialized());
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$picture = $em->merge($picture);
|
|
|
|
|
2014-11-12 19:03:31 +03:00
|
|
|
$this->assertTrue($picture->file instanceof Proxy);
|
|
|
|
$this->assertFalse($picture->file->__isInitialized(), 'Proxy has been initialized during merge.');
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
$this->assertEquals($picture2->file, $picture->file, "Detached proxy was not merged into managed proxy");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class MUPPicture
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Column(name="picture_id", type="integer")
|
|
|
|
* @Id @GeneratedValue
|
|
|
|
*/
|
|
|
|
public $pictureId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToOne(targetEntity="MUPFile", cascade={"persist", "merge"})
|
|
|
|
* @JoinColumn(name="file_id", referencedColumnName="file_id")
|
|
|
|
*/
|
|
|
|
public $file;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class MUPFile
|
|
|
|
{
|
2015-01-16 23:09:53 +03:00
|
|
|
const CLASSNAME = __CLASS__;
|
|
|
|
|
Don't load detached proxies when merging them.
Ticket DDC-1392 fixed an issue where uninitialized proxies could not be merged
because the merge routine couldn't get the identifier from them. The soution
was to initialize the proxy.
Ticket DDC-1734 fixed the merging of *unserialized* uninitialized proxies by
resetting their internals, so these proxies were able to initialize, as required
by the fix for DDC-1392.
Somehow, in the meanwhile, the fix for DDC-1392 is not needed anymore:
reverting the patch will not break the associated test (but it does break the
test for DDC-1734). This means it is not needed anymore to initialize the proxy
when merging.
Uninitialized proxies that get merged should not be loaded at all. Since they
are not initialized, the entity data for sure hasn't changed, so it can be
safely ignored. Actually, the only thing the data is needed for while merging,
is to copy it into the managed entity, but that one is already supposed to be
up to date. By not initializing the proxy, a potential database roundtrip is
saved, and the fix for DDC-1734 is not needed anymore.
Besides optimizing the merge, this patch also solves an issue with merging.
Currently, when a detached uninitialized proxy is merged while there is already a
corresponding managed entity (proxy or not), the ORM returns a blank entity
instead of returning the already managed entity. This patch makes sure that
already existing managed entities are re-used.
2014-11-06 09:16:20 +03:00
|
|
|
/**
|
|
|
|
* @Column(name="file_id", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
public $fileId;
|
|
|
|
|
|
|
|
}
|