TYPO3 CMS  TYPO3_7-6
DownloadController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
29 
34 
38  protected $managementService;
39 
43  protected $installUtility;
44 
48  protected $downloadUtility;
49 
54 
58  public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
59  {
60  $this->extensionRepository = $extensionRepository;
61  }
62 
66  public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
67  {
68  $this->fileHandlingUtility = $fileHandlingUtility;
69  }
70 
74  public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
75  {
76  $this->managementService = $managementService;
77  }
78 
82  public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
83  {
84  $this->installUtility = $installUtility;
85  }
86 
90  public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility)
91  {
92  $this->downloadUtility = $downloadUtility;
93  }
94 
98  public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
99  {
100  $this->configurationUtility = $configurationUtility;
101  }
102 
109  public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
110  {
111  $message = '';
112  $title = '';
113  $hasDependencies = false;
114  $hasErrors = false;
115  if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']) {
116  $action = 'installFromTer';
117  try {
118  $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
119  if (!empty($dependencyTypes)) {
120  $hasDependencies = true;
121  $message = '<p>' . $this->translate('downloadExtension.dependencies.headline') . '</p>';
122  foreach ($dependencyTypes as $dependencyType => $dependencies) {
123  $extensions = '';
124  foreach ($dependencies as $extensionKey => $dependency) {
125  $extensions .= $this->translate('downloadExtension.dependencies.extensionWithVersion', [
126  $extensionKey, $dependency->getVersion()
127  ]) . '<br />';
128  }
129  $message .= $this->translate('downloadExtension.dependencies.typeHeadline',
130  [
131  $this->translate('downloadExtension.dependencyType.' . $dependencyType),
132  $extensions
133  ]
134  );
135  }
136  $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
137  }
138  $this->view->assign('dependencies', $dependencyTypes);
139  } catch (\Exception $e) {
140  $hasErrors = true;
141  $title = $this->translate('downloadExtension.dependencies.errorTitle');
142  $message = $e->getMessage();
143  }
144  } else {
145  // if automatic installation is deactivated, no dependency check is needed (download only)
146  $action = 'installExtensionWithoutSystemDependencyCheck';
147  }
148  $this->view->assign('extension', $extension)
149  ->assign('action', $action)
150  ->assign('hasDependencies', $hasDependencies)
151  ->assign('hasErrors', $hasErrors)
152  ->assign('message', $message)
153  ->assign('title', $title);
154  }
155 
162  public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath)
163  {
164  list($result, $errorMessages) = $this->installFromTer($extension, $downloadPath);
165  $emConfiguration = $this->configurationUtility->getCurrentConfiguration('extensionmanager');
166  $this->view
167  ->assign('result', $result)
168  ->assign('extension', $extension)
169  ->assign('installationTypeLanguageKey', (bool)$emConfiguration['automaticInstallation']['value'] ? '' : '.downloadOnly')
170  ->assign('unresolvedDependencies', $errorMessages);
171  }
172 
179  public function installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
180  {
181  $this->managementService->setSkipDependencyCheck(true);
182  $this->forward('installFromTer', null, null, ['extension' => $extension, 'downloadPath' => 'Local']);
183  }
184 
192  public function installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
193  {
194  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp')) {
195  $this->forward('distributions', 'List');
196  }
197  list($result, $errorMessages) = $this->installFromTer($extension);
198  if ($errorMessages) {
199  foreach ($errorMessages as $extensionKey => $messages) {
200  foreach ($messages as $message) {
201  $this->addFlashMessage(
202  $message['message'],
203  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
204  'distribution.error.headline',
205  'extensionmanager',
206  [$extensionKey]
207  ),
208  \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
209  );
210  }
211  }
212 
213  // Redirect back to distributions list action
214  $this->redirect(
215  'distributions',
216  'List'
217  );
218  } else {
219  // FlashMessage that extension is installed
220  $this->addFlashMessage(
221  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.message', 'extensionmanager')
222  . $extension->getExtensionKey(),
223  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager')
224  );
225 
226  // Redirect to show action
227  $this->redirect(
228  'show',
229  'Distribution',
230  null,
231  ['extension' => $extension]
232  );
233  }
234  }
235 
244  protected function updateExtensionAction()
245  {
246  $extensionKey = $this->request->getArgument('extension');
247  $version = $this->request->getArgument('version');
248  $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
249  if (!$extension instanceof Extension) {
250  $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
251  }
253  try {
254  if (in_array($extensionKey, $installedExtensions, true)) {
255  // To resolve new dependencies the extension is installed again
256  $this->managementService->installExtension($extension);
257  } else {
258  $this->managementService->downloadMainExtension($extension);
259  }
260  $this->addFlashMessage(
261  $this->translate('extensionList.updateFlashMessage.body', [$extensionKey]),
262  $this->translate('extensionList.updateFlashMessage.title')
263  );
264  } catch (\Exception $e) {
265  $this->addFlashMessage($e->getMessage(), '', FlashMessage::ERROR);
266  }
267 
268  return '';
269  }
270 
278  protected function updateCommentForUpdatableVersionsAction()
279  {
280  $extensionKey = $this->request->getArgument('extension');
281  $versionStart = $this->request->getArgument('integerVersionStart');
282  $versionStop = $this->request->getArgument('integerVersionStop');
283  $updateComments = [];
285  $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
286  $extensionKey,
287  $versionStart,
288  $versionStop,
289  false
290  );
291  $highestPossibleVersion = false;
292 
293  foreach ($updatableVersions as $updatableVersion) {
294  if ($highestPossibleVersion === false) {
295  $highestPossibleVersion = $updatableVersion->getVersion();
296  }
297  $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
298  }
299  $this->view->assign('updateComments', $updateComments)
300  ->assign('extensionKey', $extensionKey)
301  ->assign('version', $highestPossibleVersion);
302  }
303 
312  protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
313  {
314  $result = false;
315  $errorMessages = [];
316  try {
317  $this->downloadUtility->setDownloadPath($downloadPath);
318  $this->managementService->setAutomaticInstallationEnabled($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']);
319  if (($result = $this->managementService->installExtension($extension)) === false) {
320  $errorMessages = $this->managementService->getDependencyErrors();
321  }
322  } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
323  $errorMessages = [
324  $extension->getExtensionKey() => [
325  [
326  'code' => $e->getCode(),
327  'message' => $e->getMessage(),
328  ]
329  ],
330  ];
331  }
332 
333  return [$result, $errorMessages];
334  }
335 }
static translate($key, $extensionName, $arguments=null)
installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility)
injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
addFlashMessage($messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)
installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath='Local')
installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath)
checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)