‪TYPO3CMS  10.4
ListController.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 
39 
45 {
49  protected ‪$extensionRepository;
50 
54  protected ‪$listUtility;
55 
59  protected ‪$pageRenderer;
60 
65 
69  protected ‪$backendUserFilter = '';
70 
75  {
76  $this->extensionRepository = ‪$extensionRepository;
77  }
78 
83  {
84  $this->listUtility = ‪$listUtility;
85  }
86 
91  {
92  $this->pageRenderer = ‪$pageRenderer;
93  }
94 
99  {
100  $this->dependencyUtility = ‪$dependencyUtility;
101  }
102 
106  public function ‪initializeAction()
107  {
108  $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
109  $isAutomaticInstallationEnabled = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'offlineMode');
110  if ($isAutomaticInstallationEnabled) {
111  $this->settings['offlineMode'] = true;
112  }
113  }
114 
120  protected function ‪initializeView(ViewInterface ‪$view)
121  {
122  if (‪$view instanceof BackendTemplateView) {
124  parent::initializeView(‪$view);
125  $this->‪generateMenu();
127  }
128  }
129 
133  protected function ‪addComposerModeNotification()
134  {
136  $this->‪addFlashMessage(
138  'composerMode.message',
139  'extensionmanager'
140  ) ?? '',
142  'composerMode.title',
143  'extensionmanager'
144  ) ?? '',
146  );
147  }
148  }
149 
153  public function ‪indexAction()
154  {
155  if ($this->request->hasArgument('filter') && is_string($this->request->getArgument('filter'))) {
156  $this->backendUserFilter = $this->request->getArgument('filter');
157  $this->‪saveBackendUserFilter();
158  } else {
159  $this->backendUserFilter = $this->‪getBackendUserFilter();
160  }
161 
163  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation($this->backendUserFilter);
164  ksort($availableAndInstalledExtensions);
165  $this->view->assignMultiple(
166  [
167  'extensions' => $availableAndInstalledExtensions,
168  'isComposerMode' => ‪Environment::isComposerMode(),
169  'backendUserFilter' => $this->backendUserFilter ?: 'All'
170  ]
171  );
172  $this->‪handleTriggerArguments();
173  }
174 
181  public function ‪unresolvedDependenciesAction($extensionKey)
182  {
183  $availableExtensions = $this->listUtility->getAvailableExtensions();
184  if (isset($availableExtensions[$extensionKey])) {
185  $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
186  [
187  $extensionKey => $availableExtensions[$extensionKey]
188  ]
189  );
191  $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
192  $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
193  } else {
194  throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
195  }
196  $this->dependencyUtility->checkDependencies($extension);
197  $this->view->assign('extension', $extension);
198  $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
199  }
200 
207  public function ‪terAction($search = '')
208  {
210  $search = trim($search);
211  if (!empty($search)) {
212  $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
213  } else {
214  $extensions = $this->extensionRepository->findAll();
215  }
216  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($this->listUtility->getAvailableExtensions());
217  $this->view->assign('extensions', $extensions)
218  ->assign('search', $search)
219  ->assign('availableAndInstalled', $availableAndInstalledExtensions);
220  }
221 
227  public function ‪distributionsAction($showUnsuitableDistributions = false)
228  {
230  $importExportInstalled = ‪ExtensionManagementUtility::isLoaded('impexp');
231  if ($importExportInstalled) {
232  try {
234  $repositoryHelper = $this->objectManager->get(Helper::class);
235  // Check if a TER update has been done at all, if not, fetch it directly
236  // Repository needs an update, but not because of the extension hash has changed
237  $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
238  if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
239  $repositoryHelper->updateExtList();
240  }
241  } catch (ExtensionManagerException $e) {
242  $this->‪addFlashMessage($e->getMessage(), $e->getCode(), ‪FlashMessage::ERROR);
243  }
244 
245  $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
246  $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
247 
248  $officialDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($officialDistributions->toArray(), $showUnsuitableDistributions);
249  $communityDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($communityDistributions->toArray(), $showUnsuitableDistributions);
250 
251  $this->view->assign('officialDistributions', $officialDistributions);
252  $this->view->assign('communityDistributions', $communityDistributions);
253  }
254  $this->view->assign('enableDistributionsView', $importExportInstalled);
255  $this->view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
256  }
257 
263  public function ‪showAllVersionsAction($extensionKey)
264  {
265  $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
266  $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
267 
268  $this->view->assignMultiple(
269  [
270  'extensionKey' => $extensionKey,
271  'currentVersion' => $currentVersion,
272  'extensions' => $extensions
273  ]
274  );
275  }
276 
282  protected function ‪registerDocheaderButtons()
283  {
285  return;
286  }
287 
288  if (!in_array($this->actionMethodName, ['indexAction', 'terAction', 'showAllVersionsAction'], true)) {
289  return;
290  }
291 
293  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
294  ‪$uriBuilder = $this->controllerContext->getUriBuilder();
295 
296  if ($this->actionMethodName === 'showAllVersionsAction') {
297  $uri = ‪$uriBuilder->‪reset()->uriFor('ter', [], 'List');
298  $title = $this->‪translate('extConfTemplate.backToList');
299  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL);
300  $classes = '';
301  } else {
302  $uri = ‪$uriBuilder->‪reset()->uriFor('form', [], 'UploadExtensionFile');
303  $title = $this->‪translate('extensionList.uploadExtension');
304  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-edit-upload', ‪Icon::SIZE_SMALL);
305  $classes = 't3js-upload';
306  }
307  $button = $buttonBar->makeLinkButton()
308  ->setHref($uri)
309  ->setTitle($title)
310  ->setClasses($classes)
311  ->setIcon($icon);
312  $buttonBar->addButton($button, ‪ButtonBar::BUTTON_POSITION_LEFT);
313  }
314 
315  protected function ‪getBackendUserFilter(): string
316  {
317  $backendUser = $this->‪getBackendUserAuthentication();
318 
319  if (!$backendUser instanceof ‪BackendUserAuthentication) {
320  return '';
321  }
322 
323  return $backendUser->uc['BackendComponents']['States']['ExtensionManager']['filter'] ?? '';
324  }
325 
326  protected function ‪saveBackendUserFilter(): void
327  {
328  $backendUser = $this->‪getBackendUserAuthentication();
329 
330  if (!$backendUser instanceof BackendUserAuthentication) {
331  return;
332  }
333 
334  $backendUserId = (int)$backendUser->user['uid'];
335  $backendUserRecord = ‪BackendUtility::getRecord('be_users', $backendUserId);
336 
337  if (is_array($backendUserRecord) && isset($backendUserRecord['uc'])) {
338  $uc = unserialize($backendUserRecord['uc'], ['allowed_classes' => false]);
339  if (is_array($uc)) {
340  $uc['BackendComponents']['States']['ExtensionManager']['filter'] = ‪$this->backendUserFilter;
341  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('be_users');
342  $connection->update('be_users', ['uc' => serialize($uc)], ['uid' => $backendUserId], ['uc' => ‪Connection::PARAM_LOB]);
343  }
344  }
345  }
346 
347  protected function ‪getBackendUserAuthentication(): ?BackendUserAuthentication
348  {
349  return ‪$GLOBALS['BE_USER'];
350  }
351 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Extensionmanager\Controller\ListController\indexAction
‪indexAction()
Definition: ListController.php:148
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪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\AbstractModuleController
Definition: AbstractModuleController.php:27
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Extensionmanager\Controller\ListController\addComposerModeNotification
‪addComposerModeNotification()
Definition: ListController.php:128
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
Definition: ExtensionModelUtility.php:28
‪TYPO3\CMS\Extensionmanager\Controller\AbstractModuleController\generateMenu
‪generateMenu()
Definition: AbstractModuleController.php:60
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder\reset
‪static reset()
Definition: UriBuilder.php:534
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$dependencyUtility
‪DependencyUtility $dependencyUtility
Definition: ListController.php:60
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$backendUserFilter
‪string $backendUserFilter
Definition: ListController.php:64
‪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\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Extensionmanager\Controller\ListController\injectListUtility
‪injectListUtility(ListUtility $listUtility)
Definition: ListController.php:77
‪TYPO3\CMS\Extensionmanager\Controller\ListController\initializeAction
‪initializeAction()
Definition: ListController.php:101
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: ListController.php:56
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Extensionmanager\Controller\ListController\injectExtensionRepository
‪injectExtensionRepository(ExtensionRepository $extensionRepository)
Definition: ListController.php:69
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:38
‪TYPO3\CMS\Extensionmanager\Controller\ListController\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: ListController.php:342
‪TYPO3\CMS\Extensionmanager\Controller\ListController\getBackendUserFilter
‪getBackendUserFilter()
Definition: ListController.php:310
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:35
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$uriBuilder
‪TYPO3 CMS Extbase Mvc Web Routing UriBuilder $uriBuilder
Definition: ActionController.php:127
‪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\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$listUtility
‪ListUtility $listUtility
Definition: ListController.php:52
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface
Definition: ViewInterface.php:24
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Extensionmanager\Controller\ListController\injectDependencyUtility
‪injectDependencyUtility(DependencyUtility $dependencyUtility)
Definition: ListController.php:93
‪TYPO3\CMS\Extensionmanager\Controller\ListController\unresolvedDependenciesAction
‪unresolvedDependenciesAction($extensionKey)
Definition: ListController.php:176
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Extensionmanager\Controller\ListController\registerDocheaderButtons
‪registerDocheaderButtons()
Definition: ListController.php:277
‪TYPO3\CMS\Extensionmanager\Controller\ListController\saveBackendUserFilter
‪saveBackendUserFilter()
Definition: ListController.php:321
‪TYPO3\CMS\Backend\View\BackendTemplateView
Definition: BackendTemplateView.php:28
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:144
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Extensionmanager\Controller\ListController\distributionsAction
‪distributionsAction($showUnsuitableDistributions=false)
Definition: ListController.php:222
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Extensionmanager\Controller\ListController\initializeView
‪initializeView(ViewInterface $view)
Definition: ListController.php:115
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extensionmanager\Controller\ListController\showAllVersionsAction
‪showAllVersionsAction($extensionKey)
Definition: ListController.php:258
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Extensionmanager\Controller\ListController
Definition: ListController.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
Definition: Helper.php:37
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\handleTriggerArguments
‪handleTriggerArguments()
Definition: AbstractController.php:54
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$extensionRepository
‪ExtensionRepository $extensionRepository
Definition: ListController.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\Controller\ListController\terAction
‪terAction($search='')
Definition: ListController.php:202
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Extensionmanager\Controller\AbstractModuleController\$view
‪BackendTemplateView $view
Definition: AbstractModuleController.php:32
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Core\Database\Connection\PARAM_LOB
‪const PARAM_LOB
Definition: Connection.php:57
‪TYPO3\CMS\Extensionmanager\Controller\ListController\injectPageRenderer
‪injectPageRenderer(PageRenderer $pageRenderer)
Definition: ListController.php:85