[TASK] Use @inject annotation in extensionmanager
[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 * @inject
39 */
40 protected $extensionRepository;
41
42 /**
43 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
44 * @inject
45 */
46 protected $fileHandlingUtility;
47
48 /**
49 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
50 * @inject
51 */
52 protected $managementService;
53
54 /**
55 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
56 * @inject
57 */
58 protected $installUtility;
59
60 /**
61 * @var \TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
62 * @inject
63 */
64 protected $downloadUtility;
65
66 /**
67 * Check extension dependencies
68 *
69 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
70 * @throws \Exception
71 */
72 public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
73 $message = '';
74 $title = '';
75 $hasDependencies = FALSE;
76 $hasErrors = FALSE;
77 try {
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) {
83 $extensions = '';
84 foreach ($dependencies as $extensionKey => $dependency) {
85 $extensions .= htmlspecialchars($extensionKey) . '<br />';
86 }
87 $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
88 array(
89 $this->translate('downloadExtension.dependencyType.' . $dependencyType),
90 $extensions
91 )
92 );
93 }
94 $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
95 }
96 $this->view->assign('dependencies', $dependencyTypes);
97 } catch (\Exception $e) {
98 $hasErrors = TRUE;
99 $title = $this->translate('downloadExtension.dependencies.errorTitle');
100 $message = $e->getMessage();
101 }
102 $this->view->assign('extension', $extension)
103 ->assign('hasDependencies', $hasDependencies)
104 ->assign('hasErrors', $hasErrors)
105 ->assign('message', $message)
106 ->assign('title', $title);
107 }
108
109 /**
110 * Install an extension from TER
111 *
112 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
113 * @param string $downloadPath
114 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
115 */
116 public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath) {
117 $result = FALSE;
118 $errorMessage = '';
119 try {
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();
125 }
126 $this->view->assign('result', $result)->assign('extension', $extension)->assign('errorMessage', $errorMessage);
127 }
128
129 /**
130 * Prepares an extension for import from TER
131 * Uninstalls the extension if it is already loaded (case: update)
132 * and reloads the caches.
133 *
134 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
135 * @return void
136 */
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();
141 }
142 }
143
144 /**
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
148 * an update.
149 *
150 * @return void
151 */
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);
159 }
160
161 /**
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.
165 *
166 * @return void
167 */
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();
176 }
177 $this->view->assign('updateComments', $updateComments)->assign('extensionKey', $extensionKey);
178 }
179 }
180
181
182 ?>