[TASK] Migrate ConfigurationStatus 36/49536/6
authorTobias Adolph <mail@tobiasadolph.de>
Mon, 22 Aug 2016 11:45:00 +0000 (13:45 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 22 Aug 2016 17:31:58 +0000 (19:31 +0200)
Resolves: #77578
Releases: master
Change-Id: I34b678c2d23fe118a6d6f8b3dc50976b3e1b5fe6
Reviewed-on: https://review.typo3.org/49536
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/reports/Classes/Report/Status/ConfigurationStatus.php
typo3/sysext/reports/Resources/Private/Language/locallang_reports.xlf

index 3800943..eb66958 100644 (file)
@@ -16,12 +16,12 @@ namespace TYPO3\CMS\Reports\Report\Status;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Reports\Status as ReportStatus;
 use TYPO3\CMS\Reports\StatusProviderInterface;
@@ -267,49 +267,55 @@ class ConfigurationStatus implements StatusProviderInterface
     }
 
     /**
-     * Verifies that MySQL is used.
+     * Checks if the default connection is a MySQL compatible database instance.
      *
      * @return bool
      */
     protected function isMysqlUsed()
     {
-        return get_class($this->getDatabaseConnection()) == DatabaseConnection::class;
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
+
+        return StringUtility::beginsWith($connection->getServerVersion(), 'MySQL');
     }
 
     /**
-     * Checks the character set of the database and reports an error if it is not utf-8.
+     * Checks the character set of the default 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'];
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
+        $queryBuilder = $connection->createQueryBuilder();
+        $defaultDatabaseCharset = (string)$queryBuilder->select('DEFAULT_CHARACTER_SET_NAME')
+            ->from('information_schema.SCHEMATA')
+            ->where(
+                $queryBuilder->expr()->eq('SCHEMA_NAME', $queryBuilder->quote($connection->getDatabase()))
+            )
+            ->setMaxResults(1)
+            ->execute()
+            ->fetchColumn();
 
-        $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);
+        if (!StringUtility::beginsWith($defaultDatabaseCharset, 'utf8')) {
+            $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_Ok');
         }
 
-        return GeneralUtility::makeInstance(ReportStatus::class,
+        return GeneralUtility::makeInstance(
+            ReportStatus::class,
             $this->getLanguageService()->getLL('status_MysqlDatabaseCharacterSet'),
-            $statusValue, $message, $severity
+            $statusValue,
+            $message,
+            $severity
         );
     }
 
@@ -362,12 +368,4 @@ class ConfigurationStatus implements StatusProviderInterface
     {
         return $GLOBALS['LANG'];
     }
-
-    /**
-     * @return DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
index ed3a689..10b5ea6 100644 (file)
                                <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>
+                               <source>Your default database uses character set "%1$s", but only "utf8" or "utf8mb4" is supported with TYPO3.</source>
                        </trans-unit>
                        <trans-unit id="status_MysqlDatabaseCharacterSet_Ok">
-                               <source>Your database uses utf-8. All good.</source>
+                               <source>Your default database uses utf-8. All good.</source>
                        </trans-unit>
                        <trans-unit id="status_trustedHostsPattern">
                                <source>Trusted Hosts Pattern</source>