66153a0a8b2ce784c06b320f218c2c4e8ffa6796
[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 text file 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 use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
30
31 /**
32 * Controller for actions related to the TER download of an extension
33 *
34 * @author Susanne Moog, <typo3@susannemoog.de>
35 */
36 class DownloadController extends AbstractController {
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
40 * @inject
41 */
42 protected $extensionRepository;
43
44 /**
45 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
46 * @inject
47 */
48 protected $fileHandlingUtility;
49
50 /**
51 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
52 * @inject
53 */
54 protected $managementService;
55
56 /**
57 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
58 * @inject
59 */
60 protected $installUtility;
61
62 /**
63 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
64 * @inject
65 */
66 protected $downloadUtility;
67
68 /**
69 * Check extension dependencies
70 *
71 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
72 * @throws \Exception
73 */
74 public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
75 $message = '';
76 $title = '';
77 $hasDependencies = FALSE;
78 $hasErrors = FALSE;
79 try {
80 $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
81 if (count($dependencyTypes) > 0) {
82 $hasDependencies = TRUE;
83 $message = $this->translate('downloadExtension.dependencies.headline');
84 foreach ($dependencyTypes as $dependencyType => $dependencies) {
85 $extensions = '';
86 foreach ($dependencies as $extensionKey => $dependency) {
87 $extensions .= htmlspecialchars($extensionKey) . '<br />';
88 }
89 $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
90 array(
91 $this->translate('downloadExtension.dependencyType.' . $dependencyType),
92 $extensions
93 )
94 );
95 }
96 $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
97 }
98 $this->view->assign('dependencies', $dependencyTypes);
99 } catch (\Exception $e) {
100 $hasErrors = TRUE;
101 $title = $this->translate('downloadExtension.dependencies.errorTitle');
102 $message = $e->getMessage();
103 }
104 $this->view->assign('extension', $extension)
105 ->assign('hasDependencies', $hasDependencies)
106 ->assign('hasErrors', $hasErrors)
107 ->assign('message', $message)
108 ->assign('title', $title);
109 }
110
111 /**
112 * Install an extension from TER action
113 *
114 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
115 * @param string $downloadPath
116 */
117 public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath) {
118 list($result, $errorMessages) = $this->installFromTer($extension, $downloadPath);
119 $this->view
120 ->assign('result', $result)
121 ->assign('extension', $extension)
122 ->assign('unresolvedDependencies', $errorMessages);
123 }
124
125 /**
126 * Check extension dependencies with special dependencies
127 *
128 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
129 * @throws \Exception
130 */
131 public function installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
132 $this->managementService->setSkipSystemDependencyCheck(TRUE);
133 $this->forward('installFromTer', NULL, NULL, array('extension' => $extension, 'downloadPath' => 'Local'));
134 }
135
136 /**
137 * Action for installing a distribution -
138 * redirects directly to configuration after installing
139 *
140 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
141 * @return void
142 */
143 public function installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
144 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp')) {
145 $this->forward('distributions', 'List');
146 }
147 list($result, $errorMessage) = $this->installFromTer($extension);
148 if ($errorMessage) {
149 // @TODO: write Template
150 $this->view
151 ->assign('result', $result)
152 ->assign('errorMessage', $errorMessage);
153 } else {
154 // FlashMessage that extension is installed
155 $this->addFlashMessage(
156 \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.message', 'extensionmanager')
157 . ' <strong>' . $extension->getExtensionKey() . '</strong>',
158 \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager')
159 );
160
161 // Redirect to show action
162 $this->redirect(
163 'show',
164 'Distribution',
165 NULL,
166 array('extension' => $extension)
167 );
168 }
169 }
170
171 /**
172 * Update an extension. Makes no sanity check but directly searches highest
173 * available version from TER and updates. Update check is done by the list
174 * already. This method should only be called if we are sure that there is
175 * an update.
176 *
177 * @return void
178 */
179 protected function updateExtensionAction() {
180 $hasErrors = FALSE;
181 $errorMessage = '';
182 $result = array();
183
184 $extensionKey = $this->request->getArgument('extension');
185 /** @var Extension $highestTerVersionExtension */
186 $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
187 try {
188 $result = $this->managementService->resolveDependenciesAndInstall($highestTerVersionExtension);
189 } catch (\Exception $e) {
190 $hasErrors = TRUE;
191 $errorMessage = $e->getMessage();
192 }
193 $this->view->assign('result', $result)
194 ->assign('extension', $highestTerVersionExtension)
195 ->assign('hasErrors', $hasErrors)
196 ->assign('errorMessage', $errorMessage);
197 }
198
199 /**
200 * Show update comments for extensions that can be updated.
201 * Fetches update comments for all versions between the current
202 * installed and the highest version.
203 *
204 * @return void
205 */
206 protected function updateCommentForUpdatableVersionsAction() {
207 $extensionKey = $this->request->getArgument('extension');
208 $version = $this->request->getArgument('integerVersion');
209 $updateComments = array();
210 /** @var Extension[] $updatableVersions */
211 $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version);
212 foreach ($updatableVersions as $updatableVersion) {
213 $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
214 }
215 $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
216 }
217
218 /**
219 * Install an action from TER
220 * Downloads the extension, resolves dependencies and installs it
221 *
222 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
223 * @param string $downloadPath
224 * @return array
225 */
226 protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local') {
227 $result = FALSE;
228 $errorMessages = array();
229 try {
230 $this->downloadUtility->setDownloadPath($downloadPath);
231 if (($result = $this->managementService->installExtension($extension)) === FALSE) {
232 $errorMessages = $this->managementService->getDependencyErrors();
233 }
234 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
235 $errorMessages = array(
236 $extension->getExtensionKey() => array(
237 'code' => $e->getCode(),
238 'message' => $e->getMessage(),
239 ),
240 );
241 }
242
243 return array($result, $errorMessages);
244 }
245 }