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 8bed630 commit 2226d8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 25 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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 All @@ -57,6 +59,11 @@
*/
class ClassMetadataFactory extends AbstractClassMetadataFactory
{
private const SEQUENCE_NAME_NEEDS_TRUNCATION = [
'oracle' => true,
'sqlanywhere' => true,
];

/** @var EntityManagerInterface|null */
private $em;

Expand Down Expand Up @@ -564,7 +571,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 +603,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 +676,22 @@ private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
return ClassMetadata::GENERATOR_TYPE_TABLE;
}

private function truncateSequenceName(string $schemaElementName): string
{
$platform = $this->getTargetPlatform();
if (! (self::SEQUENCE_NAME_NEEDS_TRUNCATION[$platform->getName()] ?? false)) {
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 @@ -883,11 +883,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

0 comments on commit 2226d8c

Please sign in to comment.