diff --git a/typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php b/typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php index 3292d5df9a936a6c0e22b93634d4c494a2a493f7..cdc9474d7555ec945e6552f6945756534971b5aa 100644 --- a/typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php +++ b/typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php @@ -63,6 +63,9 @@ class ConfigurationStatus implements StatusProviderInterface $statuses['createdFilesWorldWritable'] = $this->getCreatedFilesWorldWritableStatus(); $statuses['createdDirectoriesWorldWritable'] = $this->getCreatedDirectoriesWorldWritableStatus(); } + if ($this->isMysqlUsed()) { + $statuses['mysqlDatabaseUsesUtf8'] = $this->getMysqlDatabaseUtf8Status(); + } return $statuses; } @@ -255,6 +258,53 @@ class ConfigurationStatus implements StatusProviderInterface return '<a href="' . $linkToLogFile . '">' . $logFile . '</a>'; } + /** + * Verifies that MySQL is used. + * + * @return bool + */ + protected function isMysqlUsed() + { + return get_class($this->getDatabaseConnection()) == DatabaseConnection::class; + } + + /** + * Checks the character set of the database and reports an error if it is not utf-8. + * + * @return ReportStatus + */ + protected function getMysqlDatabaseUtf8Status() + { + $result = $this->getDatabaseConnection()->admin_query('SHOW VARIABLES LIKE "character_set_database"'); + $row = $this->getDatabaseConnection()->sql_fetch_assoc($result); + + $key = $row['Variable_name']; + $value = $row['Value']; + + $message = ''; + $severity = ReportStatus::OK; + $statusValue = $this->getLanguageService()->getLL('status_ok'); + + if ($key !== 'character_set_database') { + $message = sprintf($this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet_CheckFailed'),$key); + $severity = ReportStatus::WARNING; + $statusValue = $this->getLanguageService()->getLL('status_checkFailed'); + } + // also allow utf8mb4 + if (substr($value, 0, 4) !== 'utf8') { + $message = sprintf($this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet_Unsupported'),$value); + $severity = ReportStatus::ERROR; + $statusValue = $this->getLanguageService()->getLL('status_wrongValue'); + } else { + $message = $this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet_Ok'); + } + + return GeneralUtility::makeInstance(ReportStatus::class, + $this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet'), + $statusValue, $message, $severity + ); + } + /** * Executes admin commands. * diff --git a/typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf b/typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf index 7e4d0731ca5178eaba091969745b3143c30fa148..ed3a68951fa537085a927aee6adea7c9a9e66356 100644 --- a/typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf +++ b/typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf @@ -15,6 +15,9 @@ <trans-unit id="status_ok"> <source>OK</source> </trans-unit> + <trans-unit id="status_wrongValue"> + <source>Wrong value detected</source> + </trans-unit> <trans-unit id="status_insecure"> <source>Insecure</source> </trans-unit> @@ -39,6 +42,9 @@ <trans-unit id="status_connectionFailed"> <source>Connection Failed</source> </trans-unit> + <trans-unit id="status_checkFailed"> + <source>Check Failed</source> + </trans-unit> <trans-unit id="status_updateComplete"> <source>Update Complete</source> </trans-unit> @@ -96,6 +102,18 @@ <trans-unit id="status_CreatedDirectoryPermissions.writable"> <source>Directories created by TYPO3 are configured to be world writable. Depending on your server configuration, this can be a security risk. It is usually better to configure the create mask to not allow writing to directories by "others". A sane default is often '2770' for $GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']. This can be set in the install tool.</source> </trans-unit> + <trans-unit id="status_MysqlDatabaseCharacterSet"> + <source>MySQL Database Character Set</source> + </trans-unit> + <trans-unit id="status_MysqlDatabaseCharacterSet_CheckFailed"> + <source>Checking database character set failed, got key "%1$s" instead of "character_set_database"</source> + </trans-unit> + <trans-unit id="status_MysqlDatabaseCharacterSet_Unsupported"> + <source>Your database uses character set "%1$s", but only "utf8" is supported with TYPO3.</source> + </trans-unit> + <trans-unit id="status_MysqlDatabaseCharacterSet_Ok"> + <source>Your database uses utf-8. All good.</source> + </trans-unit> <trans-unit id="status_trustedHostsPattern"> <source>Trusted Hosts Pattern</source> </trans-unit>