From a3a261e13769f934eeb44dcc311f5091e110c8bf Mon Sep 17 00:00:00 2001 From: Morton Jonuschat <m.jonuschat@mojocode.de> Date: Fri, 27 May 2016 10:23:35 +0200 Subject: [PATCH] [BUGFIX] Doctrine: Use compatible charset name for database connection Use the charset name 'utf8' instead of 'utf-8' for MySQL connections as some MySQL server versions silently ignore the connection charset name 'utf-8' and work with the global default connection charset instead. Using 'utf8' as charset name doesn't exhibit this behavior. Also changes the silent upgrade wizard to only set the default driver and connection charset if no value has been configured, this avoids silently changing non-default values for these options. Change-Id: I94e1e7c557aff890cec357ef9ee069ae9aa052c6 Resolves: #76265 Releases: master Reviewed-on: https://review.typo3.org/48310 Tested-by: Riccardo De Contardi <erredeco@gmail.com> Tested-by: Gianluigi Martino <gmartino27@gmail.com> Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Frank Naegler <frank.naegler@typo3.org> Tested-by: Frank Naegler <frank.naegler@typo3.org> --- .../SilentConfigurationUpgradeService.php | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php b/typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php index 03d8f6e1f5e4..4f7a64cbb7a6 100755 --- a/typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php +++ b/typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php @@ -106,6 +106,7 @@ class SilentConfigurationUpgradeService $this->migrateThumbnailsPngSetting(); $this->migrateLockSslSetting(); $this->migrateDatabaseConnectionSettings(); + $this->migrateDatabaseConnectionCharset(); } /** @@ -660,15 +661,44 @@ class SilentConfigurationUpgradeService ); } - // Set the utf-8 connection charset by default - $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/charset', 'utf-8'); + // Set the utf-8 connection charset by default if no value has been provided yet + try { + $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset'); + } catch (\RuntimeException $e) { + $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/charset', 'utf8'); + } - // Use the mysqli driver by default - $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/driver', 'mysqli'); + // Use the mysqli driver by default if no value has been provided yet + try { + $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver'); + } catch (\RuntimeException $e) { + $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/driver', 'mysqli'); + } if (!empty(array_filter($changedSettings))) { $confManager->removeLocalConfigurationKeysByPath(array_keys($changedSettings)); $this->throwRedirectException(); } } + + /** + * Migrate the configuration setting DB/Connections/Default/charset to 'utf8' as + * 'utf-8' is not supported by all MySQL versions. + * + * @return void + */ + protected function migrateDatabaseConnectionCharset() + { + $confManager = $this->configurationManager; + try { + $driver = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/driver'); + $charset = $confManager->getLocalConfigurationValueByPath('DB/Connections/Default/charset'); + if (in_array($driver, ['mysqli', 'pdo_mysql', 'drizzle_pdo_mysql'], true) && $charset === 'utf-8') { + $confManager->setLocalConfigurationValueByPath('DB/Connections/Default/charset', 'utf8'); + $this->throwRedirectException(); + } + } catch (\RuntimeException $e) { + // no incompatible charset configuration found, so nothing needs to be modified + } + } } -- GitLab