TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DownloadController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
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 
237  public function installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
238  {
239  if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp')) {
240  $this->forward('distributions', 'List');
241  }
242  list($result, $errorMessages) = $this->installFromTer($extension);
243  if ($errorMessages) {
244  foreach ($errorMessages as $extensionKey => $messages) {
245  foreach ($messages as $message) {
246  $this->addFlashMessage(
247  $message['message'],
248  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
249  'distribution.error.headline',
250  'extensionmanager',
251  [$extensionKey]
252  ),
253  \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR
254  );
255  }
256  }
257 
258  // Redirect back to distributions list action
259  $this->redirect(
260  'distributions',
261  'List'
262  );
263  } else {
264  // FlashMessage that extension is installed
265  $this->addFlashMessage(
266  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.message', 'extensionmanager')
267  . $extension->getExtensionKey(),
268  \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('distribution.welcome.headline', 'extensionmanager')
269  );
270 
271  // Redirect to show action
272  $this->redirect(
273  'show',
274  'Distribution',
275  null,
276  ['extension' => $extension]
277  );
278  }
279  }
280 
289  protected function updateExtensionAction()
290  {
291  $extensionKey = $this->request->getArgument('extension');
292  $version = $this->request->getArgument('version');
293  $extension = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
294  if (!$extension instanceof Extension) {
295  $extension = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
296  }
298  try {
299  if (in_array($extensionKey, $installedExtensions, true)) {
300  // To resolve new dependencies the extension is installed again
301  $this->managementService->installExtension($extension);
302  } else {
303  $this->managementService->downloadMainExtension($extension);
304  }
305  $this->addFlashMessage(
306  $this->translate('extensionList.updateFlashMessage.body', [$extensionKey]),
307  $this->translate('extensionList.updateFlashMessage.title')
308  );
309  } catch (\Exception $e) {
310  $this->addFlashMessage($e->getMessage(), '', FlashMessage::ERROR);
311  }
312 
313  return '';
314  }
315 
323  protected function updateCommentForUpdatableVersionsAction()
324  {
325  $extensionKey = $this->request->getArgument('extension');
326  $versionStart = $this->request->getArgument('integerVersionStart');
327  $versionStop = $this->request->getArgument('integerVersionStop');
328  $updateComments = [];
330  $updatableVersions = $this->extensionRepository->findByVersionRangeAndExtensionKeyOrderedByVersion(
331  $extensionKey,
332  $versionStart,
333  $versionStop,
334  false
335  );
336  $highestPossibleVersion = false;
337 
338  foreach ($updatableVersions as $updatableVersion) {
339  if ($highestPossibleVersion === false) {
340  $highestPossibleVersion = $updatableVersion->getVersion();
341  }
342  $updateComments[$updatableVersion->getVersion()] = $updatableVersion->getUpdateComment();
343  }
344 
345  $this->view->assign('value', [
346  'updateComments' => $updateComments,
347  'url' => $this->uriBuilder->uriFor(
348  'updateExtension',
349  ['extension' => $extensionKey, 'version' => $highestPossibleVersion]
350  )
351  ]);
352  }
353 
362  protected function installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath = 'Local')
363  {
364  $result = false;
365  $errorMessages = [];
366  try {
367  $this->downloadUtility->setDownloadPath($downloadPath);
368  $this->managementService->setAutomaticInstallationEnabled($this->configurationUtility->getCurrentConfiguration('extensionmanager')['automaticInstallation']['value']);
369  if (($result = $this->managementService->installExtension($extension)) === false) {
370  $errorMessages = $this->managementService->getDependencyErrors();
371  }
372  } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
373  $errorMessages = [
374  $extension->getExtensionKey() => [
375  [
376  'code' => $e->getCode(),
377  'message' => $e->getMessage(),
378  ]
379  ],
380  ];
381  }
382 
383  return [$result, $errorMessages];
384  }
385 }
installFromTer(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath= 'Local')
redirect($actionName, $controllerName=null, $extensionName=null, array $arguments=null, $pageUid=null, $delay=0, $statusCode=303)
forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
installFromTerAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $downloadPath= 'Local')
checkDependenciesAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
installExtensionWithoutSystemDependencyCheckAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
installDistributionAction(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension)
static translate($key, $extensionName, $arguments=null)
injectDownloadUtility(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility $downloadUtility)
injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
addFlashMessage($messageBody, $messageTitle= '', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)
injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)