[TASK] Merge submodule workspaces into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / DownloadController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog <typo3@susannemoog.de>
8 * All rights reserved
9 *
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.
15 *
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.
20 *
21 *
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.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Controller for actions related to the TER download of an extension
31 *
32 * @author Susanne Moog, <typo3@susannemoog.de>
33 */
34 class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
38 */
39 protected $extensionRepository;
40
41 /**
42 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
43 */
44 protected $fileHandlingUtility;
45
46 /**
47 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
48 */
49 protected $managementService;
50
51 /**
52 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
53 */
54 protected $installUtility;
55
56 /**
57 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
58 */
59 protected $downloadUtility;
60
61 /**
62 * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
63 * @return void
64 */
65 public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
66 $this->installUtility = $installUtility;
67 }
68
69 /**
70 * Dependency injection of the Extension Repository
71 *
72 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
73 * @return void
74 */
75 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
76 $this->extensionRepository = $extensionRepository;
77 }
78
79 /**
80 * @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
81 * @return void
82 */
83 public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility) {
84 $this->fileHandlingUtility = $fileHandlingUtility;
85 }
86
87 /**
88 * @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
89 * @return void
90 */
91 public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService) {
92 $this->managementService = $managementService;
93 }
94
95 /**
96 * @param \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility
97 * @return void
98 */
99 public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility) {
100 $this->downloadUtility = $downloadUtility;
101 }
102
103 /**
104 * Check extension dependencies
105 *
106 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
107 * @throws \Exception
108 */
109 public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
110 $message = '';
111 $title = '';
112 $hasDependencies = FALSE;
113 $hasErrors = FALSE;
114 try {
115 $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
116 if (count($dependencyTypes) > 0) {
117 $hasDependencies = TRUE;
118 $message = $this->translate('downloadExtension.dependencies.headline');
119 foreach ($dependencyTypes as $dependencyType => $dependencies) {
120 $extensions = '';
121 foreach ($dependencies as $extensionKey => $dependency) {
122 $extensions .= htmlspecialchars($extensionKey) . '<br />';
123 }
124 $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
125 array(
126 $this->translate('downloadExtension.dependencyType.' . $dependencyType),
127 $extensions
128 )
129 );
130 }
131 $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
132 }
133 $this->view->assign('dependencies', $dependencyTypes);
134 } catch (\Exception $e) {
135 $hasErrors = TRUE;
136 $title = $this->translate('downloadExtension.dependencies.errorTitle');
137 $message = $e->getMessage();
138 }
139 $this->view->assign('extension', $extension)
140 ->assign('hasDependencies', $hasDependencies)
141 ->assign('hasErrors', $hasErrors)
142 ->assign('message', $message)
143 ->assign('title', $title);
144 }
145
146 /**
147 * Install an extension from TER
148 *
149 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
150 * @param string $downloadPath
151 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
152 */
153 public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath) {
154 $result = FALSE;
155 $errorMessage = '';
156 try {
157 $this->downloadUtility->setDownloadPath($downloadPath);
158 $this->prepareExtensionForImport($extension);
159 $result = $this->managementService->resolveDependenciesAndInstall($extension);
160 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
161 $errorMessage = $e->getMessage();
162 }
163 $this->view->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
164 }
165
166 /**
167 * Prepares an extension for import from TER
168 * Uninstalls the extension if it is already loaded (case: update)
169 * and reloads the caches.
170 *
171 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
172 * @return void
173 */
174 protected function prepareExtensionForImport(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
175 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension->getExtensionKey())) {
176 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::unloadExtension($extension->getExtensionKey());
177 $this->installUtility->reloadCaches();
178 }
179 }
180
181 /**
182 * Update an extension. Makes no sanity check but directly searches highest
183 * available version from TER and updates. Update check is done by the list
184 * already. This method should only be called if we are sure that there is
185 * an update.
186 *
187 * @return void
188 */
189 protected function updateExtensionAction() {
190 $extensionKey = $this->request->getArgument('extension');
191 /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
192 $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
193 $this->prepareExtensionForImport($highestTerVersionExtension);
194 $result = $this->managementService->resolveDependenciesAndInstall($highestTerVersionExtension);
195 $this->view->assign('result', $result)->assign('extension', $highestTerVersionExtension);
196 }
197
198 /**
199 * Show update comments for extensions that can be updated.
200 * Fetches update comments for all versions between the current
201 * installed and the highest version.
202 *
203 * @return void
204 */
205 protected function updateCommentForUpdatableVersionsAction() {
206 $extensionKey = $this->request->getArgument('extension');
207 $version = $this->request->getArgument('integerVersion');
208 $updateComments = array();
209 /** @var $updatableVersion \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
210 $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version);
211 foreach ($updatableVersions as $updatableVersion) {
212 $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
213 }
214 $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
215 }
216 }
217
218
219 ?>