[ticket/16741] Code review fixes

PHPBB3-16741
This commit is contained in:
Máté Bartus 2021-12-05 11:09:16 +01:00
parent b8d555f56a
commit a0584b8677
17 changed files with 112 additions and 125 deletions

View file

@ -8,7 +8,9 @@ services:
synthetic: true synthetic: true
dbal.conn.doctrine: dbal.conn.doctrine:
synthetic: true class: Doctrine\DBAL\Connection
factory: ['phpbb\db\doctrine\connection_factory', 'get_connection']
arguments: ['@config.php']
# ----- DB Tools ----- # ----- DB Tools -----
dbal.tools.factory: dbal.tools.factory:

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -50,7 +50,7 @@ class comparator extends \Doctrine\DBAL\Schema\Comparator
} }
$index_columns = array_map('strtolower', $index->getUnquotedColumns()); $index_columns = array_map('strtolower', $index->getUnquotedColumns());
if (array_search($columnName, $index_columns, true) === false) if (!in_array($columnName, $index_columns, true))
{ {
continue; continue;
} }

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -18,7 +18,7 @@ use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
class Connection implements DriverConnection class connection implements DriverConnection
{ {
/** /**
* @var DriverConnection * @var DriverConnection
@ -68,7 +68,7 @@ class Connection implements DriverConnection
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function lastInsertId($name = null) public function lastInsertId($name = null): ?string
{ {
return $this->wrapped->lastInsertId($name); return $this->wrapped->lastInsertId($name);
} }
@ -76,7 +76,7 @@ class Connection implements DriverConnection
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function beginTransaction() public function beginTransaction(): bool
{ {
return $this->wrapped->beginTransaction(); return $this->wrapped->beginTransaction();
} }
@ -84,7 +84,7 @@ class Connection implements DriverConnection
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function commit() public function commit(): bool
{ {
return $this->wrapped->commit(); return $this->wrapped->commit();
} }
@ -92,7 +92,7 @@ class Connection implements DriverConnection
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function rollBack() public function rollBack(): bool
{ {
return $this->wrapped->rollBack(); return $this->wrapped->rollBack();
} }

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -35,7 +35,7 @@ class statement implements DriverStatement
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING): bool
{ {
return $this->wrapped->bindValue($param, $value, $type); return $this->wrapped->bindValue($param, $value, $type);
} }
@ -43,7 +43,7 @@ class statement implements DriverStatement
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
{ {
return $this->wrapped->bindParam($param, $variable, $type, $length); return $this->wrapped->bindParam($param, $variable, $type, $length);
} }

View file

@ -47,7 +47,7 @@ class oracle_platform extends OraclePlatform
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getCreateIndexSQL(Index $index, $table) public function getCreateIndexSQL(Index $index, $table): string
{ {
if ($table instanceof Table) if ($table instanceof Table)
{ {
@ -79,12 +79,12 @@ class oracle_platform extends OraclePlatform
/** /**
* Check whether the index name is too long * Check whether the index name is too long
* *
* @param string $table_name * @param string $table_name
* @param string $index_name * @param string $index_name
* @param bool $throw_error * @param bool $throw_error
* @return string The index name, shortened if too long * @return string The index name, shortened if too long
*/ */
protected function check_index_name_length($table_name, $index_name, $throw_error = true) protected function check_index_name_length(string $table_name, string $index_name, bool $throw_error = true): string
{ {
$max_index_name_length = $this->getMaxIdentifierLength(); $max_index_name_length = $this->getMaxIdentifierLength();
if (strlen($index_name) > $max_index_name_length) if (strlen($index_name) > $max_index_name_length)
@ -108,7 +108,9 @@ class oracle_platform extends OraclePlatform
if ($throw_error) if ($throw_error)
{ {
trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters.", E_USER_ERROR); throw new \InvalidArgumentException(
"Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters."
);
} }
} }
@ -118,9 +120,9 @@ class oracle_platform extends OraclePlatform
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getIdentitySequenceName($tableName, $columnName) public function getIdentitySequenceName($tableName, $columnName): string
{ {
return $tableName.'_SEQ'; return $tableName . '_SEQ';
} }
/** /**
@ -140,7 +142,7 @@ class oracle_platform extends OraclePlatform
/** /**
* @see OraclePlatform::normalizeIdentifier() * @see OraclePlatform::normalizeIdentifier()
*/ */
private function doctrine_normalize_identifier($name) private function doctrine_normalize_identifier($name): Identifier
{ {
$identifier = new Identifier($name); $identifier = new Identifier($name);
@ -150,7 +152,7 @@ class oracle_platform extends OraclePlatform
/** /**
* @see OraclePlatform::getAutoincrementIdentifierName() * @see OraclePlatform::getAutoincrementIdentifierName()
*/ */
private function get_doctrine_autoincrement_identifier_name(Identifier $table) private function get_doctrine_autoincrement_identifier_name(Identifier $table): string
{ {
$identifierName = $this->add_doctrine_Suffix($table->getName(), '_AI_PK'); $identifierName = $this->add_doctrine_Suffix($table->getName(), '_AI_PK');

View file

@ -95,7 +95,7 @@ class postgresql_platform extends PostgreSQL94Platform
$post_sql = []; $post_sql = [];
foreach ($columns as $column_name => $column) foreach ($columns as $column_name => $column)
{ {
if (! empty($column['autoincrement'])) if (!empty($column['autoincrement']))
{ {
$sequence = new Sequence($this->getIdentitySequenceName($name, $column_name)); $sequence = new Sequence($this->getIdentitySequenceName($name, $column_name));
$sql[] = $this->getCreateSequenceSQL($sequence); $sql[] = $this->getCreateSequenceSQL($sequence);
@ -113,7 +113,8 @@ class postgresql_platform extends PostgreSQL94Platform
} }
/** /**
* @param mixed[] $column * @param array $column
* @return bool
*/ */
private function isSerialColumn(array $column): bool private function isSerialColumn(array $column): bool
{ {
@ -138,7 +139,7 @@ class postgresql_platform extends PostgreSQL94Platform
1 AS increment_by 1 AS increment_by
FROM information_schema.sequences FROM information_schema.sequences
WHERE sequence_schema NOT LIKE 'pg\_%' WHERE sequence_schema NOT LIKE 'pg\_%'
AND sequence_schema != 'information_schema'"; AND sequence_schema <> 'information_schema'";
} }
/** /**

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -37,7 +37,7 @@ class sqlsrv_platform extends SQLServer2012Platform
$this->generate_doctrine_identifier_name($column['name']), $this->generate_doctrine_identifier_name($column['name']),
], [ ], [
$table, $table,
$column['name'].'_1', $column['name'] . '_1',
], ],
$sql); $sql);
} }
@ -70,7 +70,7 @@ class sqlsrv_platform extends SQLServer2012Platform
$phpbb_names[] = $diff->name; $phpbb_names[] = $diff->name;
// NEW Table name if relevant // NEW Table name if relevant
if ($diff->getNewName() != null) if ($diff->getNewName())
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($diff->getNewName()->getName()); $doctrine_names[] = $this->generate_doctrine_identifier_name($diff->getNewName()->getName());
$phpbb_names[] = $diff->getNewName()->getName(); $phpbb_names[] = $diff->getNewName()->getName();
@ -79,30 +79,30 @@ class sqlsrv_platform extends SQLServer2012Platform
foreach ($diff->addedColumns as $column) foreach ($diff->addedColumns as $column)
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this)); $doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1'; $phpbb_names[] = $column->getQuotedName($this) . '_1';
} }
foreach ($diff->removedColumns as $column) foreach ($diff->removedColumns as $column)
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this)); $doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1'; $phpbb_names[] = $column->getQuotedName($this) . '_1';
} }
foreach ($diff->renamedColumns as $column) foreach ($diff->renamedColumns as $column)
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this)); $doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1'; $phpbb_names[] = $column->getQuotedName($this) . '_1';
} }
foreach ($diff->changedColumns as $column) foreach ($diff->changedColumns as $column)
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->column->getQuotedName($this)); $doctrine_names[] = $this->generate_doctrine_identifier_name($column->column->getQuotedName($this));
$phpbb_names[] = $column->column->getQuotedName($this).'_1'; $phpbb_names[] = $column->column->getQuotedName($this) . '_1';
if ($column->oldColumnName != $column->column->getQuotedName($this)) if ($column->oldColumnName != $column->column->getQuotedName($this))
{ {
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->oldColumnName); $doctrine_names[] = $this->generate_doctrine_identifier_name($column->oldColumnName);
$phpbb_names[] = $column->oldColumnName.'_1'; $phpbb_names[] = $column->oldColumnName . '_1';
} }
} }
@ -116,7 +116,7 @@ class sqlsrv_platform extends SQLServer2012Platform
* *
* @return string * @return string
*/ */
private function generate_doctrine_identifier_name($identifier) private function generate_doctrine_identifier_name(string $identifier): string
{ {
// Always generate name for unquoted identifiers to ensure consistency. // Always generate name for unquoted identifiers to ensure consistency.
$identifier = new Identifier($identifier); $identifier = new Identifier($identifier);
@ -132,7 +132,7 @@ class sqlsrv_platform extends SQLServer2012Platform
* *
* @return string * @return string
*/ */
private function generate_doctrine_default_constraint_name($table, $column) private function generate_doctrine_default_constraint_name(string $table, string $column): string
{ {
return 'DF_' . $this->generate_doctrine_identifier_name($table) . '_' . $this->generate_doctrine_identifier_name($column); return 'DF_' . $this->generate_doctrine_identifier_name($table) . '_' . $this->generate_doctrine_identifier_name($column);
} }

View file

@ -4,13 +4,12 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
* *
*/ */
namespace phpbb\db\doctrine; namespace phpbb\db\doctrine;
use InvalidArgumentException; use InvalidArgumentException;

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.
@ -32,7 +32,7 @@ use phpbb\db\doctrine\table_helper;
* In general, it is recommended to use Doctrine directly instead of this class as this * In general, it is recommended to use Doctrine directly instead of this class as this
* implementation is only a BC layer. * implementation is only a BC layer.
*/ */
class doctrine implements tools_interface, tools class doctrine implements tools_interface
{ {
/** /**
* @var AbstractSchemaManager * @var AbstractSchemaManager
@ -181,49 +181,49 @@ class doctrine implements tools_interface, tools
return; return;
} }
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use($schema_changes): void function (Schema $schema) use($schema_changes): void
{ {
$mapping = [ $mapping = [
'drop_tables' => [ 'drop_tables' => [
'method' => '_schema_drop_table', 'method' => 'schema_drop_table',
'use_key' => false, 'use_key' => false,
], ],
'add_tables' => [ 'add_tables' => [
'method' => '_schema_create_table', 'method' => 'schema_create_table',
'use_key' => true, 'use_key' => true,
], ],
'change_columns' => [ 'change_columns' => [
'method' => '_schema_column_change_add', 'method' => 'schema_column_change_add',
'use_key' => true, 'use_key' => true,
'per_table' => true, 'per_table' => true,
], ],
'add_columns' => [ 'add_columns' => [
'method' => '_schema_column_add', 'method' => 'schema_column_add',
'use_key' => true, 'use_key' => true,
'per_table' => true, 'per_table' => true,
], ],
'drop_columns' => [ 'drop_columns' => [
'method' => '_schema_column_remove', 'method' => 'schema_column_remove',
'use_key' => false, 'use_key' => false,
'per_table' => true, 'per_table' => true,
], ],
'drop_keys' => [ 'drop_keys' => [
'method' => '_schema_index_drop', 'method' => 'schema_index_drop',
'use_key' => false, 'use_key' => false,
'per_table' => true, 'per_table' => true,
], ],
'add_primary_keys' => [ 'add_primary_keys' => [
'method' => '_schema_create_primary_key', 'method' => 'schema_create_primary_key',
'use_key' => true, 'use_key' => true,
], ],
'add_unique_index' => [ 'add_unique_index' => [
'method' => '_schema_create_unique_index', 'method' => 'schema_create_unique_index',
'use_key' => true, 'use_key' => true,
'per_table' => true, 'per_table' => true,
], ],
'add_index' => [ 'add_index' => [
'method' => '_schema_create_index', 'method' => 'schema_create_index',
'use_key' => true, 'use_key' => true,
'per_table' => true, 'per_table' => true,
], ],
@ -233,12 +233,10 @@ class doctrine implements tools_interface, tools
{ {
if (array_key_exists($action, $schema_changes)) if (array_key_exists($action, $schema_changes))
{ {
foreach ($schema_changes[$action] as $key => $data) foreach ($schema_changes[$action] as $table_name => $table_data)
{ {
if (array_key_exists('per_table', $params) && $params['per_table']) if (array_key_exists('per_table', $params) && $params['per_table'])
{ {
$table_name = $key;
$table_data = $data;
foreach ($table_data as $key => $data) foreach ($table_data as $key => $data)
{ {
if ($params['use_key'] == false) if ($params['use_key'] == false)
@ -255,11 +253,11 @@ class doctrine implements tools_interface, tools
{ {
if ($params['use_key'] == false) if ($params['use_key'] == false)
{ {
$this->{$params['method']}($schema, $data, true); $this->{$params['method']}($schema, $table_data, true);
} }
else else
{ {
$this->{$params['method']}($schema, $key, $data, true); $this->{$params['method']}($schema, $table_name, $table_data, true);
} }
} }
} }
@ -274,10 +272,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_create_table(string $table_name, array $table_data) public function sql_create_table(string $table_name, array $table_data)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $table_data): void function (Schema $schema) use ($table_name, $table_data): void
{ {
$this->_schema_create_table($schema, $table_name, $table_data, true); $this->schema_create_table($schema, $table_name, $table_data, true);
} }
); );
} }
@ -287,10 +285,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_table_drop(string $table_name) public function sql_table_drop(string $table_name)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name): void function (Schema $schema) use ($table_name): void
{ {
$this->_schema_drop_table($schema, $table_name, true); $this->schema_drop_table($schema, $table_name, true);
} }
); );
} }
@ -300,10 +298,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_column_add(string $table_name, string $column_name, array $column_data) public function sql_column_add(string $table_name, string $column_name, array $column_data)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name, $column_data): void function (Schema $schema) use ($table_name, $column_name, $column_data): void
{ {
$this->_schema_column_add($schema, $table_name, $column_name, $column_data); $this->schema_column_add($schema, $table_name, $column_name, $column_data);
} }
); );
} }
@ -313,10 +311,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_column_change(string $table_name, string $column_name, array $column_data) public function sql_column_change(string $table_name, string $column_name, array $column_data)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name, $column_data): void function (Schema $schema) use ($table_name, $column_name, $column_data): void
{ {
$this->_schema_column_change($schema, $table_name, $column_name, $column_data); $this->schema_column_change($schema, $table_name, $column_name, $column_data);
} }
); );
} }
@ -326,10 +324,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_column_remove(string $table_name, string $column_name) public function sql_column_remove(string $table_name, string $column_name)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $column_name): void function (Schema $schema) use ($table_name, $column_name): void
{ {
$this->_schema_column_remove($schema, $table_name, $column_name); $this->schema_column_remove($schema, $table_name, $column_name);
} }
); );
} }
@ -339,10 +337,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_create_index(string $table_name, string $index_name, $column) public function sql_create_index(string $table_name, string $index_name, $column)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $index_name, $column): void function (Schema $schema) use ($table_name, $index_name, $column): void
{ {
$this->_schema_create_index($column, $schema, $table_name, $index_name); $this->schema_create_index($column, $schema, $table_name, $index_name);
} }
); );
} }
@ -352,10 +350,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_index_drop(string $table_name, string $index_name) public function sql_index_drop(string $table_name, string $index_name)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $index_name): void function (Schema $schema) use ($table_name, $index_name): void
{ {
$this->_schema_index_drop($schema, $table_name, $index_name); $this->schema_index_drop($schema, $table_name, $index_name);
} }
); );
} }
@ -365,10 +363,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_create_unique_index(string $table_name, string $index_name, $column) public function sql_create_unique_index(string $table_name, string $index_name, $column)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $index_name, $column): void function (Schema $schema) use ($table_name, $index_name, $column): void
{ {
$this->_schema_create_unique_index($column, $schema, $table_name, $index_name); $this->schema_create_unique_index($column, $schema, $table_name, $index_name);
} }
); );
} }
@ -378,10 +376,10 @@ class doctrine implements tools_interface, tools
*/ */
public function sql_create_primary_key(string $table_name, $column) public function sql_create_primary_key(string $table_name, $column)
{ {
return $this->_alter_schema( return $this->alter_schema(
function (Schema $schema) use ($table_name, $column): void function (Schema $schema) use ($table_name, $column): void
{ {
$this->_schema_create_primary_key($schema, $column, $table_name); $this->schema_create_primary_key($schema, $column, $table_name);
} }
); );
} }
@ -458,7 +456,7 @@ class doctrine implements tools_interface, tools
* *
* @return bool|string[] * @return bool|string[]
*/ */
protected function _alter_schema(callable $callback) protected function alter_schema(callable $callback)
{ {
try try
{ {
@ -514,7 +512,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_create_table(Schema $schema, string $table_name, array $table_data, bool $safe_check = false): void protected function schema_create_table(Schema $schema, string $table_name, array $table_data, bool $safe_check = false): void
{ {
if ($safe_check && $this->sql_table_exists($table_name)) if ($safe_check && $this->sql_table_exists($table_name))
{ {
@ -585,7 +583,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_drop_table(Schema $schema, string $table_name, bool $safe_check = false): void protected function schema_drop_table(Schema $schema, string $table_name, bool $safe_check = false): void
{ {
if ($safe_check && !$schema->hasTable($table_name)) if ($safe_check && !$schema->hasTable($table_name))
{ {
@ -604,7 +602,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_column_add(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void protected function schema_column_add(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void
{ {
$this->alter_table( $this->alter_table(
$schema, $schema,
@ -634,7 +632,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_column_change(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void protected function schema_column_change(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void
{ {
$this->alter_table( $this->alter_table(
$schema, $schema,
@ -659,7 +657,7 @@ class doctrine implements tools_interface, tools
$index_columns = array_map('strtolower', $index->getUnquotedColumns()); $index_columns = array_map('strtolower', $index->getUnquotedColumns());
if (array_search($column_name, $index_columns, true) !== false) if (array_search($column_name, $index_columns, true) !== false)
{ {
$this->_recreate_index($table, $index, $index_columns); $this->recreate_index($table, $index, $index_columns);
} }
} }
} }
@ -675,16 +673,16 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_column_change_add(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void protected function schema_column_change_add(Schema $schema, string $table_name, string $column_name, array $column_data, bool $safe_check = false): void
{ {
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
if ($table->hasColumn($column_name)) if ($table->hasColumn($column_name))
{ {
$this->_schema_column_change($schema, $table_name, $column_name, $column_data, $safe_check); $this->schema_column_change($schema, $table_name, $column_name, $column_data, $safe_check);
} }
else else
{ {
$this->_schema_column_add($schema, $table_name, $column_name, $column_data, $safe_check); $this->schema_column_add($schema, $table_name, $column_name, $column_data, $safe_check);
} }
} }
@ -696,7 +694,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_column_remove(Schema $schema, string $table_name, string $column_name, bool $safe_check = false): void protected function schema_column_remove(Schema $schema, string $table_name, string $column_name, bool $safe_check = false): void
{ {
$this->alter_table( $this->alter_table(
$schema, $schema,
@ -731,7 +729,7 @@ class doctrine implements tools_interface, tools
if ($key !== false) if ($key !== false)
{ {
unset($index_columns[$key]); unset($index_columns[$key]);
$this->_recreate_index($table, $index, $index_columns); $this->recreate_index($table, $index, $index_columns);
} }
} }
$table->dropColumn($column_name); $table->dropColumn($column_name);
@ -748,7 +746,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_create_index($column, Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void protected function schema_create_index($column, Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void
{ {
$columns = (is_array($column)) ? $column : [$column]; $columns = (is_array($column)) ? $column : [$column];
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
@ -770,7 +768,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_create_unique_index($column, Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void protected function schema_create_unique_index($column, Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void
{ {
$columns = (is_array($column)) ? $column : [$column]; $columns = (is_array($column)) ? $column : [$column];
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
@ -791,7 +789,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_index_drop(Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void protected function schema_index_drop(Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void
{ {
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
@ -811,7 +809,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _schema_create_primary_key(Schema $schema, $column, string $table_name, bool $safe_check = false): void protected function schema_create_primary_key(Schema $schema, $column, string $table_name, bool $safe_check = false): void
{ {
$columns = (is_array($column)) ? $column : [$column]; $columns = (is_array($column)) ? $column : [$column];
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
@ -828,7 +826,7 @@ class doctrine implements tools_interface, tools
* *
* @throws SchemaException * @throws SchemaException
*/ */
protected function _recreate_index(Table $table, Index $index, array $new_columns): void protected function recreate_index(Table $table, Index $index, array $new_columns): void
{ {
if ($index->isPrimary()) if ($index->isPrimary())
{ {

View file

@ -19,6 +19,6 @@ namespace phpbb\db\tools;
* *
* @deprecated 4.0.0-a1 * @deprecated 4.0.0-a1
*/ */
interface tools extends tools_interface class tools extends doctrine
{ {
} }

View file

@ -4,7 +4,7 @@
* This file is part of the phpBB Forum Software package. * This file is part of the phpBB Forum Software package.
* *
* @copyright (c) phpBB Limited <https://www.phpbb.com> * @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0) * @license GNU General Public License, version 2 (GPL-2.0)
* *
* For full copyright and license information, please see * For full copyright and license information, please see
* the docs/CREDITS.txt file. * the docs/CREDITS.txt file.

View file

@ -13,7 +13,6 @@
namespace phpbb\di; namespace phpbb\di;
use phpbb\db\doctrine\connection_factory;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
@ -51,16 +50,6 @@ class container_builder
*/ */
protected $container; protected $container;
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $dbal_connection = null;
/**
* @var \Doctrine\DBAL\Connection
*/
private $dbal_connection_doctrine;
/** /**
* Indicates whether extensions should be used (default to true). * Indicates whether extensions should be used (default to true).
* *
@ -579,24 +568,20 @@ class container_builder
$config_data = $this->config_php_file->get_all(); $config_data = $this->config_php_file->get_all();
if (!empty($config_data)) if (!empty($config_data))
{ {
if ($this->dbal_connection === null) $dbal_driver_class = \phpbb\config_php_file::convert_30_dbms_to_31($this->config_php_file->get('dbms'));
{ /** @var \phpbb\db\driver\driver_interface $dbal_connection */
$dbal_driver_class = \phpbb\config_php_file::convert_30_dbms_to_31($this->config_php_file->get('dbms')); $dbal_connection = new $dbal_driver_class();
/** @var \phpbb\db\driver\driver_interface $dbal_connection */ $dbal_connection->sql_connect(
$this->dbal_connection = new $dbal_driver_class(); $this->config_php_file->get('dbhost'),
$this->dbal_connection->sql_connect( $this->config_php_file->get('dbuser'),
$this->config_php_file->get('dbhost'), $this->config_php_file->get('dbpasswd'),
$this->config_php_file->get('dbuser'), $this->config_php_file->get('dbname'),
$this->config_php_file->get('dbpasswd'), $this->config_php_file->get('dbport'),
$this->config_php_file->get('dbname'), false,
$this->config_php_file->get('dbport'), defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK
false, );
defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK //$this->dbal_connection_doctrine = connection_factory::get_connection($this->config_php_file);
); $this->container->set('dbal.conn.driver', $dbal_connection);
$this->dbal_connection_doctrine = connection_factory::get_connection($this->config_php_file);
}
$this->container->set('dbal.conn.driver', $this->dbal_connection);
$this->container->set('dbal.conn.doctrine', $this->dbal_connection_doctrine);
} }
} }

View file

@ -386,7 +386,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_perform_schema_changes_drop_columns() public function test_perform_schema_changes_drop_columns()
{ {
$db_tools = $this->getMockBuilder('\phpbb\db\tools\doctrine') $db_tools = $this->getMockBuilder('\phpbb\db\tools\doctrine')
->onlyMethods(array('sql_column_exists', '_schema_column_remove')) ->onlyMethods(array('sql_column_exists', 'schema_column_remove'))
->setConstructorArgs(array($this->doctrine_db)) ->setConstructorArgs(array($this->doctrine_db))
->getMock(); ->getMock();
@ -397,7 +397,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
->will($this->returnValue(true)); ->will($this->returnValue(true));
// drop columns // drop columns
$db_tools->expects($this->exactly(2))->method('_schema_column_remove') $db_tools->expects($this->exactly(2))->method('schema_column_remove')
->withConsecutive( ->withConsecutive(
[$this->isInstanceOf(Schema::class), 'existing_table', 'dropped_column_1', true], [$this->isInstanceOf(Schema::class), 'existing_table', 'dropped_column_1', true],
[$this->isInstanceOf(Schema::class), 'existing_table', 'dropped_column_2', true] [$this->isInstanceOf(Schema::class), 'existing_table', 'dropped_column_2', true]