aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-07-01 16:59:47 +0200
committerJoas Schilling <coding@schilljs.com>2024-07-19 11:21:14 +0200
commit829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d (patch)
tree5641e35ffe42897566f58acb1d71a0d9afba4729 /lib
parentbd383627a7ef3cb0a8e608b35de067d341f46da4 (diff)
downloadnextcloud-server-829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d.tar.gz
nextcloud-server-829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d.zip
fix(db): Promote the use of `getDatabaseProvider` to reduce the impage of removed upstream platforms
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/AllConfig.php5
-rw-r--r--lib/private/BackgroundJob/JobList.php3
-rw-r--r--lib/private/DB/Connection.php20
-rw-r--r--lib/private/DB/ConnectionAdapter.php20
-rw-r--r--lib/private/DB/MigrationService.php9
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php42
-rw-r--r--lib/private/Repair/Collation.php3
-rw-r--r--lib/public/IDBConnection.php3
8 files changed, 46 insertions, 59 deletions
diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php
index d05fe440202..58eee772fbf 100644
--- a/lib/private/AllConfig.php
+++ b/lib/private/AllConfig.php
@@ -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';
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php
index 201263320e3..5aaf14d62e7 100644
--- a/lib/private/BackgroundJob/JobList.php
+++ b/lib/private/BackgroundJob/JobList.php
@@ -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;
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index c24754a52bd..7aa3a020113 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\ConnectionLost;
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;
@@ -25,6 +26,7 @@ use OC\DB\QueryBuilder\QueryBuilder;
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
+use OCP\IDBConnection;
use OCP\IRequestId;
use OCP\PreConditionNotMetException;
use OCP\Profiler\IProfiler;
@@ -729,4 +731,22 @@ class Connection extends PrimaryReadReplicaConnection {
private function getConnectionName(): string {
return $this->isConnectedToPrimary() ? 'primary' : 'replica';
}
+
+ /**
+ * @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE
+ */
+ 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');
+ }
+ }
}
diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php
index 86a901a7de3..8a919696eaa 100644
--- a/lib/private/DB/ConnectionAdapter.php
+++ b/lib/private/DB/ConnectionAdapter.php
@@ -10,10 +10,6 @@ namespace OC\DB;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\OraclePlatform;
-use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
-use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema;
use OC\DB\Exceptions\DbalException;
use OCP\DB\IPreparedStatement;
@@ -230,18 +226,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();
}
}
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 19d1b240736..0a3b0d1dcc7 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -6,20 +6,19 @@
*/
namespace OC\DB;
-use Doctrine\DBAL\Platforms\OraclePlatform;
-use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
-use Doctrine\DBAL\Types\Types;
use OC\App\InfoParser;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\Migration\SimpleOutput;
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;
@@ -599,7 +598,7 @@ class MigrationService {
$indexName = strtolower($primaryKey->getName());
$isUsingDefaultName = $indexName === 'primary';
- if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) {
+ if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_POSTGRES) {
$defaultName = $table->getName() . '_pkey';
$isUsingDefaultName = strtolower($defaultName) === $indexName;
@@ -609,7 +608,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;
}
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index 81d8b1e7a1a..529b88199e6 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -7,14 +7,9 @@
*/
namespace OC\DB\QueryBuilder;
-use Doctrine\DBAL\Platforms\MySQLPlatform;
-use Doctrine\DBAL\Platforms\OraclePlatform;
-use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
-use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Query\QueryException;
use OC\DB\ConnectionAdapter;
use OC\DB\Exceptions\DbalException;
-use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\MySqlExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\OCIExpressionBuilder;
use OC\DB\QueryBuilder\ExpressionBuilder\PgSqlExpressionBuilder;
@@ -96,20 +91,12 @@ class QueryBuilder implements IQueryBuilder {
* @return \OCP\DB\QueryBuilder\IExpressionBuilder
*/
public function expr() {
- if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
- return new OCIExpressionBuilder($this->connection, $this);
- }
- if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) {
- return new PgSqlExpressionBuilder($this->connection, $this);
- }
- if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
- return new MySqlExpressionBuilder($this->connection, $this);
- }
- if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
- 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),
+ };
}
/**
@@ -129,17 +116,12 @@ class QueryBuilder implements IQueryBuilder {
* @return \OCP\DB\QueryBuilder\IFunctionBuilder
*/
public function func() {
- if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
- return new OCIFunctionBuilder($this->connection, $this, $this->helper);
- }
- if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
- return new SqliteFunctionBuilder($this->connection, $this, $this->helper);
- }
- if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) {
- return new PgSqlFunctionBuilder($this->connection, $this, $this->helper);
- }
-
- return new FunctionBuilder($this->connection, $this, $this->helper);
+ return match($this->connection->getDatabaseProvider()) {
+ IDBConnection::PLATFORM_ORACLE => new OCIFunctionBuilder($this->connection, $this, $this->helper),
+ IDBConnection::PLATFORM_POSTGRES => new PgSqlFunctionBuilder($this->connection, $this, $this->helper),
+ IDBConnection::PLATFORM_MYSQL => new FunctionBuilder($this->connection, $this, $this->helper),
+ IDBConnection::PLATFORM_SQLITE => new SqliteFunctionBuilder($this->connection, $this, $this->helper),
+ };
}
/**
diff --git a/lib/private/Repair/Collation.php b/lib/private/Repair/Collation.php
index 0affb3b1ca9..a01a684151b 100644
--- a/lib/private/Repair/Collation.php
+++ b/lib/private/Repair/Collation.php
@@ -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;
}
diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php
index a5df85896e2..09bd1a564cd 100644
--- a/lib/public/IDBConnection.php
+++ b/lib/public/IDBConnection.php
@@ -278,6 +278,7 @@ interface IDBConnection {
*
* @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
* @since 8.0.0
+ * @deprecated 30.0.0 Please use {@see self::getDatabaseProvider()} and compare to self::PLATFORM_* constants
*/
public function getDatabasePlatform();
@@ -341,7 +342,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;
}