[BUGFIX] Resolve dependencies for local extensions
authorHelmut Hummel <helmut.hummel@typo3.org>
Mon, 22 Oct 2012 09:01:41 +0000 (11:01 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 22 Oct 2012 20:22:17 +0000 (22:22 +0200)
Add the dependency resolving when installing local
extensions with the extension manager.

Cleanup the download controller arguments on the go.

Fixes: #41273
Releases: 6.0

Change-Id: I10876f09bf4bed7b33d803a80a3d89fb583d4c7e
Reviewed-on: http://review.typo3.org/15873
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extensionmanager/Classes/Controller/ActionController.php
typo3/sysext/extensionmanager/Classes/Controller/DownloadController.php
typo3/sysext/extensionmanager/Classes/Service/ExtensionManagementService.php
typo3/sysext/extensionmanager/Classes/Utility/DependencyUtility.php

index a168941..9ea2699 100644 (file)
@@ -46,6 +46,11 @@ class ActionController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractCo
         */
        protected $fileHandlingUtility;
 
+       /**
+        * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
+        */
+       protected $managementService;
+
        /**
         * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
         */
@@ -60,6 +65,13 @@ class ActionController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractCo
                $this->fileHandlingUtility = $fileHandlingUtility;
        }
 
+       /**
+        * @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
+        */
+       public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService) {
+               $this->managementService = $managementService;
+       }
+
        /**
         * Toggle extension installation state action
         *
@@ -72,7 +84,9 @@ class ActionController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractCo
                        $this->installUtility->uninstall($extension);
                } else {
                        // install
-                       $this->installUtility->install($extension);
+                       $this->managementService->resolveDependenciesAndInstall(
+                               $this->installUtility->enrichExtensionWithDetails($extension)
+                       );
                }
                $this->redirect('index', 'List');
        }
index a5c4a89..c1e05e3 100644 (file)
@@ -148,22 +148,15 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
        /**
         * Install an extension from TER
         *
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
+        * @param string $downloadPath
         * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
-        * @return void
         */
-       public function installFromTerAction() {
+       public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath) {
                $result = FALSE;
                $errorMessage = '';
                try {
-                       if (!$this->request->hasArgument('extension')) {
-                               throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Required argument extension not set.', 1334433342);
-                       }
-                       $extensionUid = $this->request->getArgument('extension');
-                       if ($this->request->hasArgument('downloadPath')) {
-                               $this->downloadUtility->setDownloadPath($this->request->getArgument('downloadPath'));
-                       }
-                       /** @var $extension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
-                       $extension = $this->extensionRepository->findByUid(intval($extensionUid));
+                       $this->downloadUtility->setDownloadPath($downloadPath);
                        $this->prepareExtensionForImport($extension);
                        $result = $this->managementService->resolveDependenciesAndInstall($extension);
                } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
index 6a649b7..6800dca 100644 (file)
@@ -129,12 +129,21 @@ class ExtensionManagementService implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|array $extension
         * @return array
         */
-       public function resolveDependenciesAndInstall(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
+       public function resolveDependenciesAndInstall($extension) {
+               if (!is_array($extension) && !$extension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
+                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Extension must be array or object.', 1350891642);
+               }
                $this->dependencyUtility->buildExtensionDependenciesTree($extension);
-               $this->downloadQueue->addExtensionToQueue($extension);
+               if ($extension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
+                       // We have a TER Extension, which should be downloaded first.
+                       $this->downloadQueue->addExtensionToQueue($extension);
+                       $extensionKey = $extension->getExtensionKey();
+               } else {
+                       $extensionKey = $extension['key'];
+               }
                $queue = $this->downloadQueue->getExtensionQueue();
                $downloadedDependencies = array();
                $updatedDependencies = array();
@@ -147,7 +156,7 @@ class ExtensionManagementService implements \TYPO3\CMS\Core\SingletonInterface {
                        $updatedDependencies = $this->uninstallDependenciesToBeUpdated($queue['update']);
                }
                // add extension at the end of the download queue
-               $this->downloadQueue->addExtensionToInstallQueue($extension->getExtensionKey());
+               $this->downloadQueue->addExtensionToInstallQueue($extensionKey);
                $installQueue = $this->downloadQueue->getExtensionInstallStorage();
                if (count($installQueue) > 0) {
                        $installedDependencies = $this->installDependencies($installQueue);
index 6ba3d4d..d0b4b6c 100644 (file)
@@ -121,11 +121,18 @@ class DependencyUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
-        * @return void
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|array $extension
+        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
         */
        public function buildExtensionDependenciesTree($extension) {
-               $dependencies = $extension->getDependencies();
+               if (!is_array($extension) && !$extension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
+                       throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Extension must be array or object.', 1350891642);
+               }
+               if ($extension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
+                       $dependencies = $extension->getDependencies();
+               } else {
+                       $dependencies = $this->convertDependenciesToObjects(serialize($extension['constraints']));
+               }
                $this->checkDependencies($dependencies);
        }