[BUGFIX] Do not fetch extension list on every request
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 18 Aug 2012 22:25:04 +0000 (00:25 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sun, 19 Aug 2012 08:40:32 +0000 (10:40 +0200)
Due to comparing a DateTime object with an integer
the extension list is fetched every time when switching
to the get extensions tab in the extension manager.

Convert the DateTime object to a timestamp first and
add a test which ensure this works.

Additionally clean up the doc comment of that
property in the model and use forceUpdateCheck
as action parameter in the controller.

Change-Id: I71f6599a6fa41115515c1764deb26e8e56762f4f
Resolves: #39944
Releases: 6.0
Reviewed-on: http://review.typo3.org/13905
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
typo3/sysext/extensionmanager/Classes/Controller/UpdateFromTerController.php
typo3/sysext/extensionmanager/Classes/Domain/Model/Repository.php
typo3/sysext/extensionmanager/Tests/Controller/UpdateFromTerControllerTest.php

index 3f62a79..1724b14 100644 (file)
@@ -95,18 +95,16 @@ class Tx_Extensionmanager_Controller_UpdateFromTerController extends Tx_Extensio
        /**
         * Update extension list from TER
         *
+        * @param boolean $forceUpdateCheck
         * @return void
         */
-       public function updateExtensionListFromTerAction() {
+       public function updateExtensionListFromTerAction($forceUpdateCheck) {
                $updated = FALSE;
-               $forceUpdateCheck = FALSE;
                $errorMessage = '';
-               if ($this->request->hasArgument('forceUpdateCheck') && (int)$this->request->getArgument('forceUpdateCheck') == 1) {
-                       $forceUpdateCheck = TRUE;
-               }
+
                /** @var $repository Tx_Extensionmanager_Domain_Model_Repository */
                $repository = $this->repositoryRepository->findOneByUid((int)$this->settings['repositoryUid']);
-               if ($repository->getLastUpdate() < ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60) || $forceUpdateCheck) {
+               if ($repository->getLastUpdate()->getTimestamp() < ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60) || $forceUpdateCheck) {
                        try {
                                $updated = $this->repositoryHelper->updateExtList();
                        } catch (Tx_Extensionmanager_Exception_ExtensionManager $e) {
index 8eeff39..1144291 100644 (file)
@@ -188,7 +188,7 @@ class Tx_Extensionmanager_Domain_Model_Repository extends Tx_Extbase_DomainObjec
         * Method returns LastUpdate.
         *
         * @access public
-        * @return int timestamp of last update
+        * @return DateTime timestamp of last update
         */
        public function getLastUpdate() {
                return $this->lastUpdate;
@@ -198,10 +198,10 @@ class Tx_Extensionmanager_Domain_Model_Repository extends Tx_Extbase_DomainObjec
         * Method sets LastUpdate.
         *
         * @access public
-        * @param int $time URL of repository WSDL
+        * @param DateTime $time URL of repository WSDL
         * @return void
         */
-       public function setLastUpdate($time) {
+       public function setLastUpdate(DateTime $time) {
                $this->lastUpdate = $time;
        }
 
index 898d044..e06ac77 100644 (file)
@@ -80,9 +80,14 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                        ->method('assign')
                        ->will($this->returnValue($viewMock));
 
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343234402);
                $repositoryModelMock->expects($this->once())
                        ->method('getLastUpdate')
-                       ->will($this->returnValue(1343234402));
+                       ->will($this->returnValue($lastUpdateDate));
+
+
 
                $repositoryRepositoryMock
                        ->expects($this->once())
@@ -92,7 +97,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
 
                $repositoryHelperMock->expects($this->once())
                        ->method('updateExtList');
-
+                       // Sat Jul 28 18:40:02 CEST 2012
                $GLOBALS['EXEC_TIME'] = 1343493602;
 
                $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
@@ -107,7 +112,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
         * @test
         * @return void
         */
-       public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
+       public function updateExtensionListFromTerDoesNotCallUpdateExtListIfLastUpdateIsLessThan24HoursAgo() {
                $controllerMock = $this->getAccessibleMock(
                        'Tx_Extensionmanager_Controller_UpdateFromTerController',
                        array('dummy')
@@ -134,21 +139,74 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                        array('hasArgument', 'getArgument')
                );
 
-               $requestMock->expects($this->once())
-                       ->method('hasArgument')
-                       ->will($this->returnValue(TRUE));
+               $viewMock->expects($this->any())
+                       ->method('assign')
+                       ->will($this->returnValue($viewMock));
+
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343493602);
+               $repositoryModelMock->expects($this->once())
+                       ->method('getLastUpdate')
+                       ->will($this->returnValue($lastUpdateDate));
+
+
+
+               $repositoryRepositoryMock
+                       ->expects($this->once())
+                       ->method('findOneByUid')
+                       ->with(1)
+                       ->will($this->returnValue($repositoryModelMock));
+
+               $repositoryHelperMock->expects($this->never())
+                       ->method('updateExtList');
+                       // Sat Jul 28 18:40:02 CEST 2012
+               $GLOBALS['EXEC_TIME'] = 1343493602;
 
-               $requestMock->expects($this->once())
-                       ->method('getArgument')
-                       ->will($this->returnValue(TRUE));
+               $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
+               $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
+               $controllerMock->_set('settings', array('repositoryUid' => 1));
+               $controllerMock->_set('view', $viewMock);
+               $controllerMock->_set('request', $requestMock);
+               $controllerMock->updateExtensionListFromTerAction();
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
+               $controllerMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Controller_UpdateFromTerController',
+                       array('dummy')
+               );
+               $repositoryRepositoryMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Domain_Repository_RepositoryRepository',
+                       array('findOneByUid')
+               );
+               $repositoryModelMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Domain_Model_Repository',
+                       array('getLastUpdate')
+               );
+               $repositoryHelperMock = $this->getAccessibleMock(
+                       'Tx_Extensionmanager_Utility_Repository_Helper',
+                       array('updateExtList')
+               );
+               $viewMock = $this->getAccessibleMock(
+                       'Tx_Fluid_View_TemplateView',
+                       array('assign')
+               );
 
                $viewMock->expects($this->any())
                        ->method('assign')
                        ->will($this->returnValue($viewMock));
 
+               $lastUpdateDate = new DateTime();
+                       // Wed Jul 25 18:40:02 CEST 2012
+               $lastUpdateDate->setTimestamp(1343234402);
                $repositoryModelMock->expects($this->once())
                        ->method('getLastUpdate')
-                       ->will($this->returnValue(1343493602));
+                       ->will($this->returnValue($lastUpdateDate));
 
                $repositoryRepositoryMock
                        ->expects($this->once())
@@ -159,6 +217,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                $repositoryHelperMock->expects($this->once())
                        ->method('updateExtList');
 
+                       // Sat Jul 28 18:40:02 CEST 2012
                $GLOBALS['EXEC_TIME'] = 1343493602;
 
                $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
@@ -166,7 +225,7 @@ class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extb
                $controllerMock->_set('settings', array('repositoryUid' => 1));
                $controllerMock->_set('view', $viewMock);
                $controllerMock->_set('request', $requestMock);
-               $controllerMock->updateExtensionListFromTerAction();
+               $controllerMock->updateExtensionListFromTerAction(TRUE);
        }
 }
 ?>
\ No newline at end of file