Skip to content
Snippets Groups Projects
Commit a67d926e authored by Benni Mack's avatar Benni Mack Committed by Christian Kuhn
Browse files

[BUGFIX] Report module should not alert when all db tables are utf8

In case a database default character set is latin1 but all tables
created in the database are utf8, the reports module warns that
the db is configured wrong, which might be the case, but on certain
hosters this is not an excuse. Instead, all TYPO3 tables
are created with a utf8 collation (equiv. to utf8 character set) and
stored correctly, so there is no need to throw a big red box.

The patch extends the utf-8 check to see if all database tables
are utf8 and everything is fine.

Resolves: #78413
Releases: master
Change-Id: I78cc65e4fec58e40f41f36ec6dbf6d46e867246f
Reviewed-on: https://review.typo3.org/50351


Reviewed-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent dbc97538
Branches
Tags
No related merge requests found
......@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Reports\Report\Status;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Registry;
......@@ -288,6 +289,7 @@ class ConfigurationStatus implements StatusProviderInterface
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $connection->createQueryBuilder();
$defaultDatabaseCharset = (string)$queryBuilder->select('DEFAULT_CHARACTER_SET_NAME')
->from('information_schema.SCHEMATA')
......@@ -302,10 +304,29 @@ class ConfigurationStatus implements StatusProviderInterface
$statusValue = $this->getLanguageService()->getLL('status_ok');
// also allow utf8mb4
if (!StringUtility::beginsWith($defaultDatabaseCharset, 'utf8')) {
$message = sprintf($this->getLanguageService()
->getLL('status_MysqlDatabaseCharacterSet_Unsupported'), $defaultDatabaseCharset);
$severity = ReportStatus::ERROR;
$statusValue = $this->getLanguageService()->getLL('status_wrongValue');
// If the default character set is e.g. latin1, BUT all tables in the system are UTF-8,
// we assume that TYPO3 has the correct charset for adding tables, and everything is fine
$nonUtf8TableCollationsFound = $queryBuilder->select('table_collation')
->from('information_schema.tables')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq('table_schema', $queryBuilder->quote($connection->getDatabase())),
$queryBuilder->expr()->notLike('table_collation', $queryBuilder->quote('utf8%'))
)
)
->setMaxResults(1)
->execute();
if ($nonUtf8TableCollationsFound->rowCount() > 0) {
$message = sprintf($this->getLanguageService()
->getLL('status_MysqlDatabaseCharacterSet_Unsupported'), $defaultDatabaseCharset);
$severity = ReportStatus::ERROR;
$statusValue = $this->getLanguageService()->getLL('status_wrongValue');
} else {
$message = $this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet_Info');
$severity = ReportStatus::INFO;
$statusValue = $this->getLanguageService()->getLL('status_info');
}
} else {
$message = $this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet_Ok');
}
......
......@@ -18,6 +18,9 @@
<trans-unit id="status_wrongValue">
<source>Wrong value detected</source>
</trans-unit>
<trans-unit id="status_info">
<source>Information</source>
</trans-unit>
<trans-unit id="status_insecure">
<source>Insecure</source>
</trans-unit>
......@@ -114,6 +117,9 @@
<trans-unit id="status_MysqlDatabaseCharacterSet_Ok">
<source>Your default database uses utf-8. All good.</source>
</trans-unit>
<trans-unit id="status_MysqlDatabaseCharacterSet_Info">
<source>Your default database uses a different charset, but all tables uses utf-8. All good. But consider fixing your database collation and check the table creation settings.</source>
</trans-unit>
<trans-unit id="status_trustedHostsPattern">
<source>Trusted Hosts Pattern</source>
</trans-unit>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment