2 namespace TYPO3\CMS\Extensionmanager\Controller
;
4 /***************************************************************
7 * (c) 2012 Susanne Moog <typo3@susannemoog.de>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 * Controller for actions related to the TER download of an extension
32 * @author Susanne Moog, <typo3@susannemoog.de>
33 * @package Extension Manager
34 * @subpackage Controller
36 class DownloadController
extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController
{
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
41 protected $extensionRepository;
44 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
46 protected $fileHandlingUtility;
49 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
51 protected $managementService;
54 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
56 protected $installUtility;
59 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
61 protected $downloadUtility;
64 * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
67 public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility
$installUtility) {
68 $this->installUtility
= $installUtility;
72 * Dependency injection of the Extension Repository
74 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
77 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
$extensionRepository) {
78 $this->extensionRepository
= $extensionRepository;
82 * @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
85 public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
$fileHandlingUtility) {
86 $this->fileHandlingUtility
= $fileHandlingUtility;
90 * @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
93 public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
$managementService) {
94 $this->managementService
= $managementService;
98 * @param \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility
101 public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
$downloadUtility) {
102 $this->downloadUtility
= $downloadUtility;
106 * Check extension dependencies
108 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
111 public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
$extension) {
112 $dependencyTypes = $this->managementService
->getAndResolveDependencies($extension);
114 if (count($dependencyTypes) > 0) {
115 // @todo translate and beautify
116 $message = 'The following dependencies have to be resolved before installation:<br /><br />';
117 foreach ($dependencyTypes as $dependencyType => $dependencies) {
118 $message .= '<h3>Extensions marked for ' . $dependencyType . ':</h3>';
119 foreach ($dependencies as $extensionKey => $dependency) {
120 $message .= $extensionKey . '<br />';
122 $message .= 'Shall these dependencies be resolved automatically?';
125 $this->view
->assign('dependencies', $dependencyTypes)->assign('extension', $extension)->assign('message', $message);
129 * Install an extension from TER
131 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
134 public function installFromTerAction() {
138 if (!$this->request
->hasArgument('extension')) {
139 throw new \TYPO3\CMS\Extensionmanager\Exception\
ExtensionManagerException('Required argument extension not set.', 1334433342);
141 $extensionUid = $this->request
->getArgument('extension');
142 if ($this->request
->hasArgument('downloadPath')) {
143 $this->downloadUtility
->setDownloadPath($this->request
->getArgument('downloadPath'));
145 /** @var $extension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
146 $extension = $this->extensionRepository
->findByUid(intval($extensionUid));
147 $this->prepareExtensionForImport($extension);
148 $result = $this->managementService
->resolveDependenciesAndInstall($extension);
149 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
$e) {
150 $errorMessage = $e->getMessage();
152 $this->view
->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
156 * Prepares an extension for import from TER
157 * Uninstalls the extension if it is already loaded (case: update)
158 * and reloads the caches.
160 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
163 protected function prepareExtensionForImport(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
$extension) {
164 if (\TYPO3\CMS\Core\Extension\ExtensionManager
::isLoaded($extension->getExtensionKey())) {
165 \TYPO3\CMS\Core\Extension\ExtensionManager
::unloadExtension($extension->getExtensionKey());
166 $this->installUtility
->reloadCaches();
171 * Update an extension. Makes no sanity check but directly searches highest
172 * available version from TER and updates. Update check is done by the list
173 * already. This method should only be called if we are sure that there is
178 protected function updateExtensionAction() {
179 $extensionKey = $this->request
->getArgument('extension');
180 /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
181 $highestTerVersionExtension = $this->extensionRepository
->findHighestAvailableVersion($extensionKey);
182 $this->prepareExtensionForImport($highestTerVersionExtension);
183 $result = $this->managementService
->resolveDependenciesAndInstall($highestTerVersionExtension);
184 $this->view
->assign('result', $result)->assign('extension', $highestTerVersionExtension);
188 * Show update comments for extensions that can be updated.
189 * Fetches update comments for all versions between the current
190 * installed and the highest version.
194 protected function updateCommentForUpdatableVersionsAction() {
195 $extensionKey = $this->request
->getArgument('extension');
196 $version = $this->request
->getArgument('integerVersion');
197 $updateComments = array();
198 /** @var $updatableVersion \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
199 $updatableVersions = $this->extensionRepository
->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version);
200 foreach ($updatableVersions as $updatableVersion) {
201 $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
203 $this->view
->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);