aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2023-09-14 14:59:06 +0200
committerAnna <anna@nextcloud.com>2023-09-19 11:56:44 +0200
commit56419d94f8a128b503a8cd6fe74befe908bb2361 (patch)
tree4b77648640bd8ac98352a690bd5076f109f50f43
parent8157d9789070e6d38710b1530aa4d903d74ca2ac (diff)
downloadnextcloud-server-56419d94f8a128b503a8cd6fe74befe908bb2361.tar.gz
nextcloud-server-56419d94f8a128b503a8cd6fe74befe908bb2361.zip
enh(db): provide database providers via API
To avoid leaking internals (OC), wrap the getDatabasePlatform and provide the associated constants fixes https://github.com/nextcloud/server/issues/30877 Signed-off-by: Anna Larch <anna@nextcloud.com>
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php4
-rw-r--r--lib/private/DB/ConnectionAdapter.php19
-rw-r--r--lib/public/IDBConnection.php20
3 files changed, 41 insertions, 2 deletions
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index 295f791babb..5dcf6cda29c 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -641,7 +641,7 @@ Raw output
protected function hasValidTransactionIsolationLevel(): bool {
try {
- if ($this->db->getDatabasePlatform() instanceof SqlitePlatform) {
+ if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
return true;
}
@@ -839,7 +839,7 @@ Raw output
];
$schema = new SchemaWrapper($this->db);
- $isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
+ $isSqlite = $this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE;
$pendingColumns = [];
foreach ($tables as $tableName => $columns) {
diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php
index 56d554f8313..e27c98194fb 100644
--- a/lib/private/DB/ConnectionAdapter.php
+++ b/lib/private/DB/ConnectionAdapter.php
@@ -27,6 +27,10 @@ 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;
@@ -242,4 +246,19 @@ class ConnectionAdapter implements IDBConnection {
public function getInner(): Connection {
return $this->inner;
}
+
+ 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');
+ }
+ }
}
diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php
index fe0267facc5..a528bb1a57b 100644
--- a/lib/public/IDBConnection.php
+++ b/lib/public/IDBConnection.php
@@ -45,6 +45,18 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
* @since 6.0.0
*/
interface IDBConnection {
+ /* @since 28.0.0 */
+ public const PLATFORM_MYSQL = 'mysql';
+
+ /* @since 28.0.0 */
+ public const PLATFORM_ORACLE = 'oracle';
+
+ /* @since 28.0.0 */
+ public const PLATFORM_POSTGRES = 'postgres';
+
+ /* @since 28.0.0 */
+ public const PLATFORM_SQLITE = 'sqlite';
+
/**
* Gets the QueryBuilder for the connection.
*
@@ -339,4 +351,12 @@ interface IDBConnection {
* @since 13.0.0
*/
public function migrateToSchema(Schema $toSchema): void;
+
+ /**
+ * Returns the database provider name
+ * @link https://github.com/nextcloud/server/issues/30877
+ * @since 28.0.0
+ * @return IDBConnection::PLATFORM_*
+ */
+ public function getDatabaseProvider(): string;
}