‪TYPO3CMS  9.5
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 
22 
28 {
32  protected ‪$extensionRepository;
33 
37  protected ‪$fileHandlingUtility;
38 
42  protected ‪$managementService;
43 
47  protected ‪$installUtility;
48 
52  protected ‪$downloadUtility;
53 
57  protected ‪$defaultViewObjectName = JsonView::class;
58 
62  protected ‪$view;
63 
67  public function ‪injectExtensionRepository(\‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository ‪$extensionRepository)
68  {
69  $this->extensionRepository = ‪$extensionRepository;
70  }
71 
75  public function ‪injectFileHandlingUtility(\‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility ‪$fileHandlingUtility)
76  {
77  $this->fileHandlingUtility = ‪$fileHandlingUtility;
78  }
79 
83  public function ‪injectManagementService(\‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService ‪$managementService)
84  {
85  $this->managementService = ‪$managementService;
86  }
87 
91  public function ‪injectInstallUtility(\‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility ‪$installUtility)
92  {
93  $this->installUtility = ‪$installUtility;
94  }
95 
99  public function ‪injectDownloadUtility(\‪TYPO3\CMS\Extensionmanager\Utility\DownloadUtility ‪$downloadUtility)
100  {
101  $this->downloadUtility = ‪$downloadUtility;
102  }
103 
107  protected function ‪initializeInstallFromTerAction()
108  {
109  $this->defaultViewObjectName = \TYPO3\CMS\Fluid\View\TemplateView::class;
110  }
111 
118  public function ‪checkDependenciesAction(\‪TYPO3\CMS\Extensionmanager\Domain\Model\‪Extension $extension)
119  {
120  $message = '';
121  $title = '';
122  $hasDependencies = false;
123  $hasErrors = false;
124  $dependencyTypes = null;
125  $configuration = [
126  'value' => [
127  'dependencies' => [],
128  ],
129  ];
130  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
131  if (!$isAutomaticInstallationEnabled) {
132  // if automatic installation is deactivated, no dependency check is needed (download only)
133  $action = 'installExtensionWithoutSystemDependencyCheck';
134  } else {
135  $action = 'installFromTer';
136  try {
137  $dependencyTypes = $this->managementService->getAndResolveDependencies($extension);
138  if (!empty($dependencyTypes)) {
139  $hasDependencies = true;
140  $message = '<p>' . $this->‪translate('downloadExtension.dependencies.headline') . '</p>';
141  foreach ($dependencyTypes as $dependencyType => $dependencies) {
142  $extensions = '';
143  foreach ($dependencies as $extensionKey => $dependency) {
144  if (!isset($configuration['value']['dependencies'][$dependencyType])) {
145  $configuration['value']['dependencies'][$dependencyType] = [];
146  }
147  $configuration['value']['dependencies'][$dependencyType][$extensionKey] = [
148  '_exclude' => [
149  'categoryIndexFromStringOrNumber',
150  ],
151  ];
152  $extensions .= $this->‪translate(
153  'downloadExtension.dependencies.extensionWithVersion',
154  [
155  $extensionKey, $dependency->getVersion()
156  ]
157  ) . '<br />';
158  }
159  $message .= $this->‪translate(
160  'downloadExtension.dependencies.typeHeadline',
161  [
162  $this->‪translate('downloadExtension.dependencyType.' . $dependencyType),
163  $extensions
164  ]
165  );
166  }
167  $title = $this->‪translate('downloadExtension.dependencies.resolveAutomatically');
168  }
169  } catch (\‪Exception $e) {
170  $hasErrors = true;
171  $title = $this->‪translate('downloadExtension.dependencies.errorTitle');
172  $message = $e->getMessage();
173  }
174  }
175 
176  $url = $this->uriBuilder->uriFor(
177  $action,
178  ['extension' => $extension->getUid(), 'format' => 'json'],
179  'Download'
180  );
181  $this->view->setConfiguration($configuration);
182  $this->view->assign('value', [
183  'dependencies' => $dependencyTypes,
184  'url' => $url,
185  'message' => $message,
186  'hasErrors' => $hasErrors,
187  'hasDependencies' => $hasDependencies,
188  'title' => $title
189  ]);
190  }
191 
198  public function ‪installFromTerAction(\‪TYPO3\CMS\Extensionmanager\Domain\Model\‪Extension $extension, $downloadPath = 'Local')
199  {
200  list($result, $errorMessages) = $this->‪installFromTer($extension, $downloadPath);
201  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
202  $this->view
203  ->assign('result', $result)
204  ->assign('extension', $extension)
205  ->assign('installationTypeLanguageKey', $isAutomaticInstallationEnabled ? '' : '.downloadOnly')
206  ->assign('unresolvedDependencies', $errorMessages);
207  }
208 
215  public function ‪installExtensionWithoutSystemDependencyCheckAction(\‪TYPO3\CMS\Extensionmanager\Domain\Model\‪Extension $extension)
216  {
217  $this->managementService->setSkipDependencyCheck(true);
218  $this->‪forward('installFromTer', null, null, ['extension' => $extension, 'downloadPath' => 'Local']);
219  }
220 
227  public function ‪installDistributionAction(\‪TYPO3\CMS\Extensionmanager\Domain\Model\‪Extension $extension)
228  {
229  if (!\‪TYPO3\CMS\Core\Utility\‪ExtensionManagementUtility::isLoaded('impexp')) {
230  $this->‪forward('distributions', 'List');
231  }
232  list($result, $errorMessages) = $this->‪installFromTer($extension);
233  if ($errorMessages) {
234  foreach ($errorMessages as $extensionKey => $messages) {
235  foreach ($messages as $message) {
236  $this->‪addFlashMessage(
237  $message['message'],
239  'distribution.error.headline',
240  'extensionmanager',
241  [$extensionKey]
242  ),
243  \‪TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
244  );
245  }
246  }
247 
248  // Redirect back to distributions list action
249  $this->‪redirect(
250  'distributions',
251  'List'
252  );
253  } else {
254  // FlashMessage that extension is installed
255  $this->‪addFlashMessage(
257  'distribution.welcome.message',
258  'extensionmanager',
259  [$extension->getExtensionKey()]
260  ),
261  \‪TYPO3\CMS\‪Extbase\Utility\‪LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager')
262  );
263 
264  // Redirect to show action
265  $this->‪redirect(
266  'show',
267  'Distribution',
268  null,
269  ['extension' => $extension]
270  );
271  }
272  }
273 
282  protected function ‪updateExtensionAction()
283  {
284  $extensionKey = $this->request->getArgument('extension');
285  $version = $this->request->getArgument('version');
286  $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
287  if (!$extension instanceof ‪Extension) {
288  $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
289  }
291  try {
292  if (in_array($extensionKey, $installedExtensions, true)) {
293  // To resolve new dependencies the extension is installed again
294  $this->managementService->installExtension($extension);
295  } else {
296  $this->managementService->downloadMainExtension($extension);
297  }
298  $this->‪addFlashMessage(
299  $this->‪translate('extensionList.updateFlashMessage.body', [$extensionKey]),
300  $this->‪translate('extensionList.updateFlashMessage.title')
301  );
302  } catch (\Exception $e) {
303  $this->‪addFlashMessage($e->getMessage(), '', ‪FlashMessage::ERROR);
304  }
305 
306  return '';
307  }
308 
314  protected function ‪updateCommentForUpdatableVersionsAction()
315  {
316  $extensionKey = $this->request->getArgument('extension');
317  $versionStart = $this->request->getArgument('integerVersionStart');
318  $versionStop = $this->request->getArgument('integerVersionStop');
319  $updateComments = [];
321  $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
322  $extensionKey,
323  $versionStart,
324  $versionStop,
325  false
326  );
327  $highestPossibleVersion = false;
328 
329  foreach ($updatableVersions as $updatableVersion) {
330  if ($highestPossibleVersion === false) {
331  $highestPossibleVersion = $updatableVersion->getVersion();
332  }
333  $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
334  }
335 
336  $this->view->assign('value', [
337  'updateComments' => $updateComments,
338  'url' => $this->uriBuilder->uriFor(
339  'updateExtension',
340  ['extension' => $extensionKey, 'version' => $highestPossibleVersion]
341  )
342  ]);
343  }
344 
353  protected function ‪installFromTer(\‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
354  {
355  $result = false;
356  $errorMessages = [];
357  try {
358  $this->downloadUtility->setDownloadPath($downloadPath);
359  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
360  $this->managementService->setAutomaticInstallationEnabled($isAutomaticInstallationEnabled);
361  if (($result = $this->managementService->installExtension($extension)) === false) {
362  $errorMessages = $this->managementService->getDependencyErrors();
363  }
364  } catch (\‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
365  $errorMessages = [
366  $extension->getExtensionKey() => [
367  [
368  'code' => $e->getCode(),
369  'message' => $e->getMessage(),
370  ]
371  ],
372  ];
373  }
374 
375  return [$result, $errorMessages];
376  }
377 }
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$installUtility
‪TYPO3 CMS Extensionmanager Utility InstallUtility $installUtility
Definition: DownloadController.php:43
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\translate
‪string null translate($key, $arguments=null)
Definition: AbstractController.php:41
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$downloadUtility
‪TYPO3 CMS Extensionmanager Utility DownloadUtility $downloadUtility
Definition: DownloadController.php:47
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\initializeInstallFromTerAction
‪initializeInstallFromTerAction()
Definition: DownloadController.php:100
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installFromTer
‪array installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath='Local')
Definition: DownloadController.php:346
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:24
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectManagementService
‪injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
Definition: DownloadController.php:76
‪TYPO3
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$view
‪JsonView $view
Definition: DownloadController.php:55
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController
Definition: DownloadController.php:28
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:2
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectDownloadUtility
‪injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility)
Definition: DownloadController.php:92
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installDistributionAction
‪installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
Definition: DownloadController.php:220
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\checkDependenciesAction
‪checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
Definition: DownloadController.php:111
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$managementService
‪TYPO3 CMS Extensionmanager Service ExtensionManagementService $managementService
Definition: DownloadController.php:39
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectExtensionRepository
‪injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
Definition: DownloadController.php:60
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$extensionRepository
‪TYPO3 CMS Extensionmanager Domain Repository ExtensionRepository $extensionRepository
Definition: DownloadController.php:31
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$defaultViewObjectName
‪JsonView $defaultViewObjectName
Definition: DownloadController.php:51
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\updateCommentForUpdatableVersionsAction
‪updateCommentForUpdatableVersionsAction()
Definition: DownloadController.php:307
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectInstallUtility
‪injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
Definition: DownloadController.php:84
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\redirect
‪redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
Definition: AbstractController.php:284
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\$fileHandlingUtility
‪TYPO3 CMS Extensionmanager Utility FileHandlingUtility $fileHandlingUtility
Definition: DownloadController.php:35
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key, $exitOnError=null)
Definition: ExtensionManagementUtility.php:115
‪TYPO3\CMS\Extensionmanager\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:23
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installExtensionWithoutSystemDependencyCheckAction
‪installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
Definition: DownloadController.php:208
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\injectFileHandlingUtility
‪injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
Definition: DownloadController.php:68
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController
Definition: AbstractController.php:22
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\installFromTerAction
‪installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath='Local')
Definition: DownloadController.php:191
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getLoadedExtensionListArray
‪static array getLoadedExtensionListArray()
Definition: ExtensionManagementUtility.php:1909
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\addFlashMessage
‪addFlashMessage($messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)
Definition: AbstractController.php:154
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: AbstractController.php:247
‪TYPO3\CMS\Extensionmanager\Controller\DownloadController\updateExtensionAction
‪string updateExtensionAction()
Definition: DownloadController.php:275