Skip to content

Commit

Permalink
Merge pull request #5529 from morozov/issues/4798
Browse files Browse the repository at this point in the history
Deprecate passing assets as names
  • Loading branch information
morozov committed Jul 22, 2022
2 parents 27906ec + 6dea08e commit c581ce5
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 27 deletions.
22 changes: 22 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ awareness about deprecated code.

# Upgrade to 3.4

## Deprecated passing asset names as assets in `AbstractPlatform` and `AbstractSchemaManager` methods.

Passing assets to the following `AbstractPlatform` methods and parameters has been deprecated:

1. The `$table` parameter of `getDropTableSQL()`,
2. The `$table` parameter of `getDropTemporaryTableSQL()`,
3. The `$index` and `$table` parameters of `getDropIndexSQL()`,
4. The `$constraint` and `$table` parameters of `getDropConstraintSQL()`,
5. The `$foreignKey` and `$table` parameters of `getDropForeignKeySQL()`,
6. The `$sequence` parameter of `getDropSequenceSQL()`,
7. The `$table` parameter of `getCreateConstraintSQL()`,
8. The `$table` parameter of `getCreatePrimaryKeySQL()`,
9. The `$table` parameter of `getCreateForeignKeySQL()`.

Passing assets to the following `AbstractSchemaManager` methods and parameters has been deprecated:

1. The `$index` and `$table` parameters of `dropIndex()`,
2. The `$table` parameter of `dropConstraint()`,
3. The `$foreignKey` and `$table` parameters of `dropForeignKey()`.

Pass a string representing the quoted asset name instead.

## Marked `AbstractPlatform` methods as internal.

The following methods have been marked internal as they are not designed to be used from outside the platform classes:
Expand Down
23 changes: 22 additions & 1 deletion src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
continue;
}

$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}

return $sql;
Expand Down Expand Up @@ -1050,6 +1050,13 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey
public function getDropIndexSQL($index, $table = null)
{
if ($index instanceof Index) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$indexName = $index->getQuotedName($this);
} elseif (is_string($index)) {
$indexName = $index;
Expand All @@ -1060,6 +1067,13 @@ public function getDropIndexSQL($index, $table = null)
}

if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
} elseif (! is_string($table)) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -1223,6 +1237,13 @@ protected function getReservedKeywordsClass()
public function getDropTemporaryTableSQL($table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
} elseif (! is_string($table)) {
throw new InvalidArgumentException(
Expand Down
109 changes: 101 additions & 8 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,13 @@ public function getDropTableSQL($table)
$tableArg = $table;

if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -1831,6 +1838,17 @@ public function getDropTableSQL($table)
*/
public function getDropTemporaryTableSQL($table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

return $this->getDropTableSQL($table);
}

Expand All @@ -1847,6 +1865,13 @@ public function getDropTemporaryTableSQL($table)
public function getDropIndexSQL($index, $table = null)
{
if ($index instanceof Index) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$index = $index->getQuotedName($this);
} elseif (! is_string($index)) {
throw new InvalidArgumentException(
Expand All @@ -1869,11 +1894,25 @@ public function getDropIndexSQL($index, $table = null)
*/
public function getDropConstraintSQL($constraint, $table)
{
if (! $constraint instanceof Constraint) {
if ($constraint instanceof Constraint) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $constraint as a Constraint object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);
} else {
$constraint = new Identifier($constraint);
}

if (! $table instanceof Table) {
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);
} else {
$table = new Identifier($table);
}

Expand All @@ -1893,11 +1932,26 @@ public function getDropConstraintSQL($constraint, $table)
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
if (! $foreignKey instanceof ForeignKeyConstraint) {
if ($foreignKey instanceof ForeignKeyConstraint) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $foreignKey as a ForeignKeyConstraint object to %s is deprecated.'
. ' Pass it as a quoted name instead.',
__METHOD__
);
} else {
$foreignKey = new Identifier($foreignKey);
}

if (! $table instanceof Table) {
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);
} else {
$table = new Identifier($table);
}

Expand Down Expand Up @@ -2119,7 +2173,7 @@ public function getDropTablesSQL(array $tables): array
}

foreach ($tables as $table) {
$sql[] = $this->getDropTableSQL($table);
$sql[] = $this->getDropTableSQL($table->getQuotedName($this));
}

return $sql;
Expand Down Expand Up @@ -2271,6 +2325,13 @@ public function getDropSequenceSQL($sequence)
}

if ($sequence instanceof Sequence) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $sequence as a Sequence object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$sequence = $sequence->getQuotedName($this);
}

Expand All @@ -2292,6 +2353,13 @@ public function getDropSequenceSQL($sequence)
public function getCreateConstraintSQL(Constraint $constraint, $table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -2336,6 +2404,13 @@ public function getCreateConstraintSQL(Constraint $constraint, $table)
public function getCreateIndexSQL(Index $index, $table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -2390,6 +2465,13 @@ protected function getCreateIndexSQLFlags(Index $index)
public function getCreatePrimaryKeySQL(Index $index, $table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -2485,6 +2567,13 @@ public function quoteSingleIdentifier($str)
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -2631,20 +2720,24 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
$sql = [];
if ($this->supportsForeignKeyConstraints()) {
foreach ($diff->removedForeignKeys as $foreignKey) {
if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this);
}

$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
}

foreach ($diff->changedForeignKeys as $foreignKey) {
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}
}

foreach ($diff->removedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableName);
}

foreach ($diff->changedIndexes as $index) {
$sql[] = $this->getDropIndexSQL($index, $tableName);
$sql[] = $this->getDropIndexSQL($index->getQuotedName($this), $tableName);
}

return $sql;
Expand Down
26 changes: 24 additions & 2 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ public function getBitOrComparisonExpression($value1, $value2)
public function getCreatePrimaryKeySQL(Index $index, $table): string
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
}

Expand Down Expand Up @@ -755,11 +762,26 @@ public function getListTableColumnsSQL($table, $database = null)
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
if (! $foreignKey instanceof ForeignKeyConstraint) {
if ($foreignKey instanceof ForeignKeyConstraint) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $foreignKey as a ForeignKeyConstraint object to %s is deprecated.'
. ' Pass it as a quoted name instead.',
__METHOD__
);
} else {
$foreignKey = new Identifier($foreignKey);
}

if (! $table instanceof Table) {
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);
} else {
$table = new Identifier($table);
}

Expand Down
21 changes: 21 additions & 0 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ public function getDropForeignKeySQL($foreignKey, $table)
public function getDropIndexSQL($index, $table = null)
{
if ($index instanceof Index) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$index = $index->getQuotedName($this);
} elseif (! is_string($index)) {
throw new InvalidArgumentException(
Expand All @@ -261,6 +268,13 @@ public function getDropIndexSQL($index, $table = null)
}

if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as an Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$table = $table->getQuotedName($this);
} elseif (! is_string($table)) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -354,6 +368,13 @@ protected function _getCreateTableSQL($name, array $columns, array $options = []
public function getCreatePrimaryKeySQL(Index $index, $table)
{
if ($table instanceof Table) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $table as a Table object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__
);

$identifier = $table->getQuotedName($this);
} else {
$identifier = $table;
Expand Down

0 comments on commit c581ce5

Please sign in to comment.