TYPO3 CMS  TYPO3_7-6
DatabaseCheck.php
Go to the documentation of this file.
1 <?php
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 
19 
30 {
36  protected $incompatibleSqlModes = [
37  'NO_BACKSLASH_ESCAPES'
38  ];
39 
45  public function getStatus()
46  {
47  $statusArray = [];
48  if ($this->isDbalEnabled() || !$this->getDatabaseConnection()) {
49  return $statusArray;
50  }
51  $statusArray[] = $this->checkMysqlVersion();
52  $statusArray[] = $this->checkInvalidSqlModes();
53  return $statusArray;
54  }
55 
61  protected function checkInvalidSqlModes()
62  {
63  $detectedIncompatibleSqlModes = $this->getIncompatibleSqlModes();
64  if (!empty($detectedIncompatibleSqlModes)) {
65  $status = new Status\ErrorStatus();
66  $status->setTitle('Incompatible SQL modes found!');
67  $status->setMessage(
68  'Incompatible SQL modes have been detected:' .
69  ' ' . implode(', ', $detectedIncompatibleSqlModes) . '.' .
70  ' The listed modes are not compatible with TYPO3 CMS.' .
71  ' You have to change that setting in your MySQL environment' .
72  ' or in $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\']'
73  );
74  } else {
75  $status = new Status\OkStatus();
76  $status->setTitle('No incompatible SQL modes found.');
77  }
78 
79  return $status;
80  }
81 
87  protected function checkMysqlVersion()
88  {
89  $minimumMysqlVersion = '5.5.0';
90  $currentMysqlVersion = '';
91  $resource = $this->getDatabaseConnection()->sql_query('SHOW VARIABLES LIKE \'version\';');
92  if ($resource !== false) {
93  $result = $this->getDatabaseConnection()->sql_fetch_row($resource);
94  if (isset($result[1])) {
95  $currentMysqlVersion = $result[1];
96  }
97  }
98  if (strpos($currentMysqlVersion, 'MariaDB') !== false) {
99  $notSupportedVersion = '10.2.0';
100  if (version_compare($currentMysqlVersion, $minimumMysqlVersion) < 0) {
101  $status = new Status\ErrorStatus();
102  $status->setTitle('MariaDB version too low');
103  $status->setMessage(
104  'Your MariaDB version ' . $currentMysqlVersion . ' is too old. TYPO3 CMS does not run' .
105  ' with this version. Update to at least MariaDB ' . $minimumMysqlVersion
106  );
107  } elseif (version_compare($currentMysqlVersion, $notSupportedVersion) >= 0) {
108  $status = new Status\ErrorStatus();
109  $status->setTitle('MariaDB version too high');
110  $status->setMessage(
111  'Your MariaDB version ' . $currentMysqlVersion . ' is too new. TYPO3 CMS does not run with this version.'
112  );
113  } else {
114  $status = new Status\OkStatus();
115  $status->setTitle('MariaDB version is fine');
116  }
117  } else {
118  $notSupportedVersion = '8.0.0';
119  if (version_compare($currentMysqlVersion, $minimumMysqlVersion) < 0) {
120  $status = new Status\ErrorStatus();
121  $status->setTitle('MySQL version too low');
122  $status->setMessage(
123  'Your MySQL version ' . $currentMysqlVersion . ' is too old. TYPO3 CMS does not run' .
124  ' with this version. Update to at least MySQL ' . $minimumMysqlVersion
125  );
126  } elseif (version_compare($currentMysqlVersion, $notSupportedVersion) >= 0) {
127  $status = new Status\ErrorStatus();
128  $status->setTitle('MySQL version too high');
129  $status->setMessage(
130  'Your MySQL version ' . $currentMysqlVersion . ' is too new. TYPO3 CMS does not run with this version.'
131  );
132  } else {
133  $status = new Status\OkStatus();
134  $status->setTitle('MySQL version is fine');
135  }
136  }
137 
138  return $status;
139  }
140 
146  protected function getIncompatibleSqlModes()
147  {
148  $sqlModes = [];
149  $resource = $this->getDatabaseConnection()->sql_query('SELECT @@SESSION.sql_mode;');
150  if ($resource !== false) {
151  $result = $this->getDatabaseConnection()->sql_fetch_row($resource);
152  if (isset($result[0])) {
153  $sqlModes = explode(',', $result[0]);
154  }
155  }
156  return array_intersect($this->incompatibleSqlModes, $sqlModes);
157  }
158 
165  protected function getDatabaseConnection()
166  {
167  static $database;
168  if (!is_object($database)) {
170  $database = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
171  $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
172  $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
173  $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
174  $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
175  $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
176  $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
177  $database->initialize();
178  $database->connectDB();
179  }
180  return $database;
181  }
182 
188  protected function isDbalEnabled()
189  {
190  return \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('dbal');
191  }
192 }
$database
Definition: server.php:40
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']