|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace App\Services\Misc; |
|
22
|
|
|
|
|
23
|
|
|
use Doctrine\DBAL\Connection; |
|
24
|
|
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; |
|
25
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform; |
|
|
|
|
|
|
26
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* This service provides db independent information about the database. |
|
30
|
|
|
*/ |
|
31
|
|
|
class DBInfoHelper |
|
32
|
|
|
{ |
|
33
|
|
|
protected Connection $connection; |
|
34
|
|
|
protected EntityManagerInterface $entityManager; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(EntityManagerInterface $entityManager) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->entityManager = $entityManager; |
|
39
|
|
|
$this->connection = $entityManager->getConnection(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the database type of the used database. |
|
44
|
|
|
* @return string|null Returns 'mysql' for MySQL/MariaDB and 'sqlite' for SQLite. Returns null if unknown type |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getDatabaseType(): ?string |
|
47
|
|
|
{ |
|
48
|
|
|
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { |
|
49
|
|
|
return 'mysql'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
53
|
|
|
return 'sqlite'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return null; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the database version of the used database. |
|
61
|
|
|
* @return string|null |
|
62
|
|
|
* @throws \Doctrine\DBAL\Exception |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getDatabaseVersion(): ?string |
|
65
|
|
|
{ |
|
66
|
|
|
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { |
|
67
|
|
|
return $this->connection->fetchOne('SELECT VERSION()'); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
71
|
|
|
return $this->connection->fetchOne('SELECT sqlite_version()'); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return null; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the database size in bytes. |
|
79
|
|
|
* @return int|null The database size in bytes or null if unknown |
|
80
|
|
|
* @throws \Doctrine\DBAL\Exception |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getDatabaseSize(): ?int |
|
83
|
|
|
{ |
|
84
|
|
|
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { |
|
85
|
|
|
try { |
|
86
|
|
|
return $this->connection->fetchOne('SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema = DATABASE()'); |
|
|
|
|
|
|
87
|
|
|
} catch (\Doctrine\DBAL\Exception $e) { |
|
88
|
|
|
return null; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
93
|
|
|
try { |
|
94
|
|
|
return $this->connection->fetchOne('SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size();'); |
|
|
|
|
|
|
95
|
|
|
} catch (\Doctrine\DBAL\Exception $e) { |
|
96
|
|
|
return null; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths