Skip to content

Commit

Permalink
Remove calls to fixSchemaElementName()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander M. Turek <[email protected]>
  • Loading branch information
derrabus committed Aug 22, 2021
1 parent b20743b commit ad9f67c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
30 changes: 20 additions & 10 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
];
Expand Down Expand Up @@ -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.
*/
Expand Down
4 changes: 1 addition & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,9 @@
<DeprecatedConstant occurrences="1">
<code>ClassMetadata::GENERATOR_TYPE_UUID</code>
</DeprecatedConstant>
<DeprecatedMethod occurrences="4">
<DeprecatedMethod occurrences="2">
<code>addNamedNativeQuery</code>
<code>addNamedQuery</code>
<code>fixSchemaElementName</code>
<code>fixSchemaElementName</code>
</DeprecatedMethod>
<DocblockTypeContradiction occurrences="3">
<code>! $class-&gt;reflClass</code>
Expand Down
2 changes: 0 additions & 2 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ad9f67c

Please sign in to comment.