fix(db): Replace more Platform usages

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-07-04 08:55:05 +02:00
parent 5718e8fff5
commit f0348be4c8
No known key found for this signature in database
GPG key ID: 74434EFE0D2E2205
18 changed files with 55 additions and 69 deletions

View file

@ -5,7 +5,6 @@
*/
namespace OCA\DAV\Migration;
use Doctrine\DBAL\Platforms\OraclePlatform;
use OCA\DAV\CalDAV\CalDavBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
@ -75,7 +74,7 @@ class CalDAVRemoveEmptyValue implements IRepairStep {
}
protected function getInvalidObjects($pattern) {
if ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
if ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$rows = [];
$chunkSize = 500;
$query = $this->db->getQueryBuilder();

View file

@ -8,7 +8,6 @@ declare(strict_types=1);
*/
namespace OCA\Settings\Tests;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use OCA\Settings\SetupChecks\SupportedDatabase;
use OCP\IDBConnection;
use OCP\IL10N;
@ -41,8 +40,7 @@ class SupportedDatabaseTest extends TestCase {
}
public function testPass(): void {
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SQLitePlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
/** SQlite always gets a warning */
$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
} else {

View file

@ -8,9 +8,9 @@
namespace OCA\User_LDAP\Mapping;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
/**
@ -216,7 +216,7 @@ abstract class AbstractMapping {
public function getListOfIdsByDn(array $fdns): array {
$totalDBParamLimit = 65000;
$sliceSize = 1000;
$maxSlices = $this->dbc->getDatabasePlatform() instanceof SQLitePlatform ? 9 : $totalDBParamLimit / $sliceSize;
$maxSlices = $this->dbc->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE ? 9 : $totalDBParamLimit / $sliceSize;
$results = [];
$slice = 1;

View file

@ -5,11 +5,11 @@
*/
namespace OC\Core\Command\Db;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Types\Type;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -53,7 +53,7 @@ class ConvertFilecacheBigInt extends Command {
protected function execute(InputInterface $input, OutputInterface $output): int {
$schema = new SchemaWrapper($this->connection);
$isSqlite = $this->connection->getDatabasePlatform() instanceof SQLitePlatform;
$isSqlite = $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE;
$updates = [];
$tables = static::getColumnsByTable();

View file

@ -5,7 +5,6 @@
*/
namespace OC\Core\Command\Db;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OC\DB\MySqlTools;
use OC\Migration\ConsoleOutput;
use OC\Repair\Collation;
@ -34,7 +33,7 @@ class ConvertMysqlToMB4 extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_MYSQL) {
$output->writeln("This command is only valid for MySQL/MariaDB databases.");
return 1;
}

View file

@ -6,7 +6,6 @@
*/
namespace OC;
use Doctrine\DBAL\Platforms\OraclePlatform;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
@ -470,7 +469,7 @@ class AllConfig implements IConfig {
$this->fixDIInit();
$qb = $this->connection->getQueryBuilder();
$configValueColumn = ($this->connection->getDatabasePlatform() instanceof OraclePlatform)
$configValueColumn = ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE)
? $qb->expr()->castColumn('configvalue', IQueryBuilder::PARAM_STR)
: 'configvalue';
$result = $qb->select('userid')
@ -509,7 +508,7 @@ class AllConfig implements IConfig {
}
$qb = $this->connection->getQueryBuilder();
$configValueColumn = ($this->connection->getDatabasePlatform() instanceof OraclePlatform)
$configValueColumn = ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE)
? $qb->expr()->castColumn('configvalue', IQueryBuilder::PARAM_STR)
: 'configvalue';

View file

@ -7,7 +7,6 @@
*/
namespace OC\BackgroundJob;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OCP\AppFramework\QueryException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\AutoloadNotAllowedException;
@ -98,7 +97,7 @@ class JobList implements IJobList {
// Add galera safe delete chunking if using mysql
// Stops us hitting wsrep_max_ws_rows when large row counts are deleted
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
// Then use chunked delete
$max = IQueryBuilder::MAX_ROW_DELETION;

View file

@ -18,6 +18,7 @@ use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
@ -27,6 +28,7 @@ use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\Diagnostics\IQueryLogger;
use OCP\IDBConnection;
use OCP\IRequestId;
use OCP\PreConditionNotMetException;
use OCP\Profiler\IProfiler;
@ -715,4 +717,19 @@ class Connection extends PrimaryReadReplicaConnection {
private function getConnectionName(): string {
return $this->isConnectedToPrimary() ? 'primary' : 'replica';
}
public function getDatabaseProvider(): string {
$platform = $this->getDatabasePlatform();
if ($platform instanceof MySQLPlatform) {
return IDBConnection::PLATFORM_MYSQL;
} elseif ($platform instanceof OraclePlatform) {
return IDBConnection::PLATFORM_ORACLE;
} elseif ($platform instanceof PostgreSQLPlatform) {
return IDBConnection::PLATFORM_POSTGRES;
} elseif ($platform instanceof SQLitePlatform) {
return IDBConnection::PLATFORM_SQLITE;
} else {
throw new \Exception('Database ' . $platform::class . ' not supported');
}
}
}

View file

@ -238,18 +238,10 @@ class ConnectionAdapter implements IDBConnection {
return $this->inner;
}
/**
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
*/
public function getDatabaseProvider(): string {
$platform = $this->inner->getDatabasePlatform();
if ($platform instanceof MySQLPlatform) {
return IDBConnection::PLATFORM_MYSQL;
} elseif ($platform instanceof OraclePlatform) {
return IDBConnection::PLATFORM_ORACLE;
} elseif ($platform instanceof PostgreSQLPlatform) {
return IDBConnection::PLATFORM_POSTGRES;
} elseif ($platform instanceof SQLitePlatform) {
return IDBConnection::PLATFORM_SQLITE;
} else {
throw new \Exception('Database ' . $platform::class . ' not supported');
}
return $this->inner->getDatabaseProvider();
}
}

View file

@ -6,8 +6,6 @@
*/
namespace OC\DB;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
@ -20,6 +18,7 @@ use OCP\AppFramework\App;
use OCP\AppFramework\QueryException;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IMigrationStep;
use OCP\Migration\IOutput;
use OCP\Server;
@ -601,7 +600,7 @@ class MigrationService {
$indexName = strtolower($primaryKey->getName());
$isUsingDefaultName = $indexName === 'primary';
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
$defaultName = $table->getName() . '_pkey';
$isUsingDefaultName = strtolower($defaultName) === $indexName;
@ -611,7 +610,7 @@ class MigrationService {
return $sequence->getName() !== $sequenceName;
});
}
} elseif ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
} elseif ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$defaultName = $table->getName() . '_seq';
$isUsingDefaultName = strtolower($defaultName) === $indexName;
}

View file

@ -109,20 +109,12 @@ class QueryBuilder implements IQueryBuilder {
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
*/
public function expr() {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
return new OCIExpressionBuilder($this->connection, $this);
}
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
return new PgSqlExpressionBuilder($this->connection, $this);
}
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
return new MySqlExpressionBuilder($this->connection, $this);
}
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
return new SqliteExpressionBuilder($this->connection, $this);
}
return new ExpressionBuilder($this->connection, $this);
return match($this->connection->getDatabaseProvider()) {
IDBConnection::PLATFORM_ORACLE => new OCIExpressionBuilder($this->connection, $this),
IDBConnection::PLATFORM_POSTGRES => new PgSqlExpressionBuilder($this->connection, $this),
IDBConnection::PLATFORM_MYSQL => new MySqlExpressionBuilder($this->connection, $this),
IDBConnection::PLATFORM_SQLITE => new SqliteExpressionBuilder($this->connection, $this),
};
}
/**

View file

@ -8,7 +8,6 @@
namespace OC\Repair;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
@ -50,7 +49,7 @@ class Collation implements IRepairStep {
* Fix mime types
*/
public function run(IOutput $output) {
if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_MYSQL) {
$output->info('Not a mysql database -> nothing to do');
return;
}

View file

@ -343,7 +343,7 @@ interface IDBConnection {
* Returns the database provider name
* @link https://github.com/nextcloud/server/issues/30877
* @since 28.0.0
* @return IDBConnection::PLATFORM_*
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
*/
public function getDatabaseProvider(): string;
}

View file

@ -8,8 +8,6 @@
namespace Test\DB;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Exception\TableDoesNotExist;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
@ -326,9 +324,9 @@ class MigrationsTest extends \Test\TestCase {
public function testEnsureOracleConstraintsValidWithPrimaryKeyDefault() {
$defaultName = 'PRIMARY';
if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
if ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
$defaultName = \str_repeat('a', 26) . '_' . \str_repeat('b', 30) . '_seq';
} elseif ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
} elseif ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$defaultName = \str_repeat('a', 26) . '_seq';
}
@ -407,9 +405,9 @@ class MigrationsTest extends \Test\TestCase {
$this->expectException(\InvalidArgumentException::class);
$defaultName = 'PRIMARY';
if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
if ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
$defaultName = \str_repeat('a', 27) . '_' . \str_repeat('b', 30) . '_seq';
} elseif ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
} elseif ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
$defaultName = \str_repeat('a', 27) . '_seq';
}

View file

@ -10,8 +10,6 @@ namespace Test\DB;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use OC\DB\Migrator;
@ -21,7 +19,7 @@ use OC\DB\TDoctrineParameterTypeMap;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
use OCP\IDBConnection;
/**
* Class MigratorTest
@ -60,12 +58,10 @@ class MigratorTest extends \Test\TestCase {
}
private function getMigrator(): Migrator {
$platform = $this->connection->getDatabasePlatform();
$random = \OC::$server->get(ISecureRandom::class);
$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
if ($platform instanceof SQLitePlatform) {
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
return new SQLiteMigrator($this->connection, $this->config, $dispatcher);
} elseif ($platform instanceof OraclePlatform) {
} elseif ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
return new OracleMigrator($this->connection, $this->config, $dispatcher);
}
return new Migrator($this->connection, $this->config, $dispatcher);
@ -304,7 +300,7 @@ class MigratorTest extends \Test\TestCase {
$migrator = $this->getMigrator();
$migrator->migrate($startSchema);
if ($oracleThrows && $this->connection->getDatabasePlatform() instanceof OraclePlatform) {
if ($oracleThrows && $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_ORACLE) {
// Oracle can not store false|empty string in notnull columns
$this->expectException(\Doctrine\DBAL\Exception\NotNullConstraintViolationException::class);
}

View file

@ -7,7 +7,7 @@
namespace Test\DB;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
@ -24,7 +24,7 @@ use Doctrine\DBAL\Types\Types;
*/
class OCPostgreSqlPlatformTest extends \Test\TestCase {
public function testAlterBigint() {
$platform = new PostgreSQL100Platform();
$platform = new PostgreSQLPlatform();
$sourceSchema = new Schema();
$targetSchema = new Schema();

View file

@ -7,12 +7,12 @@
namespace Test\Files\Cache;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use OC\Files\Cache\Cache;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Search\ISearchComparison;
use OCP\IDBConnection;
use OCP\IUser;
class LongId extends \OC\Files\Storage\Temporary {
@ -142,7 +142,7 @@ class CacheTest extends \Test\TestCase {
if (strpos($folder, 'F09F9890')) {
// 4 byte UTF doesn't work on mysql
$params = \OC::$server->get(\OC\DB\Connection::class)->getParams();
if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') {
if (\OC::$server->getDatabaseConnection()->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL && $params['charset'] !== 'utf8mb4') {
$this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8');
}
}

View file

@ -7,7 +7,6 @@
namespace Test\Repair;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use OC\Repair\Collation;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
@ -61,7 +60,7 @@ class RepairCollationTest extends TestCase {
$this->connection = \OC::$server->get(IDBConnection::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = \OC::$server->getConfig();
if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_MYSQL) {
$this->markTestSkipped("Test only relevant on MySql");
}