From af3591fbca0610c3c8b9859efe5fae79214b7fe1 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 5 Jun 2017 11:47:15 +0200 Subject: [PATCH 1/7] Fixes #5804 --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6af159fc7..3c502e3d7 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -344,9 +344,13 @@ class BasicEntityPersister implements EntityPersister . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; + $types = []; + foreach ($identifier as $fieldName) { + $types[] = $versionedClass->fieldMappings[$fieldName]['type']; + } $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - $value = $this->conn->fetchColumn($sql, array_values($flatId)); + $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); } From 4ef0a238bfb0b5da59104bfe11189f4c5b103020 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Tue, 6 Jun 2017 17:28:34 +0200 Subject: [PATCH 2/7] Inferring id's field types --- .../ORM/Persisters/Entity/BasicEntityPersister.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 3c502e3d7..f94d79e96 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -345,9 +345,12 @@ class BasicEntityPersister implements EntityPersister . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; $types = []; - foreach ($identifier as $fieldName) { - $types[] = $versionedClass->fieldMappings[$fieldName]['type']; + foreach ($id as $field => $value) { + foreach ($this->getTypes($field, $value, $versionedClass) as $type) { + $types[] = $type; + } } + $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); From f6907b95032e0af3875d802405e432d47df7578c Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 12 Jun 2017 15:40:14 +0200 Subject: [PATCH 3/7] Applied patches as for #6496 --- .../ORM/Functional/Ticket/GH5804Test.php | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php new file mode 100644 index 000000000..6d877711d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -0,0 +1,108 @@ +_schemaTool->createSchema( + [$this->_em->getClassMetadata(GH5804Article::class)] + ); + } + + public function testTextColumnSaveAndRetrieve2() + { + $firstArticle = new GH5804Article; + $firstArticle->text = 'Max'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(1, $firstArticle->version); + + $firstArticle->text = 'Moritz'; + $this->_em->persist($firstArticle); + $this->_em->flush(); + + self::assertSame(2, $firstArticle->version); + } +} + +final class GH5804Generator extends AbstractIdGenerator +{ + /** + * {@inheritdoc} + */ + public function generate(EntityManager $em, $entity) + { + return 'test5804'; + } +} + +final class GH5804Type extends Type +{ + const NAME = 'GH5804Type'; + + public function getName() + { + return self::NAME; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (empty($value)) { + return null; + } + + return 'testGh5804DbValue'; + } +} + +/** + * @Entity + * @Table(name="gh5804_articles") + */ +class GH5804Article +{ + /** + * @Id + * @Column(type="GH5804Type") + * @GeneratedValue(strategy="CUSTOM") + * @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) + */ + public $id; + /** + * @Version + * @Column(type="integer") + */ + public $version; + + /** + * @Column(type="text") + */ + public $text; +} From 82c87081b4804c013c6f34b780f1bf015d18e799 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Mon, 12 Jun 2017 15:41:20 +0200 Subject: [PATCH 4/7] Changed SQL declaration for custom type --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 6d877711d..272d2fdbe 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -66,7 +66,7 @@ final class GH5804Type extends Type */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { - return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); + return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); } /** From 60a2628f9d1a62fbe4bc467dbf60301344c52953 Mon Sep 17 00:00:00 2001 From: Alessandro Frangioni <> Date: Tue, 20 Jun 2017 09:25:14 +0200 Subject: [PATCH 5/7] Iteration simplified --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index f94d79e96..9cec30ffd 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -346,9 +346,7 @@ class BasicEntityPersister implements EntityPersister $types = []; foreach ($id as $field => $value) { - foreach ($this->getTypes($field, $value, $versionedClass) as $type) { - $types[] = $type; - } + $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); } $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); From eba8fec1fb6460937504fe4dcd6036b5ce1a4a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 22:39:47 +0200 Subject: [PATCH 6/7] Move identifier types extraction to a method --- .../Entity/BasicEntityPersister.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 9cec30ffd..972199c5e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -344,16 +344,28 @@ class BasicEntityPersister implements EntityPersister . ' FROM ' . $tableName . ' WHERE ' . implode(' = ? AND ', $identifier) . ' = ?'; + + $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); + + $value = $this->conn->fetchColumn( + $sql, + array_values($flatId), + 0, + $this->extractIdentifierTypes($id, $versionedClass) + ); + + return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); + } + + private function extractIdentifierTypes(array $id, ClassMetadata $versionedClass) : array + { $types = []; + foreach ($id as $field => $value) { $types = array_merge($types, $this->getTypes($field, $value, $versionedClass)); } - $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - - $value = $this->conn->fetchColumn($sql, array_values($flatId), 0, $types); - - return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); + return $types; } /** From 6bf9f6f72f84de58a180aa9124f7ec8b0089fe56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sat, 22 Jul 2017 22:41:07 +0200 Subject: [PATCH 7/7] Remove unnecessary annotation from test --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php index 272d2fdbe..77d4fbc87 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH5804Test.php @@ -84,7 +84,6 @@ final class GH5804Type extends Type /** * @Entity - * @Table(name="gh5804_articles") */ class GH5804Article { @@ -95,6 +94,7 @@ class GH5804Article * @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) */ public $id; + /** * @Version * @Column(type="integer")