[TASK] Re-implement update TER extension list task
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 3 Nov 2012 14:55:13 +0000 (15:55 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 3 Nov 2012 15:45:12 +0000 (16:45 +0100)
The scheduler task to update the TER extension list on a regular basis
was removed with the implementation of the new extension manager.
The patch adds an updated version of it and takes care that
existing registered tasks of this type still work.

Change-Id: Ic770ed78f23413b589352c25998eaee7863ec64f
Resolves: #39915
Releases: 6.0
Reviewed-on: http://review.typo3.org/16168
Reviewed-by: Felix Kopp
Tested-by: Felix Kopp
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Classes/Task/UpdateExtensionListTask.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Migrations/Code/ClassAliasMap.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Resources/Private/Language/locallang.xlf
typo3/sysext/extensionmanager/Tests/Unit/Task/UpdateExtensionListTaskTest.php [new file with mode: 0644]
typo3/sysext/extensionmanager/ext_localconf.php

diff --git a/typo3/sysext/extensionmanager/Classes/Task/UpdateExtensionListTask.php b/typo3/sysext/extensionmanager/Classes/Task/UpdateExtensionListTask.php
new file mode 100644 (file)
index 0000000..b056efe
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Task;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Christian Kuhn <lolli@schwarzbu.ch>
+ *  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 extension list from TER task
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ */
+class UpdateExtensionListTask extends \TYPO3\CMS\Scheduler\Task {
+
+       /**
+        * Public method, called by scheduler.
+        *
+        * @return boolean TRUE on success
+        */
+       public function execute() {
+               // Throws exceptions if something went wrong
+               $this->updateExtensionlist();
+
+               return TRUE;
+       }
+
+       /**
+        * Update extension list
+        *
+        * @TODO: Adapt to multiple repositories if the Helper can handle this
+        * @return void
+        */
+       protected function updateExtensionlist() {
+               /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
+               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               /** @var $repositoryHelper \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper */
+               $repositoryHelper = $objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper');
+               $repositoryHelper->updateExtList();
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extensionmanager/Migrations/Code/ClassAliasMap.php b/typo3/sysext/extensionmanager/Migrations/Code/ClassAliasMap.php
new file mode 100644 (file)
index 0000000..5576eef
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+return array(
+       'tx_em_Tasks_UpdateExtensionList' => 'TYPO3\\CMS\\Extensionmanager\\Task\\UpdateExtensionListTask',
+);
+?>
\ No newline at end of file
index 0efeff3..b98ff8f 100644 (file)
                        <trans-unit id="extensionList.updateFromTer.label" xml:space="preserve">
                                <source>Update Extension List</source>
                        </trans-unit>
                        <trans-unit id="extensionList.updateFromTer.label" xml:space="preserve">
                                <source>Update Extension List</source>
                        </trans-unit>
+                       <trans-unit id="task.updateExtensionListTask.name" xml:space="preserve">
+                               <source>Update extension list</source>
+                       </trans-unit>
+                       <trans-unit id="task.updateExtensionListTask.description" xml:space="preserve">
+                               <source>Update TER extension list on a regular basis. Once a day is a good interval.</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
                </body>
        </file>
 </xliff>
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Task/UpdateExtensionListTaskTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Task/UpdateExtensionListTaskTest.php
new file mode 100644 (file)
index 0000000..4844e62
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Task;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2012 Christian Kuhn <lolli@schwarzbu.ch>
+ *  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!
+ ***************************************************************/
+
+/**
+ * Test case
+ *
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ */
+class UpdateExtensionListTaskTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var array A backup of registered singleton instances
+        */
+       protected $singletonInstances = array();
+
+       /**
+        * Set up
+        */
+       public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+       }
+
+       /**
+        * Tear down
+        */
+       public function tearDown() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+       }
+
+       /**
+        * @test
+        */
+       public function executeCallsUpdateExtListOfRepositoryHelper() {
+               $repositoryHelperMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper');
+               $repositoryHelperMock
+                               ->expects($this->once())
+                               ->method('updateExtList');
+
+               $objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $objectManagerMock
+                               ->expects($this->once())
+                               ->method('get')
+                               ->with('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper')
+                               ->will($this->returnValue($repositoryHelperMock));
+
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', $objectManagerMock);
+
+               $task = new \TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask();
+               $task->execute();
+       }
+}
+?>
\ No newline at end of file
index 948199d..f2dc782 100644 (file)
@@ -2,4 +2,12 @@
 if (!defined('TYPO3_MODE')) {
        die('Access denied.');
 }
 if (!defined('TYPO3_MODE')) {
        die('Access denied.');
 }
+
+// Register extension list update task
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['TYPO3\\CMS\\Extensionmanager\\Task\\UpdateExtensionListTask'] = array(
+       'extension' => $_EXTKEY,
+       'title' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.name',
+       'description' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xlf:task.updateExtensionListTask.description',
+       'additionalFields' => '',
+);
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file