[TASK] Fix broken references to exceptions in global namespace
[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 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 * @package Extension Manager
34 * @subpackage Controller
35 */
36 class DownloadController extends \TYPO3\CMS\Extensionmanager\Controller\AbstractController {
37
38 /**
39 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
40 */
41 protected $extensionRepository;
42
43 /**
44 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
45 */
46 protected $fileHandlingUtility;
47
48 /**
49 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
50 */
51 protected $managementService;
52
53 /**
54 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
55 */
56 protected $installUtility;
57
58 /**
59 * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
60 * @return void
61 */
62 public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
63 $this->installUtility = $installUtility;
64 }
65
66 /**
67 * Dependency injection of the Extension Repository
68 *
69 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
70 * @return void
71 */
72 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
73 $this->extensionRepository = $extensionRepository;
74 }
75
76 /**
77 * @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
78 * @return void
79 */
80 public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility) {
81 $this->fileHandlingUtility = $fileHandlingUtility;
82 }
83
84 /**
85 * @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
86 * @return void
87 */
88 public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService) {
89 $this->managementService = $managementService;
90 }
91
92 /**
93 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
94 */
95 protected $downloadUtility;
96
97 /**
98 * @param \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility
99 * @return void
100 */
101 public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility) {
102 $this->downloadUtility = $downloadUtility;
103 }
104
105 /**
106 * Check extension dependencies
107 *
108 * @throws \Exception
109 * @return void
110 */
111 public function checkDependenciesAction() {
112 if (!$this->request->hasArgument('extension')) {
113 throw new \Exception('Required argument extension not set.', 1334433342);
114 }
115 $extensionUid = $this->request->getArgument('extension');
116 /** @var $extension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
117 $extension = $this->extensionRepository->findByUid(intval($extensionUid));
118 $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
119 $message = '';
120 if (count($dependencyTypes) > 0) {
121 // @todo translate and beautify
122 $message = 'The following dependencies have to be resolved before installation:<br /><br />';
123 foreach ($dependencyTypes as $dependencyType => $dependencies) {
124 $message .= ('<h3>Extensions marked for ' . $dependencyType) . ':</h3>';
125 foreach ($dependencies as $extensionKey => $dependency) {
126 $message .= $extensionKey . '<br />';
127 }
128 $message .= 'Shall these dependencies be resolved automatically?';
129 }
130 }
131 $this->view->assign('dependencies', $dependencyTypes)->assign('extension', $extension)->assign('message', $message);
132 }
133
134 /**
135 * Install an extension from TER
136 *
137 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
138 * @return void
139 */
140 public function installFromTerAction() {
141 $result = FALSE;
142 $errorMessage = '';
143 try {
144 if (!$this->request->hasArgument('extension')) {
145 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Required argument extension not set.', 1334433342);
146 }
147 $extensionUid = $this->request->getArgument('extension');
148 if ($this->request->hasArgument('downloadPath')) {
149 $this->downloadUtility->setDownloadPath($this->request->getArgument('downloadPath'));
150 }
151 /** @var $extension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
152 $extension = $this->extensionRepository->findByUid(intval($extensionUid));
153 $this->prepareExtensionForImport($extension);
154 $result = $this->managementService->resolveDependenciesAndInstall($extension);
155 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
156 $errorMessage = $e->getMessage();
157 }
158 $this->view->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
159 }
160
161 /**
162 * Prepares an extension for import from TER
163 * Uninstalls the extension if it is already loaded (case: update)
164 * and reloads the caches.
165 *
166 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
167 * @return void
168 */
169 protected function prepareExtensionForImport(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
170 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded($extension->getExtensionKey())) {
171 \TYPO3\CMS\Core\Extension\ExtensionManager::unloadExtension($extension->getExtensionKey());
172 $this->installUtility->reloadCaches();
173 }
174 }
175
176 /**
177 * Update an extension. Makes no sanity check but directly searches highest
178 * available version from TER and updates. Update check is done by the list
179 * already. This method should only be called if we are sure that there is
180 * an update.
181 *
182 * @return void
183 */
184 protected function updateExtensionAction() {
185 $extensionKey = $this->request->getArgument('extension');
186 /** @var $highestTerVersionExtension \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
187 $highestTerVersionExtension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
188 $this->prepareExtensionForImport($highestTerVersionExtension);
189 $result = $this->managementService->resolveDependenciesAndInstall($highestTerVersionExtension);
190 $this->view->assign('result', $result)->assign('extension', $highestTerVersionExtension);
191 }
192
193 /**
194 * Show update comments for extensions that can be updated.
195 * Fetches update comments for all versions between the current
196 * installed and the highest version.
197 *
198 * @return void
199 */
200 protected function updateCommentForUpdatableVersionsAction() {
201 $extensionKey = $this->request->getArgument('extension');
202 $version = $this->request->getArgument('integerVersion');
203 $updateComments = array();
204 /** @var $updatableVersion \TYPO3\CMS\Extensionmanager\Domain\Model\Extension */
205 $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion($extensionKey, $version);
206 foreach ($updatableVersions as $updatableVersion) {
207 $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
208 }
209 $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
210 }
211
212 }
213
214
215 ?>