[TASK] Install Tool checks for system locale 10/27510/6
authorZbigniew Jacko <z.jacko@macopedia.pl>
Sun, 9 Feb 2014 12:55:00 +0000 (13:55 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Fri, 14 Feb 2014 15:44:26 +0000 (16:44 +0100)
Add two new functions to check if 'systemLocale'
setting is correct and if configured 'systemLocale'
supports UTF-8 when 'UTF8filesystem' is set.

Resolves: #55721
Releases: 6.2
Change-Id: Id9edfc896a87d5025a5170690a6b7d6eb25950e6
Reviewed-on: https://review.typo3.org/27510
Reviewed-by: Markus Klein
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/install/Classes/SystemEnvironment/Check.php

index 16fbe51..138e678 100644 (file)
@@ -107,6 +107,8 @@ class Check {
                $statusArray[] = $this->checkSuhosinExecutorIncludeWhitelistContainsVfs();
                $statusArray[] = $this->checkSomePhpOpcodeCacheIsLoaded();
                $statusArray[] = $this->checkReflectionDocComment();
+               $statusArray[] = $this->checkSystemLocale();
+               $statusArray[] = $this->checkLocaleWithUTF8filesystem();
                $statusArray[] = $this->checkWindowsApacheThreadStackSize();
                foreach ($this->requiredPhpExtensions as $extension) {
                        $statusArray[] = $this->checkRequiredPhpExtension($extension);
@@ -794,6 +796,84 @@ class Check {
        }
 
        /**
+        * Check if systemLocale setting is correct (locale exists in the OS)
+        *
+        * @return Status\StatusInterface
+        */
+       protected function checkSystemLocale() {
+
+               $currentLocale = setlocale(LC_CTYPE, 0);
+
+               // On Windows an empty locale value uses the regional settings from the Control Panel
+               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
+                       $status = new Status\InfoStatus();
+                       $status->setTitle('Empty systemLocale setting');
+                       $status->setMessage(
+                               '$GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is not set. This is fine as long as no UTF-8 file system is used.'
+                       );
+               } elseif (setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']) === FALSE) {
+                       $status = new Status\ErrorStatus();
+                       $status->setTitle('Incorrect systemLocale setting');
+                       $status->setMessage(
+                               'Current value of the $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is incorrect. Locale with this name doesn\'t exist in the operating system.'
+                       );
+                       setlocale(LC_CTYPE, $currentLocale);
+               } else {
+                       $status = new Status\OkStatus();
+                       $status->setTitle('System locale is correct');
+               }
+
+               return $status;
+       }
+
+       /**
+        * Checks whether we can use file names with UTF-8 characters.
+        * Configured system locale must support UTF-8 when UTF8filesystem is set
+        *
+        * @return Status\StatusInterface
+        */
+       protected function checkLocaleWithUTF8filesystem() {
+
+               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
+
+                       // On Windows an empty local value uses the regional settings from the Control Panel
+                       if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] === '' && TYPO3_OS !== 'WIN') {
+                               $status = new Status\ErrorStatus();
+                               $status->setTitle('System locale not set on UTF-8 file system');
+                               $status->setMessage(
+                                       '$GLOBALS[TYPO3_CONF_VARS][SYS][UTF8filesystem] is set, but $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] is empty. Make sure a valid locale which supports UTF-8 is set.'
+                               );
+                       } else {
+                               $testString = 'ÖöĄĆŻĘĆćążąęó.jpg';
+                               $currentLocale = setlocale(LC_CTYPE, 0);
+                               $quote = TYPO3_OS === 'WIN' ? '"' : '\'';
+
+                               setlocale(LC_CTYPE, $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']);
+
+                               if (escapeshellarg($testString) === $quote . $testString . $quote) {
+                                       $status = new Status\OkStatus();
+                                       $status->setTitle('File names with UTF-8 characters can be used.');
+                               } else {
+                                       $status = new Status\ErrorStatus();
+                                       $status->setTitle('System locale setting doesn\'t support UTF-8 file names.');
+                                       $status->setMessage(
+                                               'Please check your $GLOBALS[TYPO3_CONF_VARS][SYS][systemLocale] setting.'
+                                       );
+                               }
+
+                               setlocale(LC_CTYPE, $currentLocale);
+                       }
+
+
+               } else {
+                       $status = new Status\OkStatus();
+                       $status->setTitle('Skipping test, as UTF8filesystem is not enabled.');
+               }
+
+               return $status;
+       }
+
+       /**
         * Checks thread stack size if on windows with apache
         *
         * @return Status\StatusInterface