Skip to content

Merge 4.3.x up into 5.0.x #6612

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

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated `AbstractAsset::_setName()`

Setting object name via `AbstractAsset::_setName()` has been deprecated. Pass the name to the `AbstractAsset`
constructor instead.

## Marked `Identifier` class as internal

In order to build SQL identifiers, use `AbstractPlatform::quoteSingleIdentifier()`.
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@

<!-- TODO for PHPUnit 11 -->
<referencedMethod name="PHPUnit\Framework\TestCase::iniSet"/>

<!--
https://github.com/doctrine/dbal/pull/6610
TODO: remove in 5.0.0
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::_setName" />
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
26 changes: 26 additions & 0 deletions src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Schema\Exception\InvalidObjectName;
use Doctrine\DBAL\Schema\Name\Parser;
use Doctrine\DBAL\Schema\Name\Parser\Identifier;
use Doctrine\Deprecations\Deprecation;

use function array_map;
use function count;
Expand Down Expand Up @@ -40,11 +41,36 @@
/** @var list<Identifier> */
private array $identifiers = [];

public function __construct(?string $name = null)
{
if ($name === null) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6610',
'Not passing $name to %s is deprecated.',
__METHOD__,
);

Check warning on line 52 in src/Schema/AbstractAsset.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractAsset.php#L47-L52

Added lines #L47 - L52 were not covered by tests

return;

Check warning on line 54 in src/Schema/AbstractAsset.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractAsset.php#L54

Added line #L54 was not covered by tests
}

$this->_setName($name);
}

/**
* Sets the name of this asset.
*
* @deprecated Use the constructor instead.
*/
protected function _setName(string $name): void
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6610',
'%s is deprecated. Use the constructor instead.',
__METHOD__,
);

if ($name !== '') {
$parser = new Parser();

Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Column extends AbstractAsset
*/
public function __construct(string $name, Type $type, array $options = [])
{
$this->_setName($name);
parent::__construct($name);

$this->setType($type);
$this->setOptions($options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/ForeignKeyConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
string $name = '',
protected array $options = [],
) {
$this->_setName($name);
parent::__construct($name);

$this->_localColumnNames = $this->createIdentifierMap($localColumnNames);
$this->_foreignTableName = new Identifier($foreignTableName);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Identifier extends AbstractAsset
*/
public function __construct(string $identifier, bool $quote = false)
{
$this->_setName($identifier);
parent::__construct($identifier);

if (! $quote || $this->_quoted) {
return;
Expand Down
8 changes: 2 additions & 6 deletions src/Schema/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ public function __construct(
array $flags = [],
private readonly array $options = [],
) {
$isUnique = $isUnique || $isPrimary;
parent::__construct($name ?? '');

if ($name !== null) {
$this->_setName($name);
}

$this->_isUnique = $isUnique;
$this->_isUnique = $isUnique || $isPrimary;
$this->_isPrimary = $isPrimary;

foreach ($columns as $column) {
Expand Down
11 changes: 7 additions & 4 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public function __construct(

$name = $schemaConfig->getName();

if ($name !== null) {
$this->_setName($name);
}
parent::__construct($name ?? '');

foreach ($namespaces as $namespace) {
$this->createNamespace($namespace);
Expand Down Expand Up @@ -290,7 +288,12 @@ public function createTable(string $name): Table
public function renameTable(string $oldName, string $newName): self
{
$table = $this->getTable($oldName);
$table->_setName($newName);

$identifier = new Identifier($newName);

$table->_name = $identifier->_name;
$table->_namespace = $identifier->_namespace;
$table->_quoted = $identifier->_quoted;

$this->dropTable($oldName);
$this->_addTable($table);
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function __construct(
int $initialValue = 1,
protected ?int $cache = null,
) {
$this->_setName($name);
parent::__construct($name);

$this->setAllocationSize($allocationSize);
$this->setInitialValue($initialValue);
}
Expand Down
15 changes: 10 additions & 5 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
throw InvalidTableName::new($name);
}

$this->_setName($name);
parent::__construct($name);

foreach ($columns as $column) {
$this->_addColumn($column);
Expand Down Expand Up @@ -298,10 +298,15 @@ final public function renameColumn(string $oldName, string $newName): Column
));
}

$column = $this->getColumn($oldName);
$column->_setName($newName);
$oldColumn = $this->getColumn($oldName);
$options = $oldColumn->toArray();

unset($options['name'], $options['type']);

$newColumn = new Column($newName, $oldColumn->getType(), $options);

unset($this->_columns[$oldName]);
$this->_addColumn($column);
$this->_addColumn($newColumn);

$this->renameColumnInIndexes($oldName, $newName);
$this->renameColumnInForeignKeyConstraints($oldName, $newName);
Expand All @@ -318,7 +323,7 @@ final public function renameColumn(string $oldName, string $newName): Column
$this->renamedColumns[$newName] = $oldName;
}

return $column;
return $newColumn;
}

/** @param array<string, mixed> $options */
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/UniqueConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(
array $flags = [],
private readonly array $options = [],
) {
$this->_setName($name);
parent::__construct($name);

foreach ($columns as $column) {
$this->addColumn($column);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class View extends AbstractAsset
{
public function __construct(string $name, private readonly string $sql)
{
$this->_setName($name);
parent::__construct($name);
}

public function getSql(): string
Expand Down