[BUGFIX] Report module should not alert when all db tables are utf8 51/50351/4
authorBenni Mack <benni@typo3.org>
Mon, 24 Oct 2016 21:01:30 +0000 (23:01 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 25 Oct 2016 19:14:55 +0000 (21:14 +0200)
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: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php
typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf

index 1cd256a..74c688b 100644 (file)
@@ -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');
         }
index 4a5f656..a1fc984 100644 (file)
@@ -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>
                        <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>