[TASK] Improve retrieving distribution list 82/39182/3
authorNicole Cordes <typo3@cordes.co>
Sat, 2 May 2015 09:12:35 +0000 (11:12 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 2 May 2015 11:53:14 +0000 (13:53 +0200)
If you open the "Get preconfigured distribution" extension manager
function the extension list is retrieved twice. Furthermore database
queries are executed multiple times. This patch improves retrieving the
extension list, prevents database queries and catches thrown errors to
prevent errors.

Releases: master, 6.2
Resolves: #66730
Change-Id: Ice1bd36e1233fde121bb33232f98a4e25480b0e0
Reviewed-on: http://review.typo3.org/39182
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extensionmanager/Classes/Controller/ListController.php
typo3/sysext/extensionmanager/Classes/Task/UpdateExtensionListTask.php
typo3/sysext/extensionmanager/Classes/Utility/Repository/Helper.php

index 2b552e2..2f1f061 100644 (file)
@@ -14,6 +14,12 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Messaging\FlashMessage;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
+use TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility;
+use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper;
+
 /**
  * Controller for extension listings (TER or local extensions)
  *
@@ -67,7 +73,7 @@ class ListController extends AbstractController {
         * Shows a list of unresolved dependency errors with the possibility to bypass the dependency check
         *
         * @param string $extensionKey
-        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
+        * @throws ExtensionManagerException
         * @return void
         */
        public function unresolvedDependenciesAction($extensionKey) {
@@ -78,11 +84,11 @@ class ListController extends AbstractController {
                                        $extensionKey => $availableExtensions[$extensionKey]
                                )
                        );
-                       /** @var \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility $extensionModelUtility */
-                       $extensionModelUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class);
+                       /** @var ExtensionModelUtility $extensionModelUtility */
+                       $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
                        $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
                } else {
-                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
+                       throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
                }
                $this->dependencyUtility->checkDependencies($extension);
                $this->view->assign('extension', $extension);
@@ -114,15 +120,19 @@ class ListController extends AbstractController {
         * @return void
         */
        public function distributionsAction() {
-               $importExportInstalled = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp');
+               $importExportInstalled = ExtensionManagementUtility::isLoaded('impexp');
                if ($importExportInstalled) {
-                       // check if a TER update has been done at all, if not, fetch it directly
-                       /** @var $repositoryHelper \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper */
-                       $repositoryHelper = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::class);
-                       // repository needs an update, but not because of the extension hash has changed
-                       if ($repositoryHelper->isExtListUpdateNecessary() > 0 && ($repositoryHelper->isExtListUpdateNecessary() & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
-                               $repositoryHelper->fetchExtListFile();
-                               $repositoryHelper->updateExtList();
+                       try {
+                               /** @var $repositoryHelper Helper */
+                               $repositoryHelper = $this->objectManager->get(Helper::class);
+                               // Check if a TER update has been done at all, if not, fetch it directly
+                               // Repository needs an update, but not because of the extension hash has changed
+                               $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
+                               if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
+                                       $repositoryHelper->updateExtList();
+                               }
+                       } catch (ExtensionManagerException $e) {
+                               $this->addFlashMessage(htmlspecialchars($e->getMessage()), $e->getCode(), FlashMessage::ERROR);
                        }
 
                        $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
index 4b161e1..fa6e67e 100644 (file)
@@ -38,6 +38,7 @@ class UpdateExtensionListTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
         *
         * @TODO: Adapt to multiple repositories if the Helper can handle this
         * @return void
+        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
         */
        protected function updateExtensionList() {
                /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
index da5f96f..ee3b32c 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extensionmanager\Utility\Repository;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
+
 /**
  * Central utility class for repository handling.
  *
@@ -128,17 +130,17 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
         * @param string $localResource local resource (absolute file path) to store retrieved contents to
         * @return void
         * @see \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(), \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile()
-        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
+        * @throws ExtensionManagerException
         */
        protected function fetchFile($remoteResource, $localResource) {
                if (is_string($remoteResource) && is_string($localResource) && !empty($remoteResource) && !empty($localResource)) {
                        $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($remoteResource, 0, array(TYPO3_user_agent));
                        if ($fileContent !== FALSE) {
                                if (\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($localResource, $fileContent) === FALSE) {
-                                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Could not write to file %s.', htmlspecialchars($localResource)), 1342635378);
+                                       throw new ExtensionManagerException(sprintf('Could not write to file %s.', htmlspecialchars($localResource)), 1342635378);
                                }
                        } else {
-                               throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Could not access remote resource %s.', htmlspecialchars($remoteResource)), 1342635425);
+                               throw new ExtensionManagerException(sprintf('Could not access remote resource %s.', htmlspecialchars($remoteResource)), 1342635425);
                        }
                }
        }
@@ -235,7 +237,7 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
         *
         * @access public
         * @see Tx_Extensionmanager_Utility_Repository_Helper::PROBLEM_NO_VERSIONS_IN_DATABASE,
-        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
+        * @throws ExtensionManagerException
         * @return int "0" if everything is perfect, otherwise bitmask with problems
         */
        public function isExtListUpdateNecessary() {
@@ -253,7 +255,7 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
                                        $updateNecessity |= self::PROBLEM_EXTENSION_HASH_CHANGED;
                                }
                        } else {
-                               throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Could not retrieve extension hash file from remote server.', 1342635016);
+                               throw new ExtensionManagerException('Could not retrieve extension hash file from remote server.', 1342635016);
                        }
                }
                return $updateNecessity;
@@ -264,6 +266,7 @@ class Helper implements \TYPO3\CMS\Core\SingletonInterface {
         * extension version records.
         *
         * @return bool TRUE if the extension list was successfully update, FALSE if no update necessary
+        * @throws ExtensionManagerException
         * @see isExtListUpdateNecessary()
         */
        public function updateExtList() {