From ad9f67c21917b19c5ec290d8d25c20bd97e7e492 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 22 Aug 2021 16:32:51 +0200 Subject: [PATCH] Remove calls to fixSchemaElementName() Signed-off-by: Alexander M. Turek --- .../ORM/Mapping/ClassMetadataFactory.php | 30 ++++++++++++------- psalm-baseline.xml | 4 +-- .../ORM/Mapping/ClassMetadataFactoryTest.php | 2 -- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index da9b361d329..4d2dccf5b73 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -21,14 +21,6 @@ use Doctrine\ORM\Mapping\Exception\InvalidCustomGenerator; use Doctrine\ORM\Mapping\Exception\TableGeneratorNotImplementedYet; use Doctrine\ORM\Mapping\Exception\UnknownGeneratorType; -use Doctrine\ORM\NotImplementedYet; -use Doctrine\ORM\Sequencing; -use Doctrine\ORM\Sequencing\Planning\AssociationValueGeneratorExecutor; -use Doctrine\ORM\Sequencing\Planning\ColumnValueGeneratorExecutor; -use Doctrine\ORM\Sequencing\Planning\CompositeValueGenerationPlan; -use Doctrine\ORM\Sequencing\Planning\NoopValueGenerationPlan; -use Doctrine\ORM\Sequencing\Planning\SingleValueGenerationPlan; -use Doctrine\ORM\Sequencing\Planning\ValueGenerationExecutor; use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory; use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface; use Doctrine\Persistence\Mapping\Driver\MappingDriver; @@ -43,8 +35,10 @@ use function explode; use function in_array; use function is_subclass_of; +use function strlen; use function strpos; use function strtolower; +use function substr; /** * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the @@ -564,7 +558,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void $sequencePrefix = $class->getSequencePrefix($this->getTargetPlatform()); $sequenceName = $this->getTargetPlatform()->getIdentitySequenceName($sequencePrefix, $columnName); $definition = [ - 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName), + 'sequenceName' => $this->truncateSequenceName($sequenceName), ]; if ($quoted) { @@ -596,7 +590,7 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class): void $quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']); $definition = [ - 'sequenceName' => $this->getTargetPlatform()->fixSchemaElementName($sequenceName), + 'sequenceName' => $this->truncateSequenceName($sequenceName), 'allocationSize' => 1, 'initialValue' => 1, ]; @@ -669,6 +663,22 @@ private function determineIdGeneratorStrategy(AbstractPlatform $platform): int return ClassMetadata::GENERATOR_TYPE_TABLE; } + private function truncateSequenceName(string $schemaElementName): string + { + $platform = $this->getTargetPlatform(); + if (! in_array($platform->getName(), ['oracle', 'sqlanywhere'], true)) { + return $schemaElementName; + } + + $maxIdentifierLength = $platform->getMaxIdentifierLength(); + + if (strlen($schemaElementName) > $maxIdentifierLength) { + return substr($schemaElementName, 0, $maxIdentifierLength); + } + + return $schemaElementName; + } + /** * Inherits the ID generator mapping from a parent class. */ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index eb35ea93ca8..9c9d50a5afe 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -896,11 +896,9 @@ ClassMetadata::GENERATOR_TYPE_UUID - + addNamedNativeQuery addNamedQuery - fixSchemaElementName - fixSchemaElementName ! $class->reflClass diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 86ad9ed72c6..69e9f18cf95 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -13,7 +13,6 @@ use Doctrine\ORM\Events; use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Id\AbstractIdGenerator; -use Doctrine\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\Column; @@ -24,7 +23,6 @@ use Doctrine\ORM\Mapping\Id; use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\Mapping\MappingException; -use Doctrine\ORM\Sequencing\Generator; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\Mapping\RuntimeReflectionService; use Doctrine\Tests\Mocks\ConnectionMock;