TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DatabaseCheck.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\SystemEnvironment;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 use TYPO3\CMS\Install\Status;
22 
33 {
39  protected $incompatibleSqlModes = [
40  'NO_BACKSLASH_ESCAPES'
41  ];
42 
48  public function getStatus()
49  {
50  $statusArray = [];
51  $defaultConnection = GeneralUtility::makeInstance(ConnectionPool::class)
52  ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
53  if (strpos($defaultConnection->getServerVersion(), 'MySQL') !== 0) {
54  return $statusArray;
55  }
56  $statusArray[] = $this->checkMysqlVersion($defaultConnection);
57  $statusArray[] = $this->checkInvalidSqlModes($defaultConnection);
58  $statusArray[] = $this->checkMysqlDatabaseUtf8Status($defaultConnection);
59  return $statusArray;
60  }
61 
68  protected function checkInvalidSqlModes($connection)
69  {
70  $detectedIncompatibleSqlModes = $this->getIncompatibleSqlModes($connection);
71  if (!empty($detectedIncompatibleSqlModes)) {
72  $status = new Status\ErrorStatus();
73  $status->setTitle('Incompatible SQL modes found!');
74  $status->setMessage(
75  'Incompatible SQL modes have been detected:' .
76  ' ' . implode(', ', $detectedIncompatibleSqlModes) . '.' .
77  ' The listed modes are not compatible with TYPO3 CMS.' .
78  ' You have to change that setting in your MySQL environment' .
79  ' or in $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\']'
80  );
81  } else {
82  $status = new Status\OkStatus();
83  $status->setTitle('No incompatible SQL modes found.');
84  }
85 
86  return $status;
87  }
88 
95  protected function checkMysqlVersion($connection)
96  {
97  $minimumMysqlVersion = '5.5.0';
98  preg_match('/MySQL ((\d+\.)*(\d+\.)*\d+)/', $connection->getServerVersion(), $match);
99  $currentMysqlVersion = $match[1];
100  if (version_compare($currentMysqlVersion, $minimumMysqlVersion) < 0) {
101  $status = new Status\ErrorStatus();
102  $status->setTitle('MySQL version too low');
103  $status->setMessage(
104  'Your MySQL version ' . $currentMysqlVersion . ' is too old. TYPO3 CMS does not run' .
105  ' with this version. Update to at least MySQL ' . $minimumMysqlVersion
106  );
107  } else {
108  $status = new Status\OkStatus();
109  $status->setTitle('MySQL version is fine');
110  }
111 
112  return $status;
113  }
114 
121  protected function checkMysqlDatabaseUtf8Status(Connection $connection)
122  {
124  $queryBuilder = $connection->createQueryBuilder();
125  $defaultDatabaseCharset = (string)$queryBuilder->select('DEFAULT_CHARACTER_SET_NAME')
126  ->from('information_schema.SCHEMATA')
127  ->where(
128  $queryBuilder->expr()->eq(
129  'SCHEMA_NAME',
130  $queryBuilder->createNamedParameter($connection->getDatabase(), \PDO::PARAM_STR)
131  )
132  )
133  ->setMaxResults(1)
134  ->execute()
135  ->fetchColumn();
136  // also allow utf8mb4
137  if (strpos($defaultDatabaseCharset, 'utf8') !== 0) {
138  $status = new Status\ErrorStatus();
139  $status->setTitle('MySQL database character set check failed');
140  $status->setMessage(
141  'Checking database character set failed, got key "'
142  . $defaultDatabaseCharset . '" instead of "utf8" or "utf8mb4"'
143  );
144  } else {
145  $status = new Status\OkStatus();
146  $status->setTitle('Your database uses utf-8. All good.');
147  }
148  return $status;
149  }
150 
157  protected function getIncompatibleSqlModes($connection)
158  {
159  $sqlModes = explode(',', $connection->executeQuery('SELECT @@SESSION.sql_mode;')
160  ->fetch(0)['@@SESSION.sql_mode']);
161  return array_intersect($this->incompatibleSqlModes, $sqlModes);
162  }
163 }
static makeInstance($className,...$constructorArguments)