‪TYPO3CMS  9.5
MySqlCheck.php
Go to the documentation of this file.
1 <?php
2 
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 
24 
37 {
41  protected ‪$messageQueue;
42 
48  protected ‪$minimumMySQLVersion = '5.5.0';
49 
55  protected ‪$incompatibleSqlModes = [
56  'NO_BACKSLASH_ESCAPES'
57  ];
58 
66  public function ‪getStatus(): ‪FlashMessageQueue
67  {
68  $this->messageQueue = new ‪FlashMessageQueue('install');
69  $defaultConnection = GeneralUtility::makeInstance(ConnectionPool::class)
70  ->getConnectionByName(‪ConnectionPool::DEFAULT_CONNECTION_NAME);
71  if (strpos($defaultConnection->getServerVersion(), 'MySQL') !== 0) {
73  }
74  $this->‪checkMysqlVersion($defaultConnection);
75  $this->‪checkInvalidSqlModes($defaultConnection);
76  $this->‪checkMysqlDatabaseUtf8Status($defaultConnection);
78  }
79 
85  protected function ‪checkInvalidSqlModes(‪Connection $connection)
86  {
87  $detectedIncompatibleSqlModes = $this->‪getIncompatibleSqlModes($connection);
88  if (!empty($detectedIncompatibleSqlModes)) {
89  $this->messageQueue->enqueue(new ‪FlashMessage(
90  'Incompatible SQL modes have been detected:'
91  . ' ' . implode(', ', $detectedIncompatibleSqlModes) . '.'
92  . ' The listed modes are not compatible with TYPO3 CMS.'
93  . ' You have to change that setting in your MySQL environment'
94  . ' or in $GLOBALS[\'TYPO3_CONF_VARS\'][\'DB\'][\'Connections\'][\'Default\'][\'initCommands\']',
95  'Incompatible SQL modes found!',
97  ));
98  } else {
99  $this->messageQueue->enqueue(new ‪FlashMessage(
100  '',
101  'No incompatible SQL modes found.'
102  ));
103  }
104  }
105 
111  protected function ‪checkMysqlVersion(‪Connection $connection)
112  {
113  preg_match('/MySQL ((\d+\.)*(\d+\.)*\d+)/', $connection->‪getServerVersion(), $match);
114  $currentMysqlVersion = $match[1];
115  if (version_compare($currentMysqlVersion, $this->minimumMySQLVersion, '<')) {
116  $this->messageQueue->enqueue(new ‪FlashMessage(
117  'Your MySQL version ' . $currentMysqlVersion . ' is too old. TYPO3 CMS does not run'
118  . ' with this version. Update to at least MySQL ' . $this->minimumMySQLVersion,
119  'MySQL version too low',
121  ));
122  } else {
123  $this->messageQueue->enqueue(new ‪FlashMessage(
124  '',
125  'MySQL version is fine'
126  ));
127  }
128  }
129 
135  protected function ‪checkMysqlDatabaseUtf8Status(‪Connection $connection)
136  {
137  $queryBuilder = $connection->‪createQueryBuilder();
138  $defaultDatabaseCharset = (string)$queryBuilder->‪select('DEFAULT_CHARACTER_SET_NAME')
139  ->‪from('information_schema.SCHEMATA')
140  ->‪where(
141  $queryBuilder->expr()->eq(
142  'SCHEMA_NAME',
143  $queryBuilder->createNamedParameter($connection->getDatabase(), \PDO::PARAM_STR)
144  )
145  )
146  ->setMaxResults(1)
147  ->‪execute()
148  ->fetchColumn();
149  // also allow utf8mb4
150  if (strpos($defaultDatabaseCharset, 'utf8') !== 0) {
151  $this->messageQueue->enqueue(new ‪FlashMessage(
152  'Checking database character set failed, got key "'
153  . $defaultDatabaseCharset . '" instead of "utf8" or "utf8mb4"',
154  'MySQL database character set check failed',
156  ));
157  } else {
158  $this->messageQueue->enqueue(new ‪FlashMessage(
159  '',
160  'Your database uses utf-8. All good.'
161  ));
162  }
163  }
164 
171  protected function ‪getIncompatibleSqlModes(‪Connection $connection): array
172  {
173  $sqlModes = explode(',', $connection->executeQuery('SELECT @@SESSION.sql_mode;')
174  ->fetch(0)['@@SESSION.sql_mode']);
175  return array_intersect($this->incompatibleSqlModes, $sqlModes);
176  }
177 }
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\select
‪QueryBuilder select(string ... $selects)
Definition: QueryBuilder.php:390
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\getStatus
‪FlashMessageQueue getStatus()
Definition: MySqlCheck.php:63
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkInvalidSqlModes
‪checkInvalidSqlModes(Connection $connection)
Definition: MySqlCheck.php:82
‪TYPO3\CMS\Install\SystemEnvironment\CheckInterface
Definition: CheckInterface.php:31
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkMysqlVersion
‪checkMysqlVersion(Connection $connection)
Definition: MySqlCheck.php:108
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform
Definition: MySqlCheck.php:3
‪TYPO3\CMS\Core\Database\ConnectionPool\DEFAULT_CONNECTION_NAME
‪const DEFAULT_CONNECTION_NAME
Definition: ConnectionPool.php:48
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\from
‪QueryBuilder from(string $from, string $alias=null)
Definition: QueryBuilder.php:506
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\getIncompatibleSqlModes
‪array getIncompatibleSqlModes(Connection $connection)
Definition: MySqlCheck.php:168
‪TYPO3\CMS\Core\Database\Connection\getServerVersion
‪string getServerVersion()
Definition: Connection.php:370
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\execute
‪Doctrine DBAL Driver Statement int execute()
Definition: QueryBuilder.php:178
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\$incompatibleSqlModes
‪array $incompatibleSqlModes
Definition: MySqlCheck.php:52
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck
Definition: MySqlCheck.php:37
‪TYPO3\CMS\Core\Database\Connection\createQueryBuilder
‪TYPO3 CMS Core Database Query QueryBuilder createQueryBuilder()
Definition: Connection.php:110
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\$messageQueue
‪FlashMessageQueue $messageQueue
Definition: MySqlCheck.php:40
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\$minimumMySQLVersion
‪string $minimumMySQLVersion
Definition: MySqlCheck.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkMysqlDatabaseUtf8Status
‪checkMysqlDatabaseUtf8Status(Connection $connection)
Definition: MySqlCheck.php:132
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:25
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\where
‪QueryBuilder where(... $predicates)
Definition: QueryBuilder.php:630
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29