[ticket/16741] General fixes

PHPBB3-16741
This commit is contained in:
Tristan Darricau 2021-11-09 02:48:34 +01:00
parent 300e5399f5
commit 6ce708539b
20 changed files with 941 additions and 385 deletions

View file

@ -7,7 +7,6 @@ imports:
- { resource: services_content.yml } - { resource: services_content.yml }
- { resource: services_cron.yml } - { resource: services_cron.yml }
- { resource: services_db.yml } - { resource: services_db.yml }
- { resource: services_doctrine.yml }
- { resource: services_event.yml } - { resource: services_event.yml }
- { resource: services_extensions.yml } - { resource: services_extensions.yml }
- { resource: services_feed.yml } - { resource: services_feed.yml }

View file

@ -7,7 +7,10 @@ services:
dbal.conn.driver: dbal.conn.driver:
synthetic: true synthetic: true
# ----- DB Tools ----- dbal.conn.doctrine:
synthetic: true
# ----- DB Tools -----
dbal.tools.factory: dbal.tools.factory:
class: phpbb\db\tools\factory class: phpbb\db\tools\factory
@ -15,7 +18,7 @@ services:
class: phpbb\db\tools\tools_interface class: phpbb\db\tools\tools_interface
factory: ['@dbal.tools.factory', get] factory: ['@dbal.tools.factory', get]
arguments: arguments:
- '@dbal.conn.driver' - '@dbal.conn.doctrine'
# ----- DB Extractor ----- # ----- DB Extractor -----
dbal.extractor.factory: dbal.extractor.factory:

View file

@ -1,5 +0,0 @@
services:
doctrine.connection:
class: Doctrine\DBAL\Connection
factory: ['phpbb\db\doctrine\connection_factory', 'get_connection']
arguments: ['@config.php']

View file

@ -49,8 +49,15 @@ $classes = $finder->core_path('phpbb/')
->get_classes(); ->get_classes();
$db = new \phpbb\db\driver\sqlite3(); $db = new \phpbb\db\driver\sqlite3();
// The database is not used by db\tools when we generate the schema but it requires a doctrine DBAL object
// which always tries to connect to the database in the constructor. Which means if we want a valid doctrine
// Connection object that is not connected to any database we have to do that.
$ref = new ReflectionClass(\Doctrine\DBAL\Connection::class);
$db_doctrine = $ref->newInstanceWithoutConstructor();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db, true); $db_tools = $factory->get($db_doctrine, true);
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml'); $tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml');
$tables = []; $tables = [];

View file

@ -365,10 +365,7 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false, $
*/ */
function get_tables($db) function get_tables($db)
{ {
$db_tools_factory = new \phpbb\db\tools\factory(); throw new BadFunctionCallException('function removed from phpBB core, use db_tools service instead.');
$db_tools = $db_tools_factory->get($db);
return $db_tools->sql_list_tables();
} }
/** /**

View file

@ -14,6 +14,7 @@
namespace phpbb\convert\controller; namespace phpbb\convert\controller;
use phpbb\cache\driver\driver_interface; use phpbb\cache\driver\driver_interface;
use phpbb\db\doctrine\connection_factory;
use phpbb\exception\http_exception; use phpbb\exception\http_exception;
use phpbb\install\controller\helper; use phpbb\install\controller\helper;
use phpbb\install\helper\container_factory; use phpbb\install\helper\container_factory;
@ -25,6 +26,7 @@ use phpbb\install\helper\navigation\navigation_provider;
use phpbb\language\language; use phpbb\language\language;
use phpbb\request\request_interface; use phpbb\request\request_interface;
use phpbb\template\template; use phpbb\template\template;
use PHPUnit\DbUnit\Database\Connection;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
/** /**
@ -76,6 +78,11 @@ class convertor
*/ */
protected $db; protected $db;
/**
* @var Connection
*/
protected $db_doctrine;
/** /**
* @var install_helper * @var install_helper
*/ */
@ -169,6 +176,7 @@ class convertor
$this->config = $container->get('config'); $this->config = $container->get('config');
$this->config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext); $this->config_php_file = new \phpbb\config_php_file($this->phpbb_root_path, $this->php_ext);
$this->db = $container->get('dbal.conn.driver'); $this->db = $container->get('dbal.conn.driver');
$this->db_doctrine = $container->get('dbal.conn.doctrine');
$this->config_table = $container->get_parameter('tables.config'); $this->config_table = $container->get_parameter('tables.config');
$this->session_keys_table = $container->get_parameter('tables.sessions_keys'); $this->session_keys_table = $container->get_parameter('tables.sessions_keys');
@ -507,11 +515,13 @@ class convertor
/** @var \phpbb\db\driver\driver_interface $src_db */ /** @var \phpbb\db\driver\driver_interface $src_db */
$src_db = new $src_dbms(); $src_db = new $src_dbms();
$src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd, ENT_COMPAT), $src_dbname, $src_dbport, false, true); $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd, ENT_COMPAT), $src_dbname, $src_dbport, false, true);
$src_db_doctrine = connection_factory::get_connection_from_params($src_dbms, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd, ENT_COMPAT), $src_dbname, $src_dbport);
$same_db = false; $same_db = false;
} }
else else
{ {
$src_db = $this->db; $src_db = $this->db;
$src_db_doctrine = $this->db_doctrine;
$same_db = true; $same_db = true;
} }
@ -526,7 +536,7 @@ class convertor
$prefixes = array(); $prefixes = array();
$db_tools_factory = new \phpbb\db\tools\factory(); $db_tools_factory = new \phpbb\db\tools\factory();
$db_tools = $db_tools_factory->get($src_db); $db_tools = $db_tools_factory->get($src_db_doctrine);
$tables_existing = $db_tools->sql_list_tables(); $tables_existing = $db_tools->sql_list_tables();
$tables_existing = array_map('strtolower', $tables_existing); $tables_existing = array_map('strtolower', $tables_existing);
foreach ($tables_existing as $table_name) foreach ($tables_existing as $table_name)

View file

@ -1876,11 +1876,7 @@ function phpbb_check_username_collisions()
function phpbb_convert_timezone($timezone) function phpbb_convert_timezone($timezone)
{ {
global $config, $db, $phpbb_root_path, $phpEx, $table_prefix; return \phpbb\db\migration\data\v310\timezone::convert_phpbb30_timezone($timezone, 0);
$factory = new \phpbb\db\tools\factory();
$timezone_migration = new \phpbb\db\migration\data\v310\timezone($config, $db, $factory->get($db), $phpbb_root_path, $phpEx, $table_prefix);
return $timezone_migration->convert_phpbb30_timezone($timezone, 0);
} }
function phpbb_add_notification_options($user_notify_pm) function phpbb_add_notification_options($user_notify_pm)

View file

@ -97,13 +97,16 @@ class connection_factory
try try
{ {
$connection = DriverManager::getConnection($params); $connection = DriverManager::getConnection($params);
if (!Type::hasType(case_insensitive_string::CASE_INSENSITIVE_STRING))
{
Type::addType(case_insensitive_string::CASE_INSENSITIVE_STRING, case_insensitive_string::class); Type::addType(case_insensitive_string::CASE_INSENSITIVE_STRING, case_insensitive_string::class);
}
$connection->getDatabasePlatform()->registerDoctrineTypeMapping('varchar_ci', case_insensitive_string::CASE_INSENSITIVE_STRING); $connection->getDatabasePlatform()->registerDoctrineTypeMapping('varchar_ci', case_insensitive_string::CASE_INSENSITIVE_STRING);
return $connection; return $connection;
} }
catch (Exception $e) catch (Exception $e)
{ {
throw new runtime_exception('DB_CONNECTION_FAILED'); throw new runtime_exception('DB_CONNECTION_FAILED', [], $e);
} }
} }

View file

@ -14,6 +14,7 @@
namespace phpbb\db\doctrine; namespace phpbb\db\doctrine;
use InvalidArgumentException; use InvalidArgumentException;
use phpbb\db\doctrine\oci8\driver as oci8_driver;
/** /**
* Helper class to generate Doctrine DBAL configuration. * Helper class to generate Doctrine DBAL configuration.
@ -152,9 +153,14 @@ class connection_parameter_factory
'oci8' => [ 'oci8' => [
'charset' => 'UTF8', 'charset' => 'UTF8',
'platform' => new oracle_platform(), 'platform' => new oracle_platform(),
'driverClass' => oci8_driver::class,
], ],
'pdo_pgsql' => [ 'pdo_pgsql' => [
'charset' => 'UTF8', 'charset' => 'UTF8',
'platform' => new postgresql_platform(),
],
'pdo_sqlsrv' => [
'platform' => new sqlsrv_platform(),
], ],
]; ];

View file

@ -27,7 +27,7 @@ class table_helper
public static function convert_column_data(array $column_data, string $dbms_layer): array public static function convert_column_data(array $column_data, string $dbms_layer): array
{ {
$options = self::resolve_dbms_specific_options($column_data, $dbms_layer); $options = self::resolve_dbms_specific_options($column_data, $dbms_layer);
list($type, $opts) = type_converter::convert($column_data[0]); list($type, $opts) = type_converter::convert($column_data[0], $dbms_layer);
$options = array_merge($options, $opts); $options = array_merge($options, $opts);
return [$type, $options]; return [$type, $options];
} }
@ -54,12 +54,19 @@ class table_helper
$doctrine_options['default'] = $column_data[1]; $doctrine_options['default'] = $column_data[1];
$doctrine_options['notnull'] = true; $doctrine_options['notnull'] = true;
} }
else
{
$doctrine_options['notnull'] = false;
}
$non_string_pattern = '/^[a-z]*(?:int|decimal|bool|timestamp)(?::[0-9]+)?$/'; $non_string_pattern = '/^[a-z]*(?:int|decimal|bool|timestamp)(?::[0-9]+)?$/';
if ($dbms_layer === 'oracle' && !preg_match($non_string_pattern, strtolower($column_data[0])) if ($dbms_layer === 'oracle'
&& array_key_exists('default', $doctrine_options[0]) && $doctrine_options[0]['default'] === '') && !preg_match($non_string_pattern, strtolower($column_data[0]))
&& array_key_exists('default', $doctrine_options)
&& $doctrine_options['default'] === '')
{ {
unset($doctrine_options['notnull']); // Not null is true by default and Oracle does not allow empty strings in not null columns
$doctrine_options['notnull'] = false;
} }
if (isset($column_data[2])) if (isset($column_data[2]))

View file

@ -24,6 +24,7 @@ class type_converter
* @var array * @var array
*/ */
private const TYPE_MAP = [ private const TYPE_MAP = [
'INT' => ['integer', []],
'BINT' => ['bigint', []], 'BINT' => ['bigint', []],
'ULINT' => ['integer', ['unsigned' => true]], 'ULINT' => ['integer', ['unsigned' => true]],
'UINT' => ['integer', ['unsigned' => true]], 'UINT' => ['integer', ['unsigned' => true]],
@ -41,8 +42,8 @@ class type_converter
'MTEXT' => ['text', ['length' => ((1 << 24) - 1)]], 'MTEXT' => ['text', ['length' => ((1 << 24) - 1)]],
'MTEXT_UNI' => ['text', ['length' => ((1 << 24) - 1)]], 'MTEXT_UNI' => ['text', ['length' => ((1 << 24) - 1)]],
'TIMESTAMP' => ['integer', ['unsigned' => true]], 'TIMESTAMP' => ['integer', ['unsigned' => true]],
'DECIMAL' => ['integer', ['precision' => 5, 'scale' => 2]], 'DECIMAL' => ['decimal', ['precision' => 5, 'scale' => 2]],
'PDECIMAL' => ['integer', ['precision' => 6, 'scale' => 3]], 'PDECIMAL' => ['decimal', ['precision' => 6, 'scale' => 3]],
'VCHAR_UNI' => ['string', ['length' => 255]], 'VCHAR_UNI' => ['string', ['length' => 255]],
'VCHAR_CI' => ['string_ci', ['length' => 255]], 'VCHAR_CI' => ['string_ci', ['length' => 255]],
'VARBINARY' => ['binary', ['length' => 255]], 'VARBINARY' => ['binary', ['length' => 255]],
@ -55,7 +56,7 @@ class type_converter
* *
* @return array<string, array> Pair of type name and options. * @return array<string, array> Pair of type name and options.
*/ */
public static function convert(string $type): array public static function convert(string $type, string $dbms): array
{ {
if (strpos($type, ':') !== false) if (strpos($type, ':') !== false)
{ {
@ -63,7 +64,7 @@ class type_converter
return self::mapWithLength($typename, (int) $length); return self::mapWithLength($typename, (int) $length);
} }
return self::mapType($type); return self::mapType($type, $dbms);
} }
/** /**
@ -108,13 +109,40 @@ class type_converter
* *
* @return array<string, array> Pair of type name and an array of options. * @return array<string, array> Pair of type name and an array of options.
*/ */
private static function mapType(string $type): array private static function mapType(string $type, string $dbms): array
{ {
if (!in_array($type, self::TYPE_MAP, true)) if (!array_key_exists($type, self::TYPE_MAP))
{ {
throw new \InvalidArgumentException("Database type is undefined."); throw new \InvalidArgumentException("Database type is undefined.");
} }
// Historically, on mssql varbinary fields were stored as varchar.
// For compatibility reasons we have to keep it (because when
// querying the database, mssql does not convert strings to their
// binary representation automatically like the other dbms.
if ($type === 'VARBINARY' && $dbms === 'mssql')
{
return self::TYPE_MAP['VCHAR'];
}
// Historically, on mssql bool fields were stored as integer.
// For compatibility reasons we have to keep it because is
// some queries we are using MIN() to these columns which
// is forbidden by MSSQL for bool (bit) columns.
if ($type === 'BOOL' && $dbms === 'mssql')
{
return self::TYPE_MAP['TINT'];
}
// Historically, on postgres bool fields were stored as integer.
// For compatibility reasons we have to keep it because when
// querying the database, postgres does not convert automatically
// 0 and 1 to their boolean representation like the other dbms.
if ($type === 'BOOL' && $dbms === 'postgresql')
{
return self::TYPE_MAP['TINT'];
}
return self::TYPE_MAP[$type]; return self::TYPE_MAP[$type];
} }
} }

View file

@ -72,7 +72,7 @@ class timezone extends \phpbb\db\migration\migration
foreach ($update_blocks as $timezone => $user_ids) foreach ($update_blocks as $timezone => $user_ids)
{ {
$timezone = explode(':', $timezone); $timezone = explode(':', $timezone);
$converted_timezone = $this->convert_phpbb30_timezone($timezone[0], $timezone[1]); $converted_timezone = static::convert_phpbb30_timezone($timezone[0], $timezone[1]);
$sql = 'UPDATE ' . $this->table_prefix . "users $sql = 'UPDATE ' . $this->table_prefix . "users
SET user_timezone = '" . $this->db->sql_escape($converted_timezone) . "' SET user_timezone = '" . $this->db->sql_escape($converted_timezone) . "'
@ -88,7 +88,7 @@ class timezone extends \phpbb\db\migration\migration
// Update board default timezone // Update board default timezone
$sql = 'UPDATE ' . $this->table_prefix . "config $sql = 'UPDATE ' . $this->table_prefix . "config
SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' SET config_value = '" . static::convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "'
WHERE config_name = 'board_timezone'"; WHERE config_name = 'board_timezone'";
$this->sql_query($sql); $this->sql_query($sql);
} }
@ -101,7 +101,7 @@ class timezone extends \phpbb\db\migration\migration
* @param $dst int Users daylight saving time * @param $dst int Users daylight saving time
* @return string Users new php Timezone which is used since 3.1 * @return string Users new php Timezone which is used since 3.1
*/ */
public function convert_phpbb30_timezone($timezone, $dst) public static function convert_phpbb30_timezone($timezone, $dst)
{ {
$offset = (float) $timezone + (int) $dst; $offset = (float) $timezone + (int) $dst;

File diff suppressed because it is too large Load diff

View file

@ -13,32 +13,18 @@
namespace phpbb\db\tools; namespace phpbb\db\tools;
use Doctrine\DBAL\Connection;
/** /**
* A factory which serves the suitable tools instance for the given dbal * A factory which serves the suitable tools instance for the given dbal
*/ */
class factory class factory
{ {
/** /**
* @param mixed $db_driver * @return tools_interface
* @param bool $return_statements
* @return \phpbb\db\tools\tools_interface
*/ */
public function get($db_driver, $return_statements = false) public function get(Connection $connection, $return_statements = false)
{ {
// @todo: only create the doctrine tools object. return new doctrine($connection, $return_statements);
if ($db_driver instanceof \phpbb\db\driver\mssql_base)
{
return new \phpbb\db\tools\mssql($db_driver, $return_statements);
}
else if ($db_driver instanceof \phpbb\db\driver\postgres)
{
return new \phpbb\db\tools\postgres($db_driver, $return_statements);
}
else if ($db_driver instanceof \phpbb\db\driver\driver_interface)
{
return new \phpbb\db\tools\tools($db_driver, $return_statements);
}
throw new \InvalidArgumentException('Invalid database driver given');
} }
} }

View file

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

View file

@ -1,15 +1,15 @@
<?php <?php
/** /**
* *
* 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\tools; namespace phpbb\db\tools;
@ -40,8 +40,10 @@ interface tools_interface
* *
* *
* @param array $schema_changes * @param array $schema_changes
*
* @return bool|string[]
*/ */
public function perform_schema_changes(array $schema_changes): void; public function perform_schema_changes(array $schema_changes);
/** /**
* Gets a list of tables in the database. * Gets a list of tables in the database.
@ -54,6 +56,7 @@ interface tools_interface
* Check if table exists * Check if table exists
* *
* @param string $table_name The table name to check for * @param string $table_name The table name to check for
*
* @return bool True if table exists, else false * @return bool True if table exists, else false
*/ */
public function sql_table_exists(string $table_name): bool; public function sql_table_exists(string $table_name): bool;
@ -63,22 +66,25 @@ interface tools_interface
* *
* @param string $table_name The table name to create * @param string $table_name The table name to create
* @param array $table_data Array containing table data. * @param array $table_data Array containing table data.
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_create_table(string $table_name, array $table_data): bool; public function sql_create_table(string $table_name, array $table_data);
/** /**
* Drop Table * Drop Table
* *
* @param string $table_name The table name to drop * @param string $table_name The table name to drop
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_table_drop(string $table_name): bool; public function sql_table_drop(string $table_name);
/** /**
* Gets a list of columns of a table. * Gets a list of columns of a table.
* *
* @param string $table_name Table name * @param string $table_name Table name
*
* @return array Array of column names (all lower case) * @return array Array of column names (all lower case)
*/ */
public function sql_list_columns(string $table_name): array; public function sql_list_columns(string $table_name): array;
@ -88,6 +94,7 @@ interface tools_interface
* *
* @param string $table_name Table to check * @param string $table_name Table to check
* @param string $column_name Column to check * @param string $column_name Column to check
*
* @return bool True if column exists, false otherwise * @return bool True if column exists, false otherwise
*/ */
public function sql_column_exists(string $table_name, string $column_name): bool; public function sql_column_exists(string $table_name, string $column_name): bool;
@ -99,9 +106,9 @@ interface tools_interface
* @param string $column_name Name of the column to add * @param string $column_name Name of the column to add
* @param array $column_data Column data * @param array $column_data Column data
* *
* @return bool True if the statements have been executed * @return bool|string[] True if the statements have been executed
*/ */
public function sql_column_add(string $table_name, string $column_name, array $column_data): bool; public function sql_column_add(string $table_name, string $column_name, array $column_data);
/** /**
* Change column type (not name!) * Change column type (not name!)
@ -110,9 +117,9 @@ interface tools_interface
* @param string $column_name Name of the column to modify * @param string $column_name Name of the column to modify
* @param array $column_data Column data * @param array $column_data Column data
* *
* @return bool True if the statements have been executed * @return bool|string[] True if the statements have been executed
*/ */
public function sql_column_change(string $table_name, string $column_name, array $column_data): bool; public function sql_column_change(string $table_name, string $column_name, array $column_data);
/** /**
* Drop column * Drop column
@ -120,9 +127,9 @@ interface tools_interface
* @param string $table_name Table to modify * @param string $table_name Table to modify
* @param string $column_name Name of the column to drop * @param string $column_name Name of the column to drop
* *
* @return bool True if the statements have been executed * @return bool|string[] True if the statements have been executed
*/ */
public function sql_column_remove(string $table_name, string $column_name): bool; public function sql_column_remove(string $table_name, string $column_name);
/** /**
* List all of the indices that belong to a table * List all of the indices that belong to a table
@ -132,6 +139,7 @@ interface tools_interface
* - PRIMARY keys * - PRIMARY keys
* *
* @param string $table_name Table to check * @param string $table_name Table to check
*
* @return array Array with index names * @return array Array with index names
*/ */
public function sql_list_index(string $table_name): array; public function sql_list_index(string $table_name): array;
@ -141,6 +149,7 @@ interface tools_interface
* *
* @param string $table_name Table to check the index at * @param string $table_name Table to check the index at
* @param string $index_name The index name to check * @param string $index_name The index name to check
*
* @return bool True if index exists, else false * @return bool True if index exists, else false
*/ */
public function sql_index_exists(string $table_name, string $index_name): bool; public function sql_index_exists(string $table_name, string $index_name): bool;
@ -151,18 +160,20 @@ interface tools_interface
* @param string $table_name Table to modify * @param string $table_name Table to modify
* @param string $index_name Name of the index to create * @param string $index_name Name of the index to create
* @param string|array $column Either a string with a column name, or an array with columns * @param string|array $column Either a string with a column name, or an array with columns
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_create_index(string $table_name, string $index_name, $column): bool; public function sql_create_index(string $table_name, string $index_name, $column);
/** /**
* Drop Index * Drop Index
* *
* @param string $table_name Table to modify * @param string $table_name Table to modify
* @param string $index_name Name of the index to delete * @param string $index_name Name of the index to delete
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_index_drop(string $table_name, string $index_name): bool; public function sql_index_drop(string $table_name, string $index_name);
/** /**
* Check if a specified index exists in table. * Check if a specified index exists in table.
@ -171,9 +182,10 @@ interface tools_interface
* *
* @param string $table_name Table to check the index at * @param string $table_name Table to check the index at
* @param string $index_name The index name to check * @param string $index_name The index name to check
* @return bool True if index exists, else false *
* @return bool|string[] True if index exists, else false
*/ */
public function sql_unique_index_exists(string $table_name, string $index_name): bool; public function sql_unique_index_exists(string $table_name, string $index_name);
/** /**
* Add unique index * Add unique index
@ -181,16 +193,18 @@ interface tools_interface
* @param string $table_name Table to modify * @param string $table_name Table to modify
* @param string $index_name Name of the unique index to create * @param string $index_name Name of the unique index to create
* @param string|array $column Either a string with a column name, or an array with columns * @param string|array $column Either a string with a column name, or an array with columns
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_create_unique_index(string $table_name, string $index_name, $column): bool; public function sql_create_unique_index(string $table_name, string $index_name, $column);
/** /**
* Add primary key * Add primary key
* *
* @param string $table_name Table to modify * @param string $table_name Table to modify
* @param string|array $column Either a string with a column name, or an array with columns * @param string|array $column Either a string with a column name, or an array with columns
* @return bool True if the statements have been executed *
* @return bool|string[] True if the statements have been executed
*/ */
public function sql_create_primary_key(string $table_name, $column): bool; public function sql_create_primary_key(string $table_name, $column);
} }

View file

@ -13,6 +13,7 @@
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;
@ -55,6 +56,11 @@ class container_builder
*/ */
protected $dbal_connection = null; 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).
* *
@ -587,8 +593,10 @@ class container_builder
false, false,
defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK 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', $this->dbal_connection); $this->container->set('dbal.conn.driver', $this->dbal_connection);
$this->container->set('dbal.conn.doctrine', $this->dbal_connection_doctrine);
} }
} }

View file

@ -13,6 +13,7 @@
namespace phpbb\install\helper; namespace phpbb\install\helper;
use phpbb\db\doctrine\connection_factory;
use phpbb\install\exception\invalid_dbms_exception; use phpbb\install\exception\invalid_dbms_exception;
use phpbb\filesystem\helper as filesystem_helper; use phpbb\filesystem\helper as filesystem_helper;
@ -389,8 +390,9 @@ class database
$temp_prefix . 'users', $temp_prefix . 'users',
); );
$doctrine_db = connection_factory::get_connection_from_params($dbms, $dbhost, $dbuser, $dbpass, $dbname, $dbport);
$db_tools_factory = new \phpbb\db\tools\factory(); $db_tools_factory = new \phpbb\db\tools\factory();
$db_tools = $db_tools_factory->get($db); $db_tools = $db_tools_factory->get($doctrine_db);
$tables = $db_tools->sql_list_tables(); $tables = $db_tools->sql_list_tables();
$tables = array_map('strtolower', $tables); $tables = array_map('strtolower', $tables);
$table_intersect = array_intersect($tables, $table_ary); $table_intersect = array_intersect($tables, $table_ary);

View file

@ -13,6 +13,7 @@
namespace phpbb\install\module\install_database\task; namespace phpbb\install\module\install_database\task;
use phpbb\db\doctrine\connection_factory;
use phpbb\db\driver\driver_interface; use phpbb\db\driver\driver_interface;
use phpbb\db\tools\tools_interface; use phpbb\db\tools\tools_interface;
use phpbb\install\helper\config; use phpbb\install\helper\config;
@ -83,8 +84,17 @@ class add_tables extends task_base
false false
); );
$doctrine_db = connection_factory::get_connection_from_params(
$config->get('dbms'),
$config->get('dbhost'),
$config->get('dbuser'),
$config->get('dbpasswd'),
$config->get('dbname'),
$config->get('dbport')
);
$this->config = $config; $this->config = $config;
$this->db_tools = $factory->get($this->db); $this->db_tools = $factory->get($doctrine_db);
$this->schema_file_path = $phpbb_root_path . 'store/schema.json'; $this->schema_file_path = $phpbb_root_path . 'store/schema.json';
$this->table_prefix = $this->config->get('table_prefix'); $this->table_prefix = $this->config->get('table_prefix');
$this->change_prefix = $this->config->get('change_table_prefix', true); $this->change_prefix = $this->config->get('change_table_prefix', true);

View file

@ -13,6 +13,7 @@
namespace phpbb\install\module\install_database\task; namespace phpbb\install\module\install_database\task;
use phpbb\db\doctrine\connection_factory;
use phpbb\install\exception\resource_limit_reached_exception; use phpbb\install\exception\resource_limit_reached_exception;
/** /**
@ -30,6 +31,11 @@ class create_schema_file extends \phpbb\install\task_base
*/ */
protected $db; protected $db;
/**
* @var \Doctrine\DBAL\Connection
*/
protected $db_doctrine;
/** /**
* @var \phpbb\filesystem\filesystem_interface * @var \phpbb\filesystem\filesystem_interface
*/ */
@ -81,6 +87,15 @@ class create_schema_file extends \phpbb\install\task_base
false false
); );
$this->db_doctrine = connection_factory::get_connection_from_params(
$config->get('dbms'),
$config->get('dbhost'),
$config->get('dbuser'),
$config->get('dbpasswd'),
$config->get('dbname'),
$config->get('dbport')
);
$this->config = $config; $this->config = $config;
$this->filesystem = $filesystem; $this->filesystem = $filesystem;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
@ -129,7 +144,7 @@ class create_schema_file extends \phpbb\install\task_base
$finder = $finder_factory->get(); $finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db, true); $db_tools = $factory->get($this->db_doctrine, true);
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($this->phpbb_root_path . '/config/default/container/tables.yml'); $tables_data = \Symfony\Component\Yaml\Yaml::parseFile($this->phpbb_root_path . '/config/default/container/tables.yml');
$tables = []; $tables = [];
foreach ($tables_data['parameters'] as $parameter => $table) foreach ($tables_data['parameters'] as $parameter => $table)