[BUGFIX] Make language module accessible without internet connection 44/47944/2
authorNicole Cordes <typo3@cordes.co>
Thu, 21 Apr 2016 14:22:48 +0000 (16:22 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Wed, 27 Apr 2016 18:48:18 +0000 (20:48 +0200)
This patch adds the possibility to access the language module without
having an internet connection. You are able to activate and deactivate
languages but trying to update files will give you an error.

Resolves: #75820
Releases: master, 7.6
Change-Id: I27be7f34c76f680a4240e6c75c4a331d96467681
Reviewed-on: https://review.typo3.org/47944
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/lang/Classes/Controller/LanguageController.php
typo3/sysext/lang/Classes/Service/TranslationService.php

index 636c147..333fd82 100644 (file)
@@ -158,7 +158,7 @@ class LanguageController extends ActionController
                 $result = $this->translationService->updateTranslation($extensionKey, $data['locale']);
                 $progress = round((($offset + 1) * 100) / $allCount, 2);
                 $response['result'][$data['locale']][$extensionKey] = $result[$data['locale']];
-                if (empty($result[$extensionKey][$data['locale']]['error'])) {
+                if (empty($result[$data['locale']]['error'])) {
                     $response['success'] = true;
                 } else {
                     // Could not update an extension, stop here!
index 126a66e..2ea06ee 100644 (file)
@@ -65,7 +65,11 @@ class TranslationService implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function injectRepositoryHelper(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $helper)
     {
-        $this->mirrorUrl = $helper->getMirrors(false)->getMirrorUrl();
+        try {
+            $this->mirrorUrl = $helper->getMirrors(false)->getMirrorUrl();
+        } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
+            $this->mirrorUrl = '';
+        }
     }
 
     /**
@@ -102,15 +106,22 @@ class TranslationService implements \TYPO3\CMS\Core\SingletonInterface
      * @param string $extensionKey The extension key
      * @param string $locale Locale to update
      * @return int Translation state
+     * @throws \Exception
      */
     protected function updateTranslationForExtension($extensionKey, $locale)
     {
         if (empty($extensionKey) || empty($locale)) {
             return static::TRANSLATION_INVALID;
         }
+
+        $mirrorUrl = $this->getMirrorUrl($extensionKey);
+        if (empty($mirrorUrl)) {
+            throw new \Exception('Not able to fetch languages files due to missing mirror url.', 1461248062);
+        }
+
         $state = static::TRANSLATION_FAILED;
 
-        $updateResult = $this->terService->updateTranslation($extensionKey, $locale, $this->getMirrorUrl($extensionKey));
+        $updateResult = $this->terService->updateTranslation($extensionKey, $locale, $mirrorUrl);
         if ($updateResult === true) {
             $state = static::TRANSLATION_UPDATED;
         }