‪TYPO3CMS  10.4
DownloadController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
31 
37 {
41  protected ‪$extensionRepository;
42 
46  protected ‪$managementService;
47 
51  protected ‪$downloadUtility;
52 
56  protected ‪$defaultViewObjectName = JsonView::class;
57 
61  protected ‪$view;
62 
67  {
68  $this->extensionRepository = ‪$extensionRepository;
69  }
70 
75  {
76  $this->managementService = ‪$managementService;
77  }
78 
83  {
84  $this->downloadUtility = ‪$downloadUtility;
85  }
86 
90  protected function ‪initializeInstallFromTerAction()
91  {
92  $this->defaultViewObjectName = TemplateView::class;
93  }
94 
101  public function ‪checkDependenciesAction(Extension $extension)
102  {
103  $message = '';
104  $title = '';
105  $hasDependencies = false;
106  $hasErrors = false;
107  $dependencyTypes = null;
108  $configuration = [
109  'value' => [
110  'dependencies' => [],
111  ],
112  ];
113  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
114  if (!$isAutomaticInstallationEnabled) {
115  // if automatic installation is deactivated, no dependency check is needed (download only)
116  $action = 'installExtensionWithoutSystemDependencyCheck';
117  } else {
118  $action = 'installFromTer';
119  try {
120  $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
121  if (!empty($dependencyTypes)) {
122  $hasDependencies = true;
123  $message = '<p>' . $this->‪translate('downloadExtension.dependencies.headline') . '</p>';
124  foreach ($dependencyTypes as $dependencyType => $dependencies) {
125  $extensions = '';
126  foreach ($dependencies as $extensionKey => $dependency) {
127  if (!isset($configuration['value']['dependencies'][$dependencyType])) {
128  $configuration['value']['dependencies'][$dependencyType] = [];
129  }
130  $configuration['value']['dependencies'][$dependencyType][$extensionKey] = [
131  '_exclude' => [
132  'categoryIndexFromStringOrNumber',
133  ],
134  ];
135  $extensions .= $this->‪translate(
136  'downloadExtension.dependencies.extensionWithVersion',
137  [
138  $extensionKey, $dependency->getVersion()
139  ]
140  ) . '<br />';
141  }
142  $message .= $this->‪translate(
143  'downloadExtension.dependencies.typeHeadline',
144  [
145  $this->‪translate('downloadExtension.dependencyType.' . $dependencyType),
146  $extensions
147  ]
148  );
149  }
150  $title = $this->‪translate('downloadExtension.dependencies.resolveAutomatically');
151  }
152  } catch (\Exception $e) {
153  $hasErrors = true;
154  $title = $this->‪translate('downloadExtension.dependencies.errorTitle');
155  $message = $e->getMessage();
156  }
157  }
158 
159  $url = $this->uriBuilder->uriFor(
160  $action,
161  ['extension' => $extension->getUid(), 'format' => 'json'],
162  'Download'
163  );
164  $this->view->setConfiguration($configuration);
165  $this->view->assign('value', [
166  'dependencies' => $dependencyTypes,
167  'url' => $url,
168  'message' => $message,
169  'hasErrors' => $hasErrors,
170  'hasDependencies' => $hasDependencies,
171  'title' => $title
172  ]);
173  }
174 
181  public function ‪installFromTerAction(Extension $extension, $downloadPath = 'Local')
182  {
183  [$result, $errorMessages] = $this->‪installFromTer($extension, $downloadPath);
184  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
185  $this->view
186  ->assign('result', $result)
187  ->assign('extension', $extension)
188  ->assign('installationTypeLanguageKey', $isAutomaticInstallationEnabled ? '' : '.downloadOnly')
189  ->assign('unresolvedDependencies', $errorMessages);
190  }
191 
198  public function ‪installExtensionWithoutSystemDependencyCheckAction(Extension $extension)
199  {
200  $this->managementService->setSkipDependencyCheck(true);
201  $this->‪forward('installFromTer', null, null, ['extension' => $extension, 'downloadPath' => 'Local']);
202  }
203 
210  public function ‪installDistributionAction(Extension $extension)
211  {
213  $this->‪forward('distributions', 'List');
214  }
215  [$result, $errorMessages] = $this->‪installFromTer($extension);
216  if ($errorMessages) {
217  foreach ($errorMessages as $extensionKey => $messages) {
218  foreach ($messages as $message) {
220  $this->‪addFlashMessage(
221  $message['message'],
223  'distribution.error.headline',
224  'extensionmanager',
225  [$extensionKey]
226  ) ?? '',
228  );
229  }
230  }
231 
232  // Redirect back to distributions list action
233  $this->‪redirect(
234  'distributions',
235  'List'
236  );
237  } else {
238  // FlashMessage that extension is installed
239  $this->‪addFlashMessage(
241  'distribution.welcome.message',
242  'extensionmanager',
243  [$extension->getExtensionKey()]
244  ) ?? '',
245  ‪LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager') ?? ''
246  );
247 
248  // Redirect to show action
249  $this->‪redirect(
250  'show',
251  'Distribution',
252  null,
253  ['extension' => $extension]
254  );
255  }
256  }
257 
266  protected function ‪updateExtensionAction()
267  {
268  $extensionKey = $this->request->getArgument('extension');
269  $version = $this->request->getArgument('version');
270  $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
271  if (!$extension instanceof Extension) {
272  $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
273  }
275  try {
276  if (in_array($extensionKey, $installedExtensions, true)) {
277  // To resolve new dependencies the extension is installed again
278  $this->managementService->installExtension($extension);
279  } else {
280  $this->managementService->downloadMainExtension($extension);
281  }
282  $this->‪addFlashMessage(
283  $this->‪translate('extensionList.updateFlashMessage.body', [$extensionKey]),
284  $this->‪translate('extensionList.updateFlashMessage.title')
285  );
286  } catch (\Exception $e) {
287  $this->‪addFlashMessage($e->getMessage(), '', ‪FlashMessage::ERROR);
288  }
289 
290  return '';
291  }
292 
298  protected function ‪updateCommentForUpdatableVersionsAction()
299  {
300  $extensionKey = $this->request->getArgument('extension');
301  $versionStart = $this->request->getArgument('integerVersionStart');
302  $versionStop = $this->request->getArgument('integerVersionStop');
303  $updateComments = [];
305  $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
306  $extensionKey,
307  $versionStart,
308  $versionStop,
309  false
310  );
311  $highestPossibleVersion = false;
312 
313  foreach ($updatableVersions as $updatableVersion) {
314  if ($highestPossibleVersion === false) {
315  $highestPossibleVersion = $updatableVersion->getVersion();
316  }
317  $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
318  }
319 
320  $this->view->assign('value', [
321  'updateComments' => $updateComments,
322  'url' => $this->uriBuilder->uriFor(
323  'updateExtension',
324  ['extension' => $extensionKey, 'version' => $highestPossibleVersion]
325  )
326  ]);
327  }
328 
337  protected function ‪installFromTer(Extension $extension, $downloadPath = 'Local')
338  {
339  $result = false;
340  $errorMessages = [];
341  try {
342  $this->downloadUtility->setDownloadPath($downloadPath);
343  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
344  $this->managementService->setAutomaticInstallationEnabled($isAutomaticInstallationEnabled);
345  if (($result = $this->managementService->installExtension($extension)) === false) {
346  $errorMessages = $this->managementService->getDependencyErrors();
347  }
348  } catch (ExtensionManagerException $e) {
349  $errorMessages = [
350  $extension->getExtensionKey() => [
351  [
352  'code' => $e->getCode(),
353  'message' => $e->getMessage(),
354  ]
355  ],
356  ];
357  }
358 
359  return [$result, $errorMessages];
360  }
361 }
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: ActionController.php:815
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int null getUid()
Definition: AbstractDomainObject.php:67
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\translate
‪string translate($key, $arguments=null)
Definition: AbstractController.php:44
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\initializeInstallFromTerAction
‪initializeInstallFromTerAction()
Definition: DownloadController.php:85
‪TYPO3\CMS\Core\Package\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$view
‪JsonView $view
Definition: DownloadController.php:56
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController
Definition: DownloadController.php:37
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installFromTer
‪array installFromTer(Extension $extension, $downloadPath='Local')
Definition: DownloadController.php:332
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:16
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$managementService
‪ExtensionManagementService $managementService
Definition: DownloadController.php:44
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\addFlashMessage
‪addFlashMessage($messageBody, $messageTitle='', $severity=AbstractMessage::OK, $storeInSession=true)
Definition: ActionController.php:747
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectDownloadUtility
‪injectDownloadUtility(DownloadUtility $downloadUtility)
Definition: DownloadController.php:77
‪TYPO3\CMS\Fluid\View\TemplateView
Definition: TemplateView.php:25
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\redirect
‪redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
Definition: ActionController.php:852
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\checkDependenciesAction
‪checkDependenciesAction(Extension $extension)
Definition: DownloadController.php:96
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:35
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\updateCommentForUpdatableVersionsAction
‪updateCommentForUpdatableVersionsAction()
Definition: DownloadController.php:293
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectExtensionRepository
‪injectExtensionRepository(ExtensionRepository $extensionRepository)
Definition: DownloadController.php:61
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\getExtensionKey
‪string getExtensionKey()
Definition: Extension.php:270
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:24
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: DownloadController.php:52
‪TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
Definition: DownloadUtility.php:29
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$extensionRepository
‪ExtensionRepository $extensionRepository
Definition: DownloadController.php:40
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController
Definition: AbstractController.php:26
‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
Definition: ExtensionManagementService.php:33
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installExtensionWithoutSystemDependencyCheckAction
‪installExtensionWithoutSystemDependencyCheckAction(Extension $extension)
Definition: DownloadController.php:193
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$downloadUtility
‪DownloadUtility $downloadUtility
Definition: DownloadController.php:48
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getLoadedExtensionListArray
‪static array getLoadedExtensionListArray()
Definition: ExtensionManagementUtility.php:1852
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installFromTerAction
‪installFromTerAction(Extension $extension, $downloadPath='Local')
Definition: DownloadController.php:176
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectManagementService
‪injectManagementService(ExtensionManagementService $managementService)
Definition: DownloadController.php:69
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installDistributionAction
‪installDistributionAction(Extension $extension)
Definition: DownloadController.php:205
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\updateExtensionAction
‪string updateExtensionAction()
Definition: DownloadController.php:261