Fixed DBInfoHelper compatibility with postgres

This commit is contained in:
Jan Böhmer 2024-06-09 00:46:23 +02:00
parent a88a2e04cf
commit dc14b58d73

View file

@ -25,6 +25,7 @@ namespace App\Services\Misc;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -54,6 +55,10 @@ class DBInfoHelper
return 'sqlite'; return 'sqlite';
} }
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
return 'postgresql';
}
return null; return null;
} }
@ -71,6 +76,10 @@ class DBInfoHelper
return $this->connection->fetchOne('SELECT sqlite_version()'); return $this->connection->fetchOne('SELECT sqlite_version()');
} }
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
return $this->connection->fetchOne('SELECT version()');
}
return null; return null;
} }
@ -97,6 +106,14 @@ class DBInfoHelper
} }
} }
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
try {
return (int) $this->connection->fetchOne('SELECT pg_database_size(current_database())');
} catch (Exception) {
return null;
}
}
return null; return null;
} }
@ -124,6 +141,14 @@ class DBInfoHelper
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
return 'sqlite'; return 'sqlite';
} }
if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
try {
return $this->connection->fetchOne('SELECT current_user');
} catch (Exception) {
return null;
}
}
return null; return null;
} }