[BUGFIX] Make language module accessible without internet connection 40/47840/3
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:41:15 +0000 (20:41 +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/47840
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-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 37c916d..e5e3ee4 100644 (file)
@@ -166,7 +166,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 325bd14..41dc1a0 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Lang\Service;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
+use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
 use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper;
 
 /**
@@ -70,7 +71,11 @@ class TranslationService implements SingletonInterface
      */
     public function injectRepositoryHelper(Helper $helper)
     {
-        $this->mirrorUrl = $helper->getMirrors(false)->getMirrorUrl();
+        try {
+            $this->mirrorUrl = $helper->getMirrors(false)->getMirrorUrl();
+        } catch (ExtensionManagerException $e) {
+            $this->mirrorUrl = '';
+        }
     }
 
     /**
@@ -108,15 +113,22 @@ class TranslationService implements 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;
         }