[FEATURE] Add scheduler task to update language packages
authorXavier Perseguers <xavier@typo3.org>
Fri, 15 Jun 2012 13:41:47 +0000 (15:41 +0200)
committerGeorg Ringer <mail@ringerge.org>
Mon, 18 Jun 2012 07:46:39 +0000 (09:46 +0200)
A scheduler task is missing to allow language packages to be
regularly updated.

Change-Id: I9af75c5ad24017123668ae5ef7b562b3992189cf
Releases: 6.0
Resolves: #38083
Reviewed-on: http://review.typo3.org/12094
Reviewed-by: Xavier Perseguers
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
typo3/sysext/em/classes/tasks/class.tx_em_tasks_updatelanguagepackages.php [new file with mode: 0644]
typo3/sysext/em/ext_autoload.php
typo3/sysext/em/ext_localconf.php
typo3/sysext/em/language/locallang.xlf

diff --git a/typo3/sysext/em/classes/tasks/class.tx_em_tasks_updatelanguagepackages.php b/typo3/sysext/em/classes/tasks/class.tx_em_tasks_updatelanguagepackages.php
new file mode 100644 (file)
index 0000000..e62ec0d
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Xavier Perseguers <xavier@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Update language packages task.
+ *
+ * @author Xavier Perseguers <xavier@typo3.org>
+ * @package TYPO3
+ * @subpackage em
+ */
+class tx_em_Tasks_UpdateLanguagePackages extends tx_scheduler_Task {
+
+       /**
+        * Must be public to be accessed by tx_em_Connection_Ter
+        * @var tx_em_Tools_XmlHandler
+        */
+       public $xmlHandler;
+
+       /**
+        * @var tx_em_Connection_Ter
+        */
+       protected $terConnection;
+
+       /**
+        * @var tx_em_Settings
+        */
+       protected $emSettings;
+
+       /**
+        * Public method, usually called by scheduler.
+        *
+        * @return boolean TRUE on success
+        */
+       public function execute() {
+                       // Throws exceptions if something goes wrong
+               $this->updateLanguagePackages();
+
+               return TRUE;
+       }
+
+       /**
+        * Updates the language packages and flushes the cache afterwards.
+        *
+        * @return void
+        */
+       protected function updateLanguagePackages() {
+               $this->xmlHandler = t3lib_div::makeInstance('tx_em_Tools_XmlHandler');
+               $this->terConnection = t3lib_div::makeInstance('tx_em_Connection_Ter', $this);
+               $this->emSettings = t3lib_div::makeInstance('tx_em_Settings');
+
+               $emSettings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['em']);
+               $selectedLanguages = t3lib_div::trimExplode(',', $emSettings['selectedLanguages']);
+
+               /** @var $extensionsList tx_em_Extensions_List */
+               $extensionsList = t3lib_div::makeInstance('tx_em_Extensions_List');
+               $installedExtensions = $extensionsList->getInstalledExtensions(TRUE);
+
+               foreach ($installedExtensions as $extension) {
+                       $this->fetchTranslations($extension['extkey'], $selectedLanguages);
+               }
+
+               /** @var $cacheInstance t3lib_cache_frontend_StringFrontend */
+               $cacheInstance = $GLOBALS['typo3CacheManager']->getCache('t3lib_l10n');
+               $cacheInstance->flush();
+       }
+
+       /**
+        * Fetches translation from server.
+        *
+        * @param string $extensionKey
+        * @param array $languages
+        * @return void
+        * @see tx_em_Connection_ExtDirectServer::fetchTranslations()
+        */
+       protected function fetchTranslations($extensionKey, array $languages) {
+               if (count($languages) > 0) {
+                       $mirrorURL = $this->emSettings->getMirrorURL();
+
+                       foreach ($languages as $language) {
+                               $fetch = $this->terConnection->fetchTranslationStatus($extensionKey, $mirrorURL);
+
+                               $localmd5 = '';
+                               if (isset($fetch[$language])) {
+                                       $zip = PATH_site . 'typo3temp/' . $extensionKey . '-l10n-' . $language . '.zip';
+                                       if (is_file($zip)) {
+                                               $localmd5 = md5_file($zip);
+                                       }
+                                       if ($localmd5 !== $fetch[$language]['md5']) {
+                                                       // Fetch translation
+                                               $this->terConnection->updateTranslation($extensionKey, $language, $mirrorURL);
+                                       }
+                               }
+                       }
+               }
+       }
+
+}
+?>
\ No newline at end of file
index 1870b7a..34d5bf1 100644 (file)
@@ -46,6 +46,7 @@ return array(
        'tx_em_settings' => $emClassesPath . 'settings/class.tx_em_settings.php',
 
        'tx_em_tasks_updateextensionlist' => $emClassesPath . 'tasks/class.tx_em_tasks_updateextensionlist.php',
+       'tx_em_tasks_updatelanguagepackages' => $emClassesPath . 'tasks/class.tx_em_tasks_updatelanguagepackages.php',
 
        'tx_em_tools' => $emClassesPath . 'tools/class.tx_em_tools.php',
        'tx_em_tools_unzip' => $emClassesPath . 'tools/class.tx_em_tools_unzip.php',
index fe61299..768eb81 100644 (file)
@@ -6,8 +6,16 @@ if (!defined ('TYPO3_MODE')) {
        // Register extension list update task
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_em_Tasks_UpdateExtensionList'] = array(
        'extension'        => $_EXTKEY,
-       'title'            => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xml:tasks_updateExtensionlistTask.name',
-       'description'      => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xml:tasks_updateExtensionlistTask.description',
+       'title'            => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xlf:tasks_updateExtensionlistTask.name',
+       'description'      => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xlf:tasks_updateExtensionlistTask.description',
+       'additionalFields' => '',
+);
+
+       // Register language package update task
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_em_Tasks_UpdateLanguagePackages'] = array(
+       'extension'        => $_EXTKEY,
+       'title'            => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xlf:tasks_updateLanguagePackagesTask.name',
+       'description'      => 'LLL:EXT:' . $_EXTKEY . '/language/locallang.xlf:tasks_updateLanguagePackagesTask.description',
        'additionalFields' => '',
 );
 ?>
\ No newline at end of file
index 0a97cd0..af2a5d3 100644 (file)
@@ -9,6 +9,12 @@
                        <trans-unit id="tasks_updateExtensionlistTask.description" xml:space="preserve">
                                <source>Update the extension list on a regular basis. Once a day is a good interval.</source>
                        </trans-unit>
+                       <trans-unit id="tasks_updateLanguagePackagesTask.name" xml:space="preserve">
+                               <source>Update Language Packages</source>
+                       </trans-unit>
+                       <trans-unit id="tasks_updateLanguagePackagesTask.description" xml:space="preserve">
+                               <source>Update the language packages on a regular basis. Once a week is a good interval.</source>
+                       </trans-unit>
                        <trans-unit id="mlang_labels_tablabel" xml:space="preserve">
                                <source>TYPO3 Extension Manager</source>
                        </trans-unit>