‪TYPO3CMS  10.4
ActionController.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 
32 
39 {
43  protected ‪$installUtility;
44 
48  protected ‪$fileHandlingUtility;
49 
53  protected ‪$extensionModelUtility;
54 
58  protected ‪$managementService;
59 
63  public function ‪injectInstallUtility(‪InstallUtility $installUtility)
64  {
65  $this->installUtility = $installUtility;
66  }
67 
71  public function ‪injectFileHandlingUtility(‪FileHandlingUtility $fileHandlingUtility)
72  {
73  $this->fileHandlingUtility = $fileHandlingUtility;
74  }
75 
79  public function ‪injectExtensionModelUtility(‪ExtensionModelUtility $extensionModelUtility)
80  {
81  $this->extensionModelUtility = $extensionModelUtility;
82  }
83 
87  public function ‪injectManagementService(‪ExtensionManagementService $managementService)
88  {
89  $this->managementService = $managementService;
90  }
91 
97  protected function toggleExtensionInstallationStateAction($extensionKey)
98  {
100  try {
101  if (in_array($extensionKey, $installedExtensions)) {
102  // uninstall
103  $this->installUtility->uninstall($extensionKey);
104  } else {
105  // install
106  $extension = $this->extensionModelUtility->mapExtensionArrayToModel(
107  $this->installUtility->enrichExtensionWithDetails($extensionKey, false)
108  );
109  if ($this->managementService->installExtension($extension) === false) {
110  $this->‪redirect('unresolvedDependencies', 'List', null, ['extensionKey' => $extensionKey]);
111  }
112  }
113  } catch (ExtensionManagerException|PackageStatesFileNotWritableException $e) {
114  $this->‪addFlashMessage($e->getMessage(), '', ‪FlashMessage::ERROR);
115  }
116  $this->‪redirect('index', 'List', null, [
117  self::TRIGGER_RefreshModuleMenu => true,
118  self::TRIGGER_RefreshTopbar => true
119  ]);
120  }
121 
127  public function ‪installExtensionWithoutSystemDependencyCheckAction($extensionKey)
128  {
129  $this->managementService->setSkipDependencyCheck(true);
130  $this->‪forward('toggleExtensionInstallationState', null, null, ['extensionKey' => $extensionKey]);
131  }
132 
139  protected function ‪removeExtensionAction($extension)
140  {
141  try {
143  throw new ExtensionManagerException(
144  'The system is set to composer mode. You are not allowed to remove any extension.',
145  1590314046
146  );
147  }
148 
149  $this->installUtility->removeExtension($extension);
150  $this->‪addFlashMessage(
152  'extensionList.remove.message',
153  'extensionmanager',
154  [
155  'extension' => $extension,
156  ]
157  ) ?? ''
158  );
159  } catch (ExtensionManagerException|Exception $e) {
160  $this->‪addFlashMessage($e->getMessage(), '', ‪FlashMessage::ERROR);
161  }
162 
163  return '';
164  }
165 
171  protected function ‪downloadExtensionZipAction($extension)
172  {
173  $fileName = $this->fileHandlingUtility->createZipFileFromExtension($extension);
174  $this->‪sendZipFileToBrowserAndDelete($fileName);
175  }
176 
182  protected function ‪sendZipFileToBrowserAndDelete(string $fileName): void
183  {
184  header('Content-Type: application/zip');
185  header('Content-Length: ' . filesize($fileName));
186  header('Content-Disposition: attachment; filename="' . ‪PathUtility::basename($fileName) . '"');
187  readfile($fileName);
188  unlink($fileName);
189  die;
190  }
191 
197  protected function ‪reloadExtensionDataAction($extension)
198  {
199  $extension = $this->installUtility->enrichExtensionWithDetails($extension, false);
200  $registryKey = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
201 
202  $registry = GeneralUtility::makeInstance(Registry::class);
203  $registry->remove('extensionDataImport', $registryKey);
204 
205  $this->installUtility->processExtensionSetup($extension['key']);
206 
207  $this->‪redirect('index', 'List');
208  }
209 }
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\removeExtensionAction
‪string removeExtensionAction($extension)
Definition: ActionController.php:135
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: ActionController.php:815
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\sendZipFileToBrowserAndDelete
‪sendZipFileToBrowserAndDelete(string $fileName)
Definition: ActionController.php:178
‪TYPO3\CMS\Core\Package\Exception\PackageStatesFileNotWritableException
Definition: PackageStatesFileNotWritableException.php:24
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Core\Package\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
Definition: ExtensionModelUtility.php:28
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\injectManagementService
‪injectManagementService(ExtensionManagementService $managementService)
Definition: ActionController.php:83
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\$managementService
‪ExtensionManagementService $managementService
Definition: ActionController.php:54
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\injectExtensionModelUtility
‪injectExtensionModelUtility(ExtensionModelUtility $extensionModelUtility)
Definition: ActionController.php:75
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\$installUtility
‪InstallUtility $installUtility
Definition: ActionController.php:42
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:16
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\addFlashMessage
‪addFlashMessage($messageBody, $messageTitle='', $severity=AbstractMessage::OK, $storeInSession=true)
Definition: ActionController.php:747
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static string basename($path)
Definition: PathUtility.php:165
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:35
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\injectInstallUtility
‪injectInstallUtility(InstallUtility $installUtility)
Definition: ActionController.php:59
‪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\Utility\InstallUtility
Definition: InstallUtility.php:55
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\reloadExtensionDataAction
‪reloadExtensionDataAction($extension)
Definition: ActionController.php:193
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\toggleExtensionInstallationStateAction
‪toggleExtensionInstallationStateAction($extensionKey)
Definition: ActionController.php:93
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\installExtensionWithoutSystemDependencyCheckAction
‪installExtensionWithoutSystemDependencyCheckAction($extensionKey)
Definition: ActionController.php:123
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\injectFileHandlingUtility
‪injectFileHandlingUtility(FileHandlingUtility $fileHandlingUtility)
Definition: ActionController.php:67
‪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\ActionController\$fileHandlingUtility
‪FileHandlingUtility $fileHandlingUtility
Definition: ActionController.php:46
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController
Definition: AbstractController.php:26
‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
Definition: ExtensionManagementService.php:33
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:144
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:55
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getLoadedExtensionListArray
‪static array getLoadedExtensionListArray()
Definition: ExtensionManagementUtility.php:1852
‪TYPO3\CMS\Core\Package\Exception
Definition: InvalidPackageKeyException.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\downloadExtensionZipAction
‪downloadExtensionZipAction($extension)
Definition: ActionController.php:167
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Extensionmanager\Controller\ActionController\$extensionModelUtility
‪ExtensionModelUtility $extensionModelUtility
Definition: ActionController.php:50