mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-12 11:44:08 +02:00
[ticket/17530] Use Doctrine driver middleware instead of 'platform' parameter
PHPBB-17530
This commit is contained in:
41
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_driver.php
Normal file
41
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_driver.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\middleware\oracle;
|
||||
|
||||
use Doctrine\DBAL\Connection as DoctrineConnection;
|
||||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
/**
|
||||
* Oracle Doctrine driver middleware.
|
||||
* Makes use of phpBB's Oracle specific platform.
|
||||
*/
|
||||
class phpbb_oracle_driver extends AbstractDriverMiddleware
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getSchemaManager(DoctrineConnection $conn, AbstractPlatform $platform)
|
||||
{
|
||||
return new phpbb_oracle_schema_manager($conn, $platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function createDatabasePlatformForVersion($version)
|
||||
{
|
||||
return new phpbb_oracle_platform();
|
||||
}
|
||||
}
|
28
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_middleware.php
Normal file
28
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_middleware.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\middleware\oracle;
|
||||
|
||||
use Doctrine\DBAL\Driver;
|
||||
|
||||
/**
|
||||
* Oracle Doctrine middleware.
|
||||
* Makes use of phpBB's Oracle specific platform.
|
||||
*/
|
||||
class phpbb_oracle_middleware implements Driver\Middleware
|
||||
{
|
||||
public function wrap(Driver $driver): Driver
|
||||
{
|
||||
return new phpbb_oracle_driver($driver);
|
||||
}
|
||||
}
|
177
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_platform.php
Normal file
177
phpBB/phpbb/db/middleware/oracle/phpbb_oracle_platform.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\middleware\oracle;
|
||||
|
||||
use Doctrine\DBAL\Platforms\OraclePlatform;
|
||||
use Doctrine\DBAL\Schema\Identifier;
|
||||
use Doctrine\DBAL\Schema\Index;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
/**
|
||||
* Oracle specific schema restrictions for BC.
|
||||
*/
|
||||
class phpbb_oracle_platform extends OraclePlatform
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVarcharTypeDeclarationSQL(array $column): string
|
||||
{
|
||||
if (array_key_exists('length', $column) && is_int($column['length']))
|
||||
{
|
||||
$column['length'] *= 3;
|
||||
}
|
||||
|
||||
return parent::getVarcharTypeDeclarationSQL($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getAsciiStringTypeDeclarationSQL(array $column): string
|
||||
{
|
||||
return parent::getVarcharTypeDeclarationSQL($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getCreateIndexSQL(Index $index, $table): string
|
||||
{
|
||||
if ($table instanceof Table)
|
||||
{
|
||||
$table_name = $table->getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
$table_name = $table;
|
||||
}
|
||||
|
||||
$index_name = $index->getName();
|
||||
if (strpos($index->getName(), $table_name) !== 0)
|
||||
{
|
||||
$index_name = $table_name . '_' . $index->getName();
|
||||
}
|
||||
|
||||
$index = new Index(
|
||||
$this->check_index_name_length($table_name, $index_name),
|
||||
$index->getColumns(),
|
||||
$index->isUnique(),
|
||||
$index->isPrimary(),
|
||||
$index->getFlags(),
|
||||
$index->getOptions()
|
||||
);
|
||||
|
||||
return parent::getCreateIndexSQL($index, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the index name is too long
|
||||
*
|
||||
* @param string $table_name
|
||||
* @param string $index_name
|
||||
* @param bool $throw_error
|
||||
* @return string The index name, shortened if too long
|
||||
*/
|
||||
protected function check_index_name_length(string $table_name, string $index_name, bool $throw_error = true): string
|
||||
{
|
||||
$max_index_name_length = $this->getMaxIdentifierLength();
|
||||
if (strlen($index_name) > $max_index_name_length)
|
||||
{
|
||||
// Try removing the table prefix if it's at the beginning
|
||||
$table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
|
||||
if (strpos($index_name, $table_prefix) === 0)
|
||||
{
|
||||
$index_name = substr($index_name, strlen($table_prefix));
|
||||
return $this->check_index_name_length($table_name, $index_name, $throw_error);
|
||||
}
|
||||
|
||||
// Try removing the remaining suffix part of table name then
|
||||
$table_suffix = substr($table_name, strlen($table_prefix));
|
||||
if (strpos($index_name, $table_suffix) === 0)
|
||||
{
|
||||
// Remove the suffix and underscore separator between table_name and index_name
|
||||
$index_name = substr($index_name, strlen($table_suffix) + 1);
|
||||
return $this->check_index_name_length($table_name, $index_name, $throw_error);
|
||||
}
|
||||
|
||||
if ($throw_error)
|
||||
{
|
||||
throw new \InvalidArgumentException(
|
||||
"Index name '$index_name' on table '$table_name' is too long. The maximum is $max_index_name_length characters."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $index_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIdentitySequenceName($tableName, $columnName): string
|
||||
{
|
||||
return $tableName . '_SEQ';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getCreateAutoincrementSql($name, $table, $start = 1)
|
||||
{
|
||||
$sql = parent::getCreateAutoincrementSql($name, $table, $start);
|
||||
|
||||
return str_replace(
|
||||
$this->get_doctrine_autoincrement_identifier_name($this->doctrine_normalize_identifier($table)),
|
||||
'T_'.$table,
|
||||
$sql
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see OraclePlatform::normalizeIdentifier()
|
||||
*/
|
||||
private function doctrine_normalize_identifier($name): Identifier
|
||||
{
|
||||
$identifier = new Identifier($name);
|
||||
|
||||
return $identifier->isQuoted() ? $identifier : new Identifier(strtoupper($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see OraclePlatform::getAutoincrementIdentifierName()
|
||||
*/
|
||||
private function get_doctrine_autoincrement_identifier_name(Identifier $table): string
|
||||
{
|
||||
$identifierName = $this->add_doctrine_suffix($table->getName(), '_AI_PK');
|
||||
|
||||
return $table->isQuoted()
|
||||
? $this->quoteSingleIdentifier($identifierName)
|
||||
: $identifierName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see OraclePlatform::addSuffix()
|
||||
*/
|
||||
private function add_doctrine_suffix(string $identifier, string $suffix): string
|
||||
{
|
||||
$maxPossibleLengthWithoutSuffix = $this->getMaxIdentifierLength() - strlen($suffix);
|
||||
if (strlen($identifier) > $maxPossibleLengthWithoutSuffix)
|
||||
{
|
||||
$identifier = substr($identifier, 0, $maxPossibleLengthWithoutSuffix);
|
||||
}
|
||||
|
||||
return $identifier . $suffix;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\db\middleware\oracle;
|
||||
|
||||
use Doctrine\DBAL\Platforms\OraclePlatform;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
||||
use Doctrine\DBAL\Schema\OracleSchemaManager;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
|
||||
class phpbb_oracle_schema_manager extends OracleSchemaManager
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Copied from upstream to lowercase 'COMMENTS'
|
||||
*/
|
||||
public function listTableDetails($name): Table
|
||||
{
|
||||
$table = AbstractSchemaManager::listTableDetails($name);
|
||||
|
||||
$platform = $this->_platform;
|
||||
assert($platform instanceof OraclePlatform);
|
||||
$sql = $platform->getListTableCommentsSQL($name);
|
||||
|
||||
$tableOptions = $this->_conn->fetchAssociative($sql);
|
||||
|
||||
if ($tableOptions !== false)
|
||||
{
|
||||
$table->addOption('comment', $tableOptions['comments']);
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user