-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address deprecations from doctrine/dbal #11809
base: 3.3.x
Are you sure you want to change the base?
Changes from all commits
939394d
2cdebdd
de2eb07
da457c8
f8fc8ec
a6dacb1
593210a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||
<?php | ||||
|
||||
declare(strict_types=1); | ||||
|
||||
namespace Doctrine\ORM\DbalCompatibility; | ||||
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||||
use Doctrine\DBAL\Schema\ForeignKeyConstraint; | ||||
|
||||
use function method_exists; | ||||
|
||||
/** @internal */ | ||||
final readonly class ForeignKey | ||||
{ | ||||
public function __construct(private ForeignKeyConstraint $foreignKey) | ||||
{ | ||||
} | ||||
|
||||
/** @return array<string> */ | ||||
public function getReferencingColumns(AbstractPlatform $platform): array | ||||
{ | ||||
if (! method_exists($this->foreignKey, 'getReferencingColumns')) { | ||||
Check failure on line 22 in src/DbalCompatibility/ForeignKey.php
|
||||
return $this->foreignKey->getLocalColumns(); | ||||
Check failure on line 23 in src/DbalCompatibility/ForeignKey.php
|
||||
} | ||||
|
||||
$namesAsStrings = []; | ||||
|
||||
foreach ($this->foreignKey->getReferencingColumnNames() as $name) { | ||||
$namesAsStrings[] = $name->toSQL($platform); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I maybe be using orm/src/Mapping/Driver/DatabaseDriver.php Line 210 in cf39e00
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to represent names as strings for compatibility with DBAL 4, then |
||||
} | ||||
|
||||
return $namesAsStrings; | ||||
} | ||||
|
||||
/** @return array<string> */ | ||||
public function getReferencedColumns(AbstractPlatform $platform): array | ||||
{ | ||||
if (! method_exists($this->foreignKey, 'getReferencedColumns')) { | ||||
Check failure on line 38 in src/DbalCompatibility/ForeignKey.php
|
||||
return $this->foreignKey->getForeignColumns(); | ||||
Check failure on line 39 in src/DbalCompatibility/ForeignKey.php
|
||||
} | ||||
|
||||
$namesAsStrings = []; | ||||
|
||||
foreach ($this->foreignKey->getReferencedColumnNames() as $name) { | ||||
$namesAsStrings[] = $name->toSQL($platform); | ||||
} | ||||
|
||||
return $namesAsStrings; | ||||
} | ||||
|
||||
public function getReferencedTableName(AbstractPlatform $platform): string | ||||
{ | ||||
if (! method_exists($this->foreignKey, 'getReferencedTableName')) { | ||||
Check failure on line 53 in src/DbalCompatibility/ForeignKey.php
|
||||
return $this->foreignKey->getForeignTableName(); | ||||
Check failure on line 54 in src/DbalCompatibility/ForeignKey.php
|
||||
} | ||||
|
||||
return $this->foreignKey->getReferencedTableName()->toSQL($platform); | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\DbalCompatibility; | ||
|
||
use Doctrine\DBAL\Schema\ForeignKeyConstraint; | ||
use Doctrine\DBAL\Schema\Table as DoctrineTable; | ||
|
||
use function array_map; | ||
|
||
/** @internal */ | ||
final readonly class Table | ||
{ | ||
public function __construct(private DoctrineTable $table) | ||
{ | ||
} | ||
|
||
/** @return array<string, ForeignKey> */ | ||
public function getForeignKeys(): array | ||
{ | ||
return array_map( | ||
static fn (ForeignKeyConstraint $foreignKey) => new ForeignKey($foreignKey), | ||
$this->table->getForeignKeys(), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use Doctrine\DBAL\Schema\Index; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\ORM\DbalCompatibility\Table as CompatibilityTable; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Mapping\AssociationMapping; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
|
@@ -37,6 +38,7 @@ | |
use function implode; | ||
use function in_array; | ||
use function is_numeric; | ||
use function method_exists; | ||
use function strtolower; | ||
|
||
/** | ||
|
@@ -723,13 +725,16 @@ | |
&& ($foreignTableName !== $addedFks[$compositeName]['foreignTableName'] | ||
|| 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns']))) | ||
) { | ||
foreach ($theJoinTable->getForeignKeys() as $fkName => $key) { | ||
$theCompatibilityTable = new CompatibilityTable($theJoinTable); | ||
foreach ($theCompatibilityTable->getForeignKeys() as $fkName => $key) { | ||
if ( | ||
count(array_diff($key->getLocalColumns(), $localColumns)) === 0 | ||
&& (($key->getForeignTableName() !== $foreignTableName) | ||
|| 0 < count(array_diff($key->getForeignColumns(), $foreignColumns))) | ||
count(array_diff($key->getReferencingColumns($this->platform), $localColumns)) === 0 | ||
&& (($key->getReferencedTableName($this->platform) !== $foreignTableName) | ||
|| 0 < count(array_diff($key->getReferencedColumns($this->platform), $foreignColumns))) | ||
) { | ||
$theJoinTable->removeForeignKey($fkName); | ||
method_exists($theJoinTable, 'dropForeignKey') | ||
? $theJoinTable->dropForeignKey($fkName) | ||
: $theJoinTable->removeForeignKey($fkName); | ||
Check failure on line 737 in src/Tools/SchemaTool.php
|
||
break; | ||
} | ||
} | ||
|
@@ -739,8 +744,8 @@ | |
$addedFks[$compositeName] = ['foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns]; | ||
$theJoinTable->addForeignKeyConstraint( | ||
$foreignTableName, | ||
$localColumns, | ||
Check failure on line 747 in src/Tools/SchemaTool.php
|
||
$foreignColumns, | ||
Check failure on line 748 in src/Tools/SchemaTool.php
|
||
$fkOptions, | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@morozov am I on the right track with this? It seems a bit complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, you want to create wrapper classes that will expose some unified interface for DBAL 4 and 5. That looks about right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a second thought, is it really necessary for ORM to support DBAL 4.2.x and 5.x? If it bumps DBAL requirement to 4.3.x, then it can switch to the new API without the need to implement the wrapers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue isn't that 4.2.x needs to be supported (otherwise indeed I would bump), the issue is that 3.x needs to be supported 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's something fundamentally wrong with this requirement.
DBAL deprecates its old APIs and provides a forward compatibility layer exactly in order to help its consumers migrate from one major release to the other (two in total) w/o building any compatibility layers themselves. ORM, on the other hand, aims at supporting 3 major DBAL releases (3 through 5) and thus has to maintain its own compatibility layer.
Maybe instead of building a compatibility layer, this effort could be spent on dropping support for DBAL 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that @derrabus has done this: #11216
@derrabus should it be backported or what?