[TASK] Remove needless check function in language module
authorKai Vogel <kai.vogel@speedprogs.de>
Wed, 10 Oct 2012 09:27:57 +0000 (11:27 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 28 Oct 2012 16:52:46 +0000 (17:52 +0100)
This patch removes the check function and related to that, the use of
the caching framework.

Resolves: #41824
Related: #39963
Releases: 6.0

Change-Id: I3d3de72c287a9b1167f0d1ea563f16994fd0ffe3
Reviewed-on: http://review.typo3.org/15475
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/lang/Classes/Controller/LanguageController.php
typo3/sysext/lang/Resources/Private/Language/locallang.xlf
typo3/sysext/lang/Resources/Private/Layouts/Default.html
typo3/sysext/lang/Resources/Private/Partials/TranslationUpdateList.html
typo3/sysext/lang/Resources/Private/Templates/Language/Index.html
typo3/sysext/lang/Resources/Public/JavaScript/LangModule.js
typo3/sysext/lang/ext_localconf.php
typo3/sysext/lang/ext_tables.php

index cede597..cb07cde 100644 (file)
@@ -43,6 +43,7 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
        const TRANSLATION_FAILED = 2;
        const TRANSLATION_OK = 3;
        const TRANSLATION_INVALID = 4;
+       const TRANSLATION_UPDATED = 5;
 
        /**
         * @var \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository
@@ -64,27 +65,16 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
         */
        protected $terConnection;
 
-       /**
-        * @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
-        */
-       protected $cache;
-
        /**
         * @var array
         */
-       protected $icons = array();
-
-       /**
-        * Keep cache for one day
-        * @var integer
-        */
-       protected $cacheLifetime = 86400;
+       protected $translationStates = array();
 
        /**
         * JSON actions
         * @var array
         */
-       protected $jsonActions = array('checkTranslation', 'updateTranslation');
+       protected $jsonActions = array('updateTranslation');
 
        /**
         * Inject the language repository
@@ -142,20 +132,6 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                }
        }
 
-       /**
-        * Initialize cache frontend
-        *
-        * @return void
-        */
-       public function initializeAction() {
-               $cacheIdentifier = $this->request->getControllerExtensionKey();
-               $cacheFrontend = $GLOBALS['typo3CacheManager'];
-               if (!$cacheFrontend->hasCache($cacheIdentifier)) {
-                       throw new \Exception('The cache with identifier "' . $cacheIdentifier . '" is not available.', 1341301708);
-               }
-               $this->cache = $cacheFrontend->getCache($cacheIdentifier);
-       }
-
        /**
         * Index action
         *
@@ -194,16 +170,14 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                $this->redirect('index');
        }
 
-
        /**
-        * Check translation state for one extension
+        * Update translation for one extension
         *
         * @param string $extension The extension key
-        * @param mixed $locales List or array of locales to check
-        * @param boolean $update Update translations if is TRUE
+        * @param mixed $locales List or array of locales to update
         * @return void
         */
-       public function checkTranslationAction($extension, $locales, $update = FALSE) {
+       public function updateTranslationAction($extension, $locales) {
                if (is_string($locales)) {
                        $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $locales);
                }
@@ -213,7 +187,7 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                        $state = static::TRANSLATION_INVALID;
                        try {
                                $state = $this->getTranslationStateForExtension($extension, $locale);
-                               if ($update && $state === static::TRANSLATION_AVAILABLE) {
+                               if ($state === static::TRANSLATION_AVAILABLE) {
                                        $state = $this->updateTranslationForExtension($extension, $locale);
                                }
                        } catch (\Exception $exception) {
@@ -229,17 +203,6 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                $this->view->assign('locales', $locales);
        }
 
-       /**
-        * Update translation for one extension
-        *
-        * @param string $extension The extension key
-        * @param mixed $locales List or array of locales to update
-        * @return void
-        */
-       public function updateTranslationAction($extension, $locales) {
-               $this->checkTranslationAction($extension, $locales, TRUE);
-       }
-
        /**
         * Returns the translation state for an extension
         *
@@ -252,47 +215,39 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                        return static::TRANSLATION_INVALID;
                }
 
-               $identifier = 'translationState-' .  $extensionKey . '-' . $locale;
-               if ($this->cache->has($identifier)) {
-                       return $this->cache->get($identifier);
+               $identifier = $extensionKey . '-' . $locale;
+               if (isset($this->translationStates[$identifier])) {
+                       return $this->translationStates[$identifier];
                }
 
                $selectedLanguages = $this->languageRepository->findSelected();
-               if (empty($selectedLanguages)) {
+               if (empty($selectedLanguages) || !is_array($selectedLanguages)) {
                        return static::TRANSLATION_INVALID;
                }
 
                $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
                $status = $this->terConnection->fetchTranslationStatus($extensionKey, $mirrorUrl);
-               $states = array();
 
                foreach ($selectedLanguages as $language) {
-                       $selectedLocale = $language->getLocale();
+                       $stateLocale = $language->getLocale();
+                       $stateIdentifier = $extensionKey . '-' . $stateLocale;
+                       $this->translationStates[$stateIdentifier] = static::TRANSLATION_INVALID;
 
-                       if (empty($status[$selectedLocale]) || !is_array($status[$selectedLocale])) {
-                               $states[$selectedLocale] = static::TRANSLATION_NOT_AVAILABLE;
+                       if (empty($status[$stateLocale]) || !is_array($status[$stateLocale])) {
+                               $this->translationStates[$stateIdentifier] = static::TRANSLATION_NOT_AVAILABLE;
                                continue;
                        }
 
-                       $md5 = $this->getTranslationFileMd5($extensionKey, $selectedLocale);
-                       if ($md5 !== $status[$selectedLocale]['md5']) {
-                               $states[$selectedLocale] = static::TRANSLATION_AVAILABLE;
+                       $md5 = $this->getTranslationFileMd5($extensionKey, $stateLocale);
+                       if ($md5 !== $status[$stateLocale]['md5']) {
+                               $this->translationStates[$stateIdentifier] = static::TRANSLATION_AVAILABLE;
                                continue;
                        }
 
-                       $states[$selectedLocale] = static::TRANSLATION_OK;
-               }
-
-               if (!isset($states[$locale])) {
-                       $states[$locale] = static::TRANSLATION_INVALID;
-               }
-
-               foreach ($states as $stateLocale => $state) {
-                       $identifier = 'translationState-' .  $extensionKey . '-' . $stateLocale;
-                       $this->cache->set($identifier, $state, array(), $this->cacheLifetime);
+                       $this->translationStates[$stateIdentifier] = static::TRANSLATION_OK;
                }
 
-               return $states[$locale];
+               return $this->translationStates[$identifier];
        }
 
        /**
@@ -329,12 +284,9 @@ class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
                $updateResult = $this->terConnection->updateTranslation($extensionKey, $locale, $mirrorUrl);
                if ($updateResult === TRUE) {
-                       $state = static::TRANSLATION_OK;
+                       $state = static::TRANSLATION_UPDATED;
                }
 
-               $identifier = 'translationState-' .  $extensionKey . '-' . $locale;
-               $this->cache->set($identifier, $state, array(), $this->cacheLifetime);
-
                return $state;
        }
 
index 09b8e85..fe07422 100644 (file)
@@ -9,9 +9,6 @@
                        <trans-unit id="state.notAvailable" xml:space="preserve">
                                <source>Not available</source>
                        </trans-unit>
-                       <trans-unit id="state.updateAvailable" xml:space="preserve">
-                               <source>Update available</source>
-                       </trans-unit>
                        <trans-unit id="state.failed" xml:space="preserve">
                                <source>Failed</source>
                        </trans-unit>
@@ -21,6 +18,9 @@
                        <trans-unit id="state.invalid" xml:space="preserve">
                                <source>Invalid</source>
                        </trans-unit>
+                       <trans-unit id="state.updated" xml:space="preserve">
+                               <source>Updated</source>
+                       </trans-unit>
                        <trans-unit id="state.checking" xml:space="preserve">
                                <source>Checking...</source>
                        </trans-unit>
@@ -28,9 +28,6 @@
                                <source>Not checked</source>
                        </trans-unit>
 
-                       <trans-unit id="button.check" xml:space="preserve">
-                               <source>Check against repository</source>
-                       </trans-unit>
                        <trans-unit id="button.update" xml:space="preserve">
                                <source>Update from repository</source>
                        </trans-unit>
@@ -60,9 +57,6 @@
                        <trans-unit id="flashmessage.multipleErrors" xml:space="preserve">
                                <source>Several requests have been failed. Please check your internet connection!</source>
                        </trans-unit>
-                       <trans-unit id="flashmessage.checkComplete" xml:space="preserve">
-                               <source>The translation check has been successfully completed.</source>
-                       </trans-unit>
                        <trans-unit id="flashmessage.updateComplete" xml:space="preserve">
                                <source>The translation update has been successfully completed.</source>
                        </trans-unit>
index 262df94..d84f0b0 100644 (file)
@@ -20,9 +20,8 @@
                1: 'flashmessage.information',
                2: 'flashmessage.success',
                3: 'flashmessage.multipleErrors',
-               4: 'flashmessage.checkComplete',
-               5: 'flashmessage.updateComplete',
-               6: 'flashmessage.canceled'
+               4: 'flashmessage.updateComplete',
+               5: 'flashmessage.canceled'
        }"
        >
        <div class="typo3-fullDoc">
index 60636fa..9f093d0 100644 (file)
@@ -14,7 +14,6 @@
                <f:for each="{extensions}" as="extension">
                        <tr
                                class="translationListRow"
-                               data-checkurl="<f:uri.action action="checkTranslation" arguments="{extension:'{extension.key}', locales:'{languageSelectionForm.selectedLanguagesLocaleList}'}" />"
                                data-updateurl="<f:uri.action action="updateTranslation" arguments="{extension:'{extension.key}', locales:'{languageSelectionForm.selectedLanguagesLocaleList}'}" />"
                        >
                                <td class="icon">
@@ -26,7 +25,6 @@
                                                class="language languageStateNone translationListCell"
                                                data-extension="{extension.key}"
                                                data-locale="{selectedLanguage.locale}"
-                                               data-checkurl="<f:uri.action action="checkTranslation" arguments="{extension:'{extension.key}', locales:'{selectedLanguage.locale}'}" />"
                                                data-updateurl="<f:uri.action action="updateTranslation" arguments="{extension:'{extension.key}', locales:'{selectedLanguage.locale}'}" />"
                                        >
                                                <span class="stateIconNone"><f:translate key="state.notChecked"/></span>
index c16f545..ebb52fb 100644 (file)
@@ -6,8 +6,6 @@
 <f:section name="iconButtons">
        <span class="menuItem updateItem"><lang:be.spriteIcon icon="actions-system-extension-download" title="{f:translate(key:'button.update')}" /><f:translate key="button.update"/></span>
        &nbsp;
-       <span class="menuItem checkItem"><lang:be.spriteIcon icon="actions-system-refresh" title="{f:translate(key:'button.check')}" /><f:translate key="button.check"/></span>
-       &nbsp;
        <span class="menuItem cancelItem"><lang:be.spriteIcon icon="status-status-permission-denied" title="{f:translate(key:'button.cancel')}" /><f:translate key="button.cancel"/></span>
 </f:section>
 
@@ -48,6 +46,9 @@
                <span class="stateIcon" id="stateIcon4">
                        <lang:be.spriteIcon icon="status-status-permission-denied" /><f:translate key="state.invalid"/>
                </span>
+               <span class="stateIcon" id="stateIcon5">
+                       <lang:be.spriteIcon icon="status-status-checked" /><f:translate key="state.updated"/>
+               </span>
                <span class="stateIcon" id="stateIconChecking">
                        <span class="stateIconChecking"><f:translate key="state.checking"/></span>
                </span>
index 09b0f9f..3f46229 100644 (file)
@@ -18,7 +18,8 @@ var languageModule = {
                available: 1,
                failed: 2,
                ok: 3,
-               invalid: 4
+               invalid: 4,
+               updated: 5
        },
 
        /**
@@ -74,10 +75,9 @@ var languageModule = {
         * Execute AJAX call for given cell of the translation matrix
         *
         * @param mixed cell The cell to process
-        * @param string type Type of the AJAX call
         * @return void
         */
-       processCell: function(cell, type) {
+       processCell: function(cell) {
                        // Intialize
                var $cell = jQuery(cell);
                languageModule.toggleEventHandlers('off');
@@ -85,7 +85,7 @@ var languageModule = {
                $cell.html(jQuery('#stateIconChecking').html());
 
                        // Process AJAX call
-               languageModule.executeAjaxCall($cell.data(type + 'url'), function(response, error) {
+               languageModule.executeAjaxCall($cell.data('updateurl'), function(response, error) {
                        var state = 'Error';
                        if (error === undefined || error === null) {
                                var locale = $cell.data('locale');
@@ -98,7 +98,7 @@ var languageModule = {
                                return;
                        }
                        languageModule.updateCellState($cell, state);
-                       languageModule.displaySuccess('flashmessage.' + type + 'Complete');
+                       languageModule.displaySuccess('flashmessage.updateComplete');
                        languageModule.toggleEventHandlers('on');
                });
        },
@@ -107,10 +107,9 @@ var languageModule = {
         * Execute AJAX calls for given rows of the translation matrix
         *
         * @param mixed rows Rows to process
-        * @param string type Type of the AJAX call
         * @return void
         */
-       processRows: function(rows, type) {
+       processRows: function(rows) {
                        // Intialize processing within first run
                if (rows) {
                        languageModule.addElementsToStack(rows);
@@ -120,7 +119,7 @@ var languageModule = {
 
                        // Stop processing if stack is empty
                if (languageModule.isStackEmpty()) {
-                       languageModule.displaySuccess('flashmessage.' + type + 'Complete');
+                       languageModule.displaySuccess('flashmessage.updateComplete');
                        languageModule.toggleEventHandlers('on');
                        return;
                }
@@ -137,7 +136,7 @@ var languageModule = {
                $cells.html(jQuery('#stateIconChecking').html());
 
                        // Process AJAX call
-               languageModule.executeAjaxCall($row.data(type + 'url'), function(response, error) {
+               languageModule.executeAjaxCall($row.data('updateurl'), function(response, error) {
                        if (error !== undefined && error !== null) {
                                $cells.html(jQuery('#stateIconError').html());
                                if (error === 'abort') {
@@ -158,7 +157,7 @@ var languageModule = {
                                        languageModule.updateCellState($cell, state);
                                });
                        }
-                       languageModule.processRows(null, type);
+                       languageModule.processRows();
                });
        },
 
@@ -225,21 +224,16 @@ var languageModule = {
                var className = 'waiting';
                var fadeSpeed = 150;
                if (action === 'on') {
-                       jQuery('.checkItem').on('click', languageModule.checkTranslations).removeClass(className);
                        jQuery('.updateItem').on('click', languageModule.updateTranslations).removeClass(className);
                        jQuery('.cancelItem').off().fadeOut(fadeSpeed);
                        jQuery('.selectionList input, .selectionList label').off().parent().removeClass(className);
                        jQuery('.selectionList input:checkbox').on('change', languageModule.submitSelectionForm);
                        jQuery('.selectionList tr, .selectionList td').removeClass(className);
                        jQuery('.translationList tr, .translationList td').removeClass(className);
-                       jQuery('.languageState1').on('click', function() {
-                               languageModule.updateSingleTranslation(this);
-                       });
                        jQuery('.languageStateNone').on('click', function() {
-                               languageModule.checkSingleTranslation(this);
+                               languageModule.updateSingleTranslation(this);
                        });
                } else {
-                       jQuery('.checkItem').off().addClass(className);
                        jQuery('.updateItem').off().addClass(className);
                        jQuery('.cancelItem').on('click', languageModule.cancelProcess).fadeIn(fadeSpeed);
                        jQuery('.selectionList input:checkbox').off();
@@ -248,7 +242,6 @@ var languageModule = {
                        }).parent().addClass(className);
                        jQuery('.selectionList tr, .selectionList td').addClass(className);
                        jQuery('.translationList tr, .translationList td').addClass(className);
-                       jQuery('.languageState1').off();
                        jQuery('.languageStateNone').off();
                }
        },
@@ -328,31 +321,13 @@ var languageModule = {
                jQuery('form[name="languageSelectionForm"]').submit();
        },
 
-       /**
-        * Check for new translations
-        *
-        * @return void
-        */
-       checkTranslations: function() {
-               languageModule.processRows('.translationListRow', 'check');
-       },
-
-       /**
-        * Check for new translation for a single element
-        *
-        * @return void
-        */
-       checkSingleTranslation: function(element) {
-               languageModule.processCell(element, 'check');
-       },
-
        /**
         * Update translations
         *
         * @return void
         */
        updateTranslations: function() {
-               languageModule.processRows('.translationListRow', 'update');
+               languageModule.processRows('.translationListRow');
        },
 
        /**
@@ -362,7 +337,7 @@ var languageModule = {
         * @return void
         */
        updateSingleTranslation: function(element) {
-               languageModule.processCell(element, 'update');
+               languageModule.processCell(element);
        },
 
        /**
index 84ce01d..be9ab19 100644 (file)
@@ -18,10 +18,4 @@ if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['cache']['clear_menu']) &&
 }
 // Register Ajax call
 $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['lang::clearCache'] = 'TYPO3\CMS\Lang\LanguageCacheClearer->clearCache';
-
-       // Register cache
-if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$_EXTKEY])
- || !is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$_EXTKEY])) {
-       $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$_EXTKEY] = array();
-}
 ?>
\ No newline at end of file
index 48be578..29442e6 100644 (file)
@@ -12,7 +12,7 @@ if (TYPO3_MODE == 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
                'after:extensionmanager', // Position
                array(
                                // An array holding the controller-action-combinations that are accessible
-                       'Language' => 'index, updateLanguageSelection, checkTranslation, updateTranslation'
+                       'Language' => 'index, updateLanguageSelection, updateTranslation'
                ),
                array(
                        'access' => 'admin',