mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 02:14:31 +02:00
Added an page to view infos about the server (Part-DB, PHP and DB config
This commit is contained in:
parent
78d1dff40f
commit
34fbcec00f
10 changed files with 1287 additions and 1018 deletions
58
src/Services/Misc/DBInfoHelper.php
Normal file
58
src/Services/Misc/DBInfoHelper.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Misc;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
* This service provides db independent information about the database.
|
||||
*/
|
||||
class DBInfoHelper
|
||||
{
|
||||
protected Connection $connection;
|
||||
protected EntityManagerInterface $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->connection = $entityManager->getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database type of the used database.
|
||||
* @return string|null Returns 'mysql' for MySQL/MariaDB and 'sqlite' for SQLite. Returns null if unknown type
|
||||
*/
|
||||
public function getDatabaseType(): ?string
|
||||
{
|
||||
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
||||
return 'mysql';
|
||||
}
|
||||
|
||||
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
return 'sqlite';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database version of the used database.
|
||||
* @return string|null
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function getDatabaseVersion(): ?string
|
||||
{
|
||||
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
|
||||
return $this->connection->fetchOne('SELECT VERSION()');
|
||||
}
|
||||
|
||||
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
return $this->connection->fetchOne('SELECT sqlite_version()');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -291,6 +291,13 @@ class ToolsTreeBuilder
|
|||
))->setIcon('fa-fw fa-treeview fa-solid fa-binoculars');
|
||||
}
|
||||
|
||||
if ($this->security->isGranted('@system.server_infos')) {
|
||||
$nodes[] = (new TreeViewNode(
|
||||
$this->translator->trans('tools.server_infos.title'),
|
||||
$this->urlGenerator->generate('tools_server_infos')
|
||||
))->setIcon('fa-fw fa-treeview fa-solid fa-database');
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue