Skip to content

Commit

Permalink
Address more DBAL 3.2 deprecations (#9256)
Browse files Browse the repository at this point in the history
* Instantiate comparator via the schema manager, if possible

* Do not use AbstractPlatform::getName()
  • Loading branch information
morozov authored Dec 16, 2021
1 parent 003090b commit bea5e71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
private function truncateSequenceName(string $schemaElementName): string
{
$platform = $this->getTargetPlatform();
if (! in_array($platform->getName(), ['oracle', 'sqlanywhere'], true)) {
if (! $platform instanceof Platforms\OraclePlatform && ! $platform instanceof Platforms\SQLAnywherePlatform) {
return $schemaElementName;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,12 @@ public function getUpdateSchemaSql(array $classes, $saveMode = false)
$toSchema = $this->getSchemaFromMetadata($classes);
$fromSchema = $this->createSchemaForComparison($toSchema);

$comparator = new Comparator();
if (method_exists($this->schemaManager, 'createComparator')) {
$comparator = $this->schemaManager->createComparator();
} else {
$comparator = new Comparator();
}

$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

if ($saveMode) {
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
<file name="lib/Doctrine/ORM/QueryBuilder.php"/>
</errorLevel>
</RedundantCastGivenDocblockType>
<RedundantCondition>
<errorLevel type="suppress">
<!-- The SQLAnywherePlatform class may or may not exist depending on the DBAL version -->
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
</errorLevel>
</RedundantCondition>
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
<ReservedWord>
<errorLevel type="suppress">
Expand Down
10 changes: 8 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function array_filter;
use function count;
use function implode;
use function method_exists;
use function strpos;

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

$comparator = new Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
if (method_exists($sm, 'createComparator')) {
$comparator = $sm->createComparator();
} else {
$comparator = new Comparator();
}

$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

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

0 comments on commit bea5e71

Please sign in to comment.