[FEATURE] Add distribution management to extension manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / DownloadController.php
index cfc47ae..d2b0584 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Susanne Moog <typo3@susannemoog.de>
+ *  (c) 2012-2013 Susanne Moog <typo3@susannemoog.de>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -30,78 +30,39 @@ namespace TYPO3\CMS\Extensionmanager\Controller;
  * Controller for actions related to the TER download of an extension
  *
  * @author Susanne Moog, <typo3@susannemoog.de>
- * @package Extension Manager
- * @subpackage Controller
  */
 class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
+        * @inject
         */
        protected $extensionRepository;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
+        * @inject
         */
        protected $fileHandlingUtility;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
+        * @inject
         */
        protected $managementService;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
+        * @inject
         */
        protected $installUtility;
 
        /**
         * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
+        * @inject
         */
        protected $downloadUtility;
 
-       /**
-        * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
-        * @return void
-        */
-       public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
-               $this->installUtility = $installUtility;
-       }
-
-       /**
-        * Dependency injection of the Extension Repository
-        *
-        * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
-        * @return void
-        */
-       public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
-               $this->extensionRepository = $extensionRepository;
-       }
-
-       /**
-        * @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
-        * @return void
-        */
-       public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility) {
-               $this->fileHandlingUtility = $fileHandlingUtility;
-       }
-
-       /**
-        * @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
-        * @return void
-        */
-       public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService) {
-               $this->managementService = $managementService;
-       }
-
-       /**
-        * @param \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility
-        * @return void
-        */
-       public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility) {
-               $this->downloadUtility = $downloadUtility;
-       }
-
        /**
         * Check extension dependencies
         *
@@ -111,12 +72,12 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
        public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
                $message = '';
                $title = '';
-               $hasDependiencies = FALSE;
+               $hasDependencies = FALSE;
                $hasErrors = FALSE;
                try {
                        $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
                        if (count($dependencyTypes) > 0) {
-                               $hasDependiencies = TRUE;
+                               $hasDependencies = TRUE;
                                $message = $this->translate('downloadExtension.dependencies.headline');
                                foreach ($dependencyTypes as $dependencyType => $dependencies) {
                                        $extensions = '';
@@ -130,7 +91,7 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
                                                )
                                        );
                                }
-                               $title = $this->translate('downloadExtension.dependencies.reloveAutomatically');
+                               $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
                        }
                        $this->view->assign('dependencies', $dependencyTypes);
                } catch (\Exception $e) {
@@ -139,30 +100,50 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
                        $message = $e->getMessage();
                }
                $this->view->assign('extension', $extension)
-                               ->assign('hasDependencies', $hasDependiencies)
+                               ->assign('hasDependencies', $hasDependencies)
                                ->assign('hasErrors', $hasErrors)
                                ->assign('message', $message)
                                ->assign('title', $title);
        }
 
        /**
-        * Install an extension from TER
+        * Install an extension from TER action
         *
         * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
         * @param string $downloadPath
-        * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
         */
        public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath) {
-               $result = FALSE;
-               $errorMessage = '';
-               try {
-                       $this->downloadUtility->setDownloadPath($downloadPath);
-                       $this->prepareExtensionForImport($extension);
-                       $result = $this->managementService->resolveDependenciesAndInstall($extension);
-               } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
-                       $errorMessage = $e->getMessage();
+               list($result, $errorMessage) = $this->installFromTer($extension, $downloadPath);
+               $this->view
+                       ->assign('result', $result)
+                       ->assign('extension', $extension)
+                       ->assign('errorMessage', $errorMessage);
+       }
+
+       /**
+        * Action for installing a distribution -
+        * redirects directly to configuration after installing
+        *
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
+        * @return void
+        */
+       public function installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
+               list($result, $errorMessage) = $this->installFromTer($extension);
+               if ($errorMessage) {
+                       // @TODO: write Template
+                       $this->view
+                               ->assign('result', $result)
+                               ->assign('errorMessage', $errorMessage);
+               } else {
+                       $this->redirect(
+                               'showConfigurationForm',
+                               'Configuration',
+                               NULL,
+                               array(
+                                       'extension' => $this->installUtility->enrichExtensionWithDetails($extension->getExtensionKey())
+                               )
+                       );
                }
-               $this->view->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
        }
 
        /**
@@ -174,8 +155,8 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
         * @return void
         */
        protected function prepareExtensionForImport(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
-               if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded($extension->getExtensionKey())) {
-                       \TYPO3\CMS\Core\Extension\ExtensionManager::unloadExtension($extension->getExtensionKey());
+               if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension->getExtensionKey())) {
+                       \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension($extension->getExtensionKey());
                        $this->installUtility->reloadCaches();
                }
        }
@@ -215,6 +196,27 @@ class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\Abstract
                }
                $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
        }
+
+       /**
+        * Install an action from TER
+        * Downloads the extension, resolves dependencies and installs it
+        *
+        * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
+        * @param string $downloadPath
+        * @return array
+        */
+       protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local') {
+               $result = FALSE;
+               $errorMessage = '';
+               try {
+                       $this->downloadUtility->setDownloadPath($downloadPath);
+                       $this->prepareExtensionForImport($extension);
+                       $result = $this->managementService->resolveDependenciesAndInstall($extension);
+               } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
+                       $errorMessage = $e->getMessage();
+               }
+               return array($result, $errorMessage);
+       }
 }