TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
30 
35 
39  protected $managementService;
40 
44  protected $installUtility;
45 
49  protected $downloadUtility;
50 
55 
59  protected $defaultViewObjectName = JsonView::class;
60 
64  protected $view;
65 
69  public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
70  {
71  $this->extensionRepository = $extensionRepository;
72  }
73 
77  public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
78  {
79  $this->fileHandlingUtility = $fileHandlingUtility;
80  }
81 
85  public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
86  {
87  $this->managementService = $managementService;
88  }
89 
93  public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
94  {
95  $this->installUtility = $installUtility;
96  }
97 
101  public function injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility)
102  {
103  $this->downloadUtility = $downloadUtility;
104  }
105 
109  public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
110  {
111  $this->configurationUtility = $configurationUtility;
112  }
113 
117  protected function initializeInstallFromTerAction()
118  {
119  $this->defaultViewObjectName = \TYPO3\CMS\Fluid\View\TemplateView::class;
120  }
121 
128  public function checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
129  {
130  $message = '';
131  $title = '';
132  $hasDependencies = false;
133  $hasErrors = false;
134  $dependencyTypes = null;
135  $configuration = [
136  'value' => [
137  'dependencies' => [],
138  ],
139  ];
140  if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']) {
141  $action = 'installFromTer';
142  try {
143  $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
144  if (!empty($dependencyTypes)) {
145  $hasDependencies = true;
146  $message = '<p>' . $this->translate('downloadExtension.dependencies.headline') . '</p>';
147  foreach ($dependencyTypes as $dependencyType => $dependencies) {
148  $extensions = '';
149  foreach ($dependencies as $extensionKey => $dependency) {
150  if (!isset($configuration['value']['dependencies'][$dependencyType])) {
151  $configuration['value']['dependencies'][$dependencyType] = [];
152  }
153  $configuration['value']['dependencies'][$dependencyType][$extensionKey] = [
154  '_exclude' => [
155  'categoryIndexFromStringOrNumber',
156  ],
157  ];
158  $extensions .= $this->translate(
159  'downloadExtension.dependencies.extensionWithVersion',
160  [
161  $extensionKey, $dependency->getVersion()
162  ]
163  ) . '<br />';
164  }
165  $message .= $this->translate(
166  'downloadExtension.dependencies.typeHeadline',
167  [
168  $this->translate('downloadExtension.dependencyType.' . $dependencyType),
169  $extensions
170  ]
171  );
172  }
173  $title = $this->translate('downloadExtension.dependencies.resolveAutomatically');
174  }
175  } catch (\Exception $e) {
176  $hasErrors = true;
177  $title = $this->translate('downloadExtension.dependencies.errorTitle');
178  $message = $e->getMessage();
179  }
180  } else {
181  // if automatic installation is deactivated, no dependency check is needed (download only)
182  $action = 'installExtensionWithoutSystemDependencyCheck';
183  }
184 
185  $url = $this->uriBuilder->uriFor(
186  $action,
187  ['extension' => $extension->getUid(), 'format' => 'json'],
188  'Download'
189  );
190  $this->view->setConfiguration($configuration);
191  $this->view->assign('value', [
192  'dependencies' => $dependencyTypes,
193  'url' => $url,
194  'message' => $message,
195  'hasErrors' => $hasErrors,
196  'hasDependencies' => $hasDependencies,
197  'title' => $title
198  ]);
199  }
200 
207  public function installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
208  {
209  list($result, $errorMessages) = $this->installFromTer($extension, $downloadPath);
210  $emConfiguration = $this->configurationUtility->getCurrentConfiguration('extensionmanager');
211  $this->view
212  ->assign('result', $result)
213  ->assign('extension', $extension)
214  ->assign('installationTypeLanguageKey', (bool)$emConfiguration['automaticInstallation']['value'] ? '' : '.downloadOnly')
215  ->assign('unresolvedDependencies', $errorMessages);
216  }
217 
224  public function installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
225  {
226  $this->managementService->setSkipDependencyCheck(true);
227  $this->forward('installFromTer', null, null, ['extension' => $extension, 'downloadPath' => 'Local']);
228  }
229 
236  public function installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
237  {
238  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp')) {
239  $this->forward('distributions', 'List');
240  }
241  list($result, $errorMessages) = $this->installFromTer($extension);
242  if ($errorMessages) {
243  foreach ($errorMessages as $extensionKey => $messages) {
244  foreach ($messages as $message) {
245  $this->addFlashMessage(
246  $message['message'],
247  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
248  'distribution.error.headline',
249  'extensionmanager',
250  [$extensionKey]
251  ),
252  \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
253  );
254  }
255  }
256 
257  // Redirect back to distributions list action
258  $this->redirect(
259  'distributions',
260  'List'
261  );
262  } else {
263  // FlashMessage that extension is installed
264  $this->addFlashMessage(
265  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.message', 'extensionmanager')
266  . $extension->getExtensionKey(),
267  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager')
268  );
269 
270  // Redirect to show action
271  $this->redirect(
272  'show',
273  'Distribution',
274  null,
275  ['extension' => $extension]
276  );
277  }
278  }
279 
288  protected function updateExtensionAction()
289  {
290  $extensionKey = $this->request->getArgument('extension');
291  $version = $this->request->getArgument('version');
292  $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
293  if (!$extension instanceof Extension) {
294  $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
295  }
297  try {
298  if (in_array($extensionKey, $installedExtensions, true)) {
299  // To resolve new dependencies the extension is installed again
300  $this->managementService->installExtension($extension);
301  } else {
302  $this->managementService->downloadMainExtension($extension);
303  }
304  $this->addFlashMessage(
305  $this->translate('extensionList.updateFlashMessage.body', [$extensionKey]),
306  $this->translate('extensionList.updateFlashMessage.title')
307  );
308  } catch (\Exception $e) {
309  $this->addFlashMessage($e->getMessage(), '', FlashMessage::ERROR);
310  }
311 
312  return '';
313  }
314 
320  protected function updateCommentForUpdatableVersionsAction()
321  {
322  $extensionKey = $this->request->getArgument('extension');
323  $versionStart = $this->request->getArgument('integerVersionStart');
324  $versionStop = $this->request->getArgument('integerVersionStop');
325  $updateComments = [];
327  $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
328  $extensionKey,
329  $versionStart,
330  $versionStop,
331  false
332  );
333  $highestPossibleVersion = false;
334 
335  foreach ($updatableVersions as $updatableVersion) {
336  if ($highestPossibleVersion === false) {
337  $highestPossibleVersion = $updatableVersion->getVersion();
338  }
339  $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
340  }
341 
342  $this->view->assign('value', [
343  'updateComments' => $updateComments,
344  'url' => $this->uriBuilder->uriFor(
345  'updateExtension',
346  ['extension' => $extensionKey, 'version' => $highestPossibleVersion]
347  )
348  ]);
349  }
350 
359  protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
360  {
361  $result = false;
362  $errorMessages = [];
363  try {
364  $this->downloadUtility->setDownloadPath($downloadPath);
365  $this->managementService->setAutomaticInstallationEnabled($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']);
366  if (($result = $this->managementService->installExtension($extension)) === false) {
367  $errorMessages = $this->managementService->getDependencyErrors();
368  }
369  } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
370  $errorMessages = [
371  $extension->getExtensionKey() => [
372  [
373  'code' => $e->getCode(),
374  'message' => $e->getMessage(),
375  ]
376  ],
377  ];
378  }
379 
380  return [$result, $errorMessages];
381  }
382 }
installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath='Local')
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)
static translate($key, $extensionName=null, $arguments=null)
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')
checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)