From cc3d872b958587c17df5b40b437d23ae03890a82 Mon Sep 17 00:00:00 2001 From: Thibault Buathier Date: Mon, 5 Jun 2023 10:58:32 +0200 Subject: [PATCH 1/3] revert: transform backed enum to value --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 144f340d00..623c2cb61c 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -273,10 +273,6 @@ public function executeInserts() $paramIndex = 1; foreach ($insertData[$tableName] as $column => $value) { - if ($value instanceof BackedEnum) { - $value = $value->value; - } - $stmt->bindValue($paramIndex++, $value, $this->columnTypes[$column]); } } From 6c9b29f237c0f56792bbf4e00f6180fb1ede5bfe Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Jun 2023 21:42:13 +0200 Subject: [PATCH 2/3] Don't call canEmulateSchemas in SchemaTool when possible (#10762) --- lib/Doctrine/ORM/Tools/SchemaTool.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 6f9a4193d4..dc0fbc53e7 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets; use Doctrine\Deprecations\Deprecation; @@ -406,8 +407,14 @@ static function (ClassMetadata $class) use ($idMapping): bool { } } - if (! $this->platform->supportsSchemas() && ! $this->platform->canEmulateSchemas()) { - $schema->visit(new RemoveNamespacedAssets()); + if (! $this->platform->supportsSchemas()) { + $filter = /** @param Sequence|Table $asset */ static function ($asset) use ($schema): bool { + return ! $asset->isInDefaultNamespace($schema->getName()); + }; + + if (array_filter($schema->getSequences() + $schema->getTables(), $filter) && ! $this->platform->canEmulateSchemas()) { + $schema->visit(new RemoveNamespacedAssets()); + } } if ($eventManager->hasListeners(ToolEvents::postGenerateSchema)) { From 3827dd769edf25d59fa29a7d63efd6ba15b3a789 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 6 Jun 2023 11:27:31 +0200 Subject: [PATCH 3/3] Don't call deprecated getSQLResultCasing and usesSequenceEmulatedIdentityColumns when we know the platform (#10759) --- lib/Doctrine/ORM/Internal/SQLResultCasing.php | 4 +++- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 7 ++++++- phpstan-dbal2.neon | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/SQLResultCasing.php b/lib/Doctrine/ORM/Internal/SQLResultCasing.php index 3edfc91196..d82a37ba61 100644 --- a/lib/Doctrine/ORM/Internal/SQLResultCasing.php +++ b/lib/Doctrine/ORM/Internal/SQLResultCasing.php @@ -9,7 +9,9 @@ use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use function get_class; use function method_exists; +use function strpos; use function strtolower; use function strtoupper; @@ -26,7 +28,7 @@ private function getSQLResultCasing(AbstractPlatform $platform, string $column): return strtolower($column); } - if (method_exists(AbstractPlatform::class, 'getSQLResultCasing')) { + if (strpos(get_class($platform), 'Doctrine\\DBAL\\Platforms\\') !== 0 && method_exists(AbstractPlatform::class, 'getSQLResultCasing')) { return $platform->getSQLResultCasing($column); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index f7aec6e3ba..3d97dce814 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -7,6 +7,9 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Platforms; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\Deprecations\Deprecation; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\LoadClassMetadataEventArgs; @@ -621,9 +624,11 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void case ClassMetadata::GENERATOR_TYPE_IDENTITY: $sequenceName = null; $fieldName = $class->identifier ? $class->getSingleIdentifierFieldName() : null; + $platform = $this->getTargetPlatform(); // Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour. - if ($this->getTargetPlatform()->usesSequenceEmulatedIdentityColumns()) { + /** @psalm-suppress UndefinedClass, InvalidClass */ + if (! $platform instanceof MySQLPlatform && ! $platform instanceof SqlitePlatform && ! $platform instanceof SQLServerPlatform && $platform->usesSequenceEmulatedIdentityColumns()) { Deprecation::trigger( 'doctrine/orm', 'https://github.com/doctrine/orm/issues/8850', diff --git a/phpstan-dbal2.neon b/phpstan-dbal2.neon index 440358bc41..646aceadc5 100644 --- a/phpstan-dbal2.neon +++ b/phpstan-dbal2.neon @@ -10,6 +10,9 @@ parameters: - '/Call to an undefined method Doctrine\\DBAL\\Connection::createSchemaManager\(\)\./' # Class name will change in DBAL 3. - '/^Class Doctrine\\DBAL\\Platforms\\PostgreSQLPlatform not found\.$/' + - + message: '/Doctrine\\DBAL\\Platforms\\MyS(ql|QL)Platform/' + path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php # Forward compatibility for DBAL 3.5 - '/^Call to an undefined method Doctrine\\DBAL\\Platforms\\AbstractPlatform::getAlterSchemaSQL\(\).$/'