‪TYPO3CMS  10.4
DatabaseCheck.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\Driver;
21 use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DoctrineDrizzlePDOMySQLDriver;
22 use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
23 use Doctrine\DBAL\Driver\Mysqli\Driver as DoctrineMysqliDriver;
24 use Doctrine\DBAL\Driver\OCI8\Driver as DoctrineOCI8Driver;
25 use Doctrine\DBAL\Driver\PDOOracle\Driver as DoctrinePDOOCIDriver;
26 use Doctrine\DBAL\Driver\SQLAnywhere\Driver as DoctrineSQLAnywhereDriver;
27 use Doctrine\DBAL\Driver\SQLSrv\Driver as DoctrineSQLSrvDriver;
28 use ‪TYPO3\CMS\Core\Database\Driver\PDOMySql\Driver as TYPO3PDOMySqlDriver;
29 use ‪TYPO3\CMS\Core\Database\Driver\PDOPgSql\Driver as TYPO3PDOPgSqlDriver;
30 use ‪TYPO3\CMS\Core\Database\Driver\PDOSqlite\Driver as TYPO3PDOSqliteDriver;
31 use ‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver as TYPO3PDOSqlSrvDriver;
45 
78 {
82  private ‪$messageQueue;
83 
89  private static ‪$databaseDriverToPlatformMapping = [
90  DoctrineMysqliDriver::class => DatabaseCheckPlatformMysql::class,
91  TYPO3PDOMySqlDriver::class => DatabaseCheckPlatformMysql::class,
92  TYPO3PDOPgSqlDriver::class => DatabaseCheckPlatformPostgreSql::class,
93  DoctrineSQLSrvDriver::class => DatabaseCheckPlatformSqlSrv::class,
94  TYPO3PDOSqlSrvDriver::class => DatabaseCheckPlatformSqlSrv::class,
95  TYPO3PDOSqliteDriver::class => DatabaseCheckPlatformSqlite::class,
96  ];
97 
101  private static ‪$driverMap = [
102  'pdo_mysql' => TYPO3PDOMySqlDriver::class,
103  'pdo_sqlite' => TYPO3PDOSqliteDriver::class,
104  'pdo_pgsql' => TYPO3PDOPgSqlDriver::class,
105  'pdo_oci' => DoctrinePDOOCIDriver::class,
106  'oci8' => DoctrineOCI8Driver::class,
107  'ibm_db2' => DB2Driver::class,
108  'pdo_sqlsrv' => TYPO3PDOSqlSrvDriver::class,
109  'mysqli' => DoctrineMysqliDriver::class,
110  'drizzle_pdo_mysql' => DoctrineDrizzlePDOMySQLDriver::class,
111  'sqlanywhere' => DoctrineSQLAnywhereDriver::class,
112  'sqlsrv' => DoctrineSQLSrvDriver::class,
113  ];
114 
120  private ‪$databaseDriverCheckMap = [
121  DoctrineMysqliDriver::class => DatabaseCheckDriverMysqli::class,
122  TYPO3PDOMySqlDriver::class => DatabaseCheckDriverPdoMysql::class,
123  TYPO3PDOPgSqlDriver::class => DatabaseCheckDriverPDOPgSql::class,
124  DoctrineSQLSrvDriver::class => DatabaseCheckDriverSQLSrv::class,
125  TYPO3PDOSqlSrvDriver::class => DatabaseCheckDriverPDOSqlsrv::class,
126  TYPO3PDOSqliteDriver::class => DatabaseCheckDriverPDOSqlite::class,
127  ];
128 
129  public function ‪__construct()
130  {
131  $this->messageQueue = new ‪FlashMessageQueue('install-database-check');
132  }
133 
139  public function ‪getStatus(): ‪FlashMessageQueue
140  {
141  $installedDrivers = $this->‪identifyInstalledDatabaseDriver();
142 
143  // check requirements of database platform for installed driver
144  foreach ($installedDrivers as $driver) {
145  try {
146  $this->‪checkDatabasePlatformRequirements($driver);
147  } catch (‪Exception $exception) {
148  $this->messageQueue->enqueue(
149  new FlashMessage(
150  '',
151  $exception->getMessage(),
153  )
154  );
155  }
156  }
157 
158  // check requirements of database driver for installed driver
159  foreach ($installedDrivers as $driver) {
160  try {
161  $this->‪checkDatabaseDriverRequirements($driver);
162  } catch (Exception $exception) {
163  $this->messageQueue->enqueue(
164  new FlashMessage(
165  '',
166  $exception->getMessage(),
168  )
169  );
170  }
171  }
172 
173  return ‪$this->messageQueue;
174  }
175 
176  public function ‪checkDatabaseDriverRequirements(string $databaseDriver): ‪FlashMessageQueue
177  {
178  if (!empty($this->databaseDriverCheckMap[$databaseDriver])) {
180  $databaseDriverCheck = new $this->databaseDriverCheckMap[$databaseDriver]();
181  foreach ($databaseDriverCheck->getStatus() as $message) {
182  $this->messageQueue->‪addMessage($message);
183  }
184 
185  return ‪$this->messageQueue;
186  }
187 
188  throw new ‪Exception(
189  sprintf(
190  'There are no database driver checks available for the given database driver: %s',
191  $databaseDriver
192  ),
193  1572521099
194  );
195  }
196 
205  public function ‪checkDatabasePlatformRequirements(string $databaseDriver): FlashMessageQueue
206  {
207  static $checkedPlatform = [];
208  $databasePlatformClass = static::$databaseDriverToPlatformMapping[$databaseDriver];
209 
210  // execute platform checks only once
211  if (in_array($databasePlatformClass, $checkedPlatform, true)) {
212  return ‪$this->messageQueue;
213  }
214 
215  if (!empty(static::$databaseDriverToPlatformMapping[$databaseDriver])) {
216  $platformMessageQueue = (new $databasePlatformClass())->‪getStatus();
217  foreach ($platformMessageQueue as $message) {
218  $this->messageQueue->‪enqueue($message);
219  }
220  $checkedPlatform[] = $databasePlatformClass;
221 
222  return ‪$this->messageQueue;
223  }
224 
225  throw new Exception(
226  sprintf(
227  'There are no database platform checks available for the given database driver: %s',
228  $databaseDriver
229  ),
230  1573753070
231  );
232  }
233 
234  public function ‪identifyInstalledDatabaseDriver(): array
235  {
236  $installedDrivers = [];
237 
238  if (static::isMysqli()) {
239  $installedDrivers[] = DoctrineMysqliDriver::class;
240  }
241 
242  if (static::isPdoMysql()) {
243  $installedDrivers[] = TYPO3PDOMySqlDriver::class;
244  }
245 
246  if (static::isPdoPgsql()) {
247  $installedDrivers[] = TYPO3PDOPgSqlDriver::class;
248  }
249 
250  if (static::isPdoSqlite()) {
251  $installedDrivers[] = TYPO3PDOSqliteDriver::class;
252  }
253 
254  if (static::isPdoSqlSrv()) {
255  $installedDrivers[] = TYPO3PDOSqlSrvDriver::class;
256  }
257 
258  if (static::isSqlSrv()) {
259  $installedDrivers[] = Driver\SQLSrv\Driver::class;
260  }
261 
262  return $installedDrivers;
263  }
264 
271  public static function ‪retrieveDatabasePlatformByDriverName(string $databaseDriverName): string
272  {
273  $databaseDriverClassName = static::retrieveDatabaseDriverClassByDriverName($databaseDriverName);
274  if (!empty(static::$databaseDriverToPlatformMapping[$databaseDriverClassName])) {
275  return static::$databaseDriverToPlatformMapping[$databaseDriverClassName];
276  }
277 
278  throw new Exception(
279  sprintf('There is no database platform available for the given driver: %s', $databaseDriverName),
280  1573753057
281  );
282  }
283 
289  public static function ‪retrieveDatabaseDriverClassByDriverName(string $driverName): string
290  {
291  if (!empty(static::$driverMap[$driverName])) {
292  return static::$driverMap[$driverName];
293  }
294 
295  throw new Exception(
296  sprintf('There is no database driver available for the given driver name: %s', $driverName),
297  1573740447
298  );
299  }
300 
301  public function ‪getMessageQueue(): ‪FlashMessageQueue
302  {
303  return ‪$this->messageQueue;
304  }
305 
306  public static function ‪isMysqli(): bool
307  {
308  return extension_loaded('mysqli');
309  }
310 
311  public static function ‪isPdoMysql(): bool
312  {
313  return extension_loaded('pdo_mysql');
314  }
315 
316  public static function ‪isPdoPgsql(): bool
317  {
318  return extension_loaded('pdo_pgsql');
319  }
320 
321  public static function ‪isPdoSqlite(): bool
322  {
323  return extension_loaded('pdo_sqlite');
324  }
325 
326  public static function ‪isPdoSqlSrv(): bool
327  {
328  return extension_loaded('pdo_sqlsrv');
329  }
330 
331  public static function ‪isSqlSrv(): bool
332  {
333  return extension_loaded('sqlsrv');
334  }
335 }
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\getMessageQueue
‪getMessageQueue()
Definition: DatabaseCheck.php:297
‪TYPO3\CMS\Core\Database\Driver\PDOPgSql\Driver
Definition: Driver.php:31
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\Sqlite
Definition: Sqlite.php:30
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\$databaseDriverToPlatformMapping
‪static string[] $databaseDriverToPlatformMapping
Definition: DatabaseCheck.php:87
‪TYPO3\CMS\Core\Database\Driver\PDOMySql\Driver
Definition: Driver.php:30
‪TYPO3\CMS\Install\SystemEnvironment\CheckInterface
Definition: CheckInterface.php:31
‪TYPO3\CMS\Core\Database\Driver\PDOSqlsrv\Driver
Definition: Driver.php:25
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\retrieveDatabasePlatformByDriverName
‪static string retrieveDatabasePlatformByDriverName(string $databaseDriverName)
Definition: DatabaseCheck.php:267
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isPdoSqlite
‪static isPdoSqlite()
Definition: DatabaseCheck.php:317
‪TYPO3\CMS\Core\Database\Driver\PDOSqlite\Driver
Definition: Driver.php:30
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue\enqueue
‪FlashMessageQueue enqueue($message)
Definition: FlashMessageQueue.php:60
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue\addMessage
‪addMessage(FlashMessage $message)
Definition: FlashMessageQueue.php:79
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\SQLSrv
Definition: SQLSrv.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\PDOPgSql
Definition: PDOPgSql.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\PdoMysql
Definition: PdoMysql.php:34
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck
Definition: DatabaseCheck.php:78
‪TYPO3\CMS\Install\Exception
Definition: Exception.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\Mysqli
Definition: Mysqli.php:35
‪TYPO3\CMS\Install\SystemEnvironment
Definition: Check.php:18
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\PostgreSql
Definition: PostgreSql.php:38
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: DatabaseCheck.php:81
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\SqlSrv
Definition: SqlSrv.php:30
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\retrieveDatabaseDriverClassByDriverName
‪static string retrieveDatabaseDriverClassByDriverName(string $driverName)
Definition: DatabaseCheck.php:285
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\$databaseDriverCheckMap
‪string[] $databaseDriverCheckMap
Definition: DatabaseCheck.php:116
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isPdoSqlSrv
‪static isPdoSqlSrv()
Definition: DatabaseCheck.php:322
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\identifyInstalledDatabaseDriver
‪identifyInstalledDatabaseDriver()
Definition: DatabaseCheck.php:230
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isSqlSrv
‪static isSqlSrv()
Definition: DatabaseCheck.php:327
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\PDOSqlite
Definition: PDOSqlite.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\__construct
‪__construct()
Definition: DatabaseCheck.php:125
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\getStatus
‪FlashMessageQueue getStatus()
Definition: DatabaseCheck.php:135
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isPdoMysql
‪static isPdoMysql()
Definition: DatabaseCheck.php:307
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\checkDatabasePlatformRequirements
‪FlashMessageQueue checkDatabasePlatformRequirements(string $databaseDriver)
Definition: DatabaseCheck.php:201
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\checkDatabaseDriverRequirements
‪checkDatabaseDriverRequirements(string $databaseDriver)
Definition: DatabaseCheck.php:172
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Platform\MySql
Definition: MySql.php:38
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\Driver\PDOSqlsrv
Definition: PDOSqlsrv.php:24
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isPdoPgsql
‪static isPdoPgsql()
Definition: DatabaseCheck.php:312
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\$driverMap
‪static string[] $driverMap
Definition: DatabaseCheck.php:98
‪TYPO3\CMS\Install\SystemEnvironment\DatabaseCheck\isMysqli
‪static isMysqli()
Definition: DatabaseCheck.php:302