2 namespace TYPO3\CMS\Install\Updates
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
18 * Move "wizard done" flags to system registry
20 class DatabaseCharsetUpdate
extends AbstractUpdate
25 protected $title = 'Set default database charset to utf-8';
28 * Checks if an update is needed
30 * @param string &$description The description for the update
31 * @return bool Whether an update is needed (TRUE) or not (FALSE)
33 public function checkForUpdate(&$description)
36 $description = 'Sets the default database charset to utf-8 to ensure new tables are created with correct charset.
37 WARNING: This will NOT convert any existing data.';
39 if($this->isDbalEnabled()) {
42 // check if database charset is utf-8
43 $defaultDatabaseCharset = $this->getDefaultDatabaseCharset();
45 if (substr($defaultDatabaseCharset, 0, 4) !== 'utf8') {
53 * Performs the accordant updates.
55 * @param array &$dbQueries Queries done in this update
56 * @param mixed &$customMessages Custom messages
57 * @return bool Whether everything went smoothly or not
59 public function performUpdate(array &$dbQueries, &$customMessages)
62 $db = $this->getDatabaseConnection();
63 $query = 'ALTER DATABASE `' . $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] . '` DEFAULT CHARACTER SET utf8';
64 $db->admin_query($query);
65 $dbQueries[] = $query;
66 if ($db->sql_error()) {
67 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($db->sql_error());
74 * Return TRUE if dbal and adodb extension is loaded
76 * @return bool TRUE if dbal and adodb is loaded
78 protected function isDbalEnabled()
80 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::isLoaded('adodb')
81 && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::isLoaded('dbal')
89 * Retrieves the default character set of the database.
93 protected function getDefaultDatabaseCharset()
95 $db = $this->getDatabaseConnection();
96 $result = $db->admin_query('SHOW VARIABLES LIKE "character_set_database"');
97 $row = $db->sql_fetch_assoc($result);
99 $key = $row['Variable_name'];
100 $value = $row['Value'];
101 $databaseCharset = '';
103 if ($key == 'character_set_database') {
104 $databaseCharset = $value;
107 return $databaseCharset;