2 namespace TYPO3\CMS\Extensionmanager\Controller
;
4 /***************************************************************
7 * (c) 2012-2013 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>
34 class DownloadController
extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController
{
37 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
40 protected $extensionRepository;
43 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
46 protected $fileHandlingUtility;
49 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
52 protected $managementService;
55 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
58 protected $installUtility;
61 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
64 protected $downloadUtility;
67 * Check extension dependencies
69 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
72 public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
$extension) {
75 $hasDependencies = FALSE;
78 $dependencyTypes = $this->managementService
->getAndResolveDependencies($extension);
79 if (count($dependencyTypes) > 0) {
80 $hasDependencies = TRUE;
81 $message = $this->translate('downloadExtension.dependencies.headline');
82 foreach ($dependencyTypes as $dependencyType => $dependencies) {
84 foreach ($dependencies as $extensionKey => $dependency) {
85 $extensions .= htmlspecialchars($extensionKey) . '<br />';
87 $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
89 $this->translate('downloadExtension.dependencyType.' . $dependencyType),
94 $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
96 $this->view
->assign('dependencies', $dependencyTypes);
97 } catch (\Exception
$e) {
99 $title = $this->translate('downloadExtension.dependencies.errorTitle');
100 $message = $e->getMessage();
102 $this->view
->assign('extension', $extension)
103 ->assign('hasDependencies', $hasDependencies)
104 ->assign('hasErrors', $hasErrors)
105 ->assign('message', $message)
106 ->assign('title', $title);
110 * Install an extension from TER
112 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
113 * @param string $downloadPath
114 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
116 public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
$extension, $downloadPath) {
120 $this->downloadUtility
->setDownloadPath($downloadPath);
121 $this->prepareExtensionForImport($extension);
122 $result = $this->managementService
->resolveDependenciesAndInstall($extension);
123 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
$e) {
124 $errorMessage = $e->getMessage();
126 $this->view
->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
130 * Prepares an extension for import from TER
131 * Uninstalls the extension if it is already loaded (case: update)
132 * and reloads the caches.
134 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
137 protected function prepareExtensionForImport(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension
$extension) {
138 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::isLoaded($extension->getExtensionKey())) {
139 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::unloadExtension($extension->getExtensionKey());
140 $this->installUtility
->reloadCaches();
145 * Update an extension. Makes no sanity check but directly searches highest
146 * available version from TER and updates. Update check is done by the list
147 * already. This method should only be called if we are sure that there is
152 protected function updateExtensionAction() {
153 $extensionKey = $this->request
->getArgument('extension');
154 /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
155 $highestTerVersionExtension = $this->extensionRepository
->findHighestAvailableVersion($extensionKey);
156 $this->prepareExtensionForImport($highestTerVersionExtension);
157 $result = $this->managementService
->resolveDependenciesAndInstall($highestTerVersionExtension);
158 $this->view
->assign('result', $result)->assign('extension', $highestTerVersionExtension);
162 * Show update comments for extensions that can be updated.
163 * Fetches update comments for all versions between the current
164 * installed and the highest version.
168 protected function updateCommentForUpdatableVersionsAction() {
169 $extensionKey = $this->request
->getArgument('extension');
170 $version = $this->request
->getArgument('integerVersion');
171 $updateComments = array();
172 /** @var $updatableVersion \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
173 $updatableVersions = $this->extensionRepository
->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version);
174 foreach ($updatableVersions as $updatableVersion) {
175 $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
177 $this->view
->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);