Skip to content

Commit bea5e71

Browse files
authored
Address more DBAL 3.2 deprecations (#9256)
* Instantiate comparator via the schema manager, if possible * Do not use AbstractPlatform::getName()
1 parent 003090b commit bea5e71

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
666666
private function truncateSequenceName(string $schemaElementName): string
667667
{
668668
$platform = $this->getTargetPlatform();
669-
if (! in_array($platform->getName(), ['oracle', 'sqlanywhere'], true)) {
669+
if (! $platform instanceof Platforms\OraclePlatform && ! $platform instanceof Platforms\SQLAnywherePlatform) {
670670
return $schemaElementName;
671671
}
672672

lib/Doctrine/ORM/Tools/SchemaTool.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,12 @@ public function getUpdateSchemaSql(array $classes, $saveMode = false)
930930
$toSchema = $this->getSchemaFromMetadata($classes);
931931
$fromSchema = $this->createSchemaForComparison($toSchema);
932932

933-
$comparator = new Comparator();
933+
if (method_exists($this->schemaManager, 'createComparator')) {
934+
$comparator = $this->schemaManager->createComparator();
935+
} else {
936+
$comparator = new Comparator();
937+
}
938+
934939
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
935940

936941
if ($saveMode) {

psalm.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@
9696
<file name="lib/Doctrine/ORM/QueryBuilder.php"/>
9797
</errorLevel>
9898
</RedundantCastGivenDocblockType>
99+
<RedundantCondition>
100+
<errorLevel type="suppress">
101+
<!-- The SQLAnywherePlatform class may or may not exist depending on the DBAL version -->
102+
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
103+
</errorLevel>
104+
</RedundantCondition>
99105
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
100106
<ReservedWord>
101107
<errorLevel type="suppress">

tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function array_filter;
1515
use function count;
1616
use function implode;
17+
use function method_exists;
1718
use function strpos;
1819

1920
use const PHP_EOL;
@@ -96,8 +97,13 @@ public function assertCreatedSchemaNeedsNoUpdates($classes): void
9697
$fromSchema = $sm->createSchema();
9798
$toSchema = $this->schemaTool->getSchemaFromMetadata($classMetadata);
9899

99-
$comparator = new Comparator();
100-
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
100+
if (method_exists($sm, 'createComparator')) {
101+
$comparator = $sm->createComparator();
102+
} else {
103+
$comparator = new Comparator();
104+
}
105+
106+
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
101107

102108
$sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
103109
$sql = array_filter($sql, static function ($sql) {

0 commit comments

Comments
 (0)