TYPO3 CMS  TYPO3_8-7
ListController.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 
28 
33 {
38 
42  protected $listUtility;
43 
47  protected $pageRenderer;
48 
52  protected $dependencyUtility;
53 
58 
62  public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
63  {
64  $this->extensionRepository = $extensionRepository;
65  }
66 
70  public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
71  {
72  $this->listUtility = $listUtility;
73  }
74 
78  public function injectPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer)
79  {
80  $this->pageRenderer = $pageRenderer;
81  }
82 
86  public function injectDependencyUtility(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility)
87  {
88  $this->dependencyUtility = $dependencyUtility;
89  }
90 
94  public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
95  {
96  $this->configurationUtility = $configurationUtility;
97  }
98 
102  public function initializeAction()
103  {
104  $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
105  if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
106  $this->settings['offlineMode'] = true;
107  }
108  }
109 
115  protected function initializeView(ViewInterface $view)
116  {
117  if ($view instanceof BackendTemplateView) {
119  parent::initializeView($view);
120  $this->generateMenu();
121  $this->registerDocheaderButtons();
122  }
123  }
124 
128  protected function addComposerModeNotification()
129  {
131  $this->addFlashMessage(
133  'composerMode.message',
134  'extensionmanager'
135  ),
137  'composerMode.title',
138  'extensionmanager'
139  ),
141  );
142  }
143  }
144 
148  public function indexAction()
149  {
151  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
152  ksort($availableAndInstalledExtensions);
153  $this->view->assignMultiple(
154  [
155  'extensions' => $availableAndInstalledExtensions,
156  'isComposerMode' => Bootstrap::usesComposerClassLoading(),
157  ]
158  );
159  $this->handleTriggerArguments();
160  }
161 
168  public function unresolvedDependenciesAction($extensionKey)
169  {
170  $availableExtensions = $this->listUtility->getAvailableExtensions();
171  if (isset($availableExtensions[$extensionKey])) {
172  $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
173  [
174  $extensionKey => $availableExtensions[$extensionKey]
175  ]
176  );
178  $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
179  $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
180  } else {
181  throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
182  }
183  $this->dependencyUtility->checkDependencies($extension);
184  $this->view->assign('extension', $extension);
185  $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
186  }
187 
194  public function terAction($search = '')
195  {
197  $search = trim($search);
198  if (!empty($search)) {
199  $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
200  } else {
201  $extensions = $this->extensionRepository->findAll();
202  }
203  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($this->listUtility->getAvailableExtensions());
204  $this->view->assign('extensions', $extensions)
205  ->assign('search', $search)
206  ->assign('availableAndInstalled', $availableAndInstalledExtensions);
207  }
208 
214  public function distributionsAction($showUnsuitableDistributions = false)
215  {
217  $importExportInstalled = ExtensionManagementUtility::isLoaded('impexp');
218  if ($importExportInstalled) {
219  try {
221  $repositoryHelper = $this->objectManager->get(Helper::class);
222  // Check if a TER update has been done at all, if not, fetch it directly
223  // Repository needs an update, but not because of the extension hash has changed
224  $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
225  if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
226  $repositoryHelper->updateExtList();
227  }
228  } catch (ExtensionManagerException $e) {
229  $this->addFlashMessage($e->getMessage(), $e->getCode(), FlashMessage::ERROR);
230  }
231 
232  $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
233  $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
234 
235  $officialDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($officialDistributions->toArray(), $showUnsuitableDistributions);
236  $communityDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($communityDistributions->toArray(), $showUnsuitableDistributions);
237 
238  $this->view->assign('officialDistributions', $officialDistributions);
239  $this->view->assign('communityDistributions', $communityDistributions);
240  }
241  $this->view->assign('enableDistributionsView', $importExportInstalled);
242  $this->view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
243  }
244 
250  public function showAllVersionsAction($extensionKey)
251  {
252  $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
253  $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
254 
255  $this->view->assignMultiple(
256  [
257  'extensionKey' => $extensionKey,
258  'currentVersion' => $currentVersion,
259  'extensions' => $extensions
260  ]
261  );
262  }
263 
269  protected function registerDocheaderButtons()
270  {
272  return;
273  }
274 
275  if (!in_array($this->actionMethodName, ['indexAction', 'terAction', 'showAllVersionsAction'], true)) {
276  return;
277  }
278 
280  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
281  $uriBuilder = $this->controllerContext->getUriBuilder();
282 
283  if ($this->actionMethodName === 'showAllVersionsAction') {
284  $uri = $uriBuilder->reset()->uriFor('ter', [], 'List');
285  $title = $this->translate('extConfTemplate.backToList');
286  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
287  $classes = '';
288  } else {
289  $uri = $uriBuilder->reset()->uriFor('form', [], 'UploadExtensionFile');
290  $title = $this->translate('extensionList.uploadExtension');
291  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-edit-upload', Icon::SIZE_SMALL);
292  $classes = 't3js-upload';
293  }
294  $button = $buttonBar->makeLinkButton()
295  ->setHref($uri)
296  ->setTitle($title)
297  ->setClasses($classes)
298  ->setIcon($icon);
299  $buttonBar->addButton($button, ButtonBar::BUTTON_POSITION_LEFT);
300  }
301 }
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
static translate($key, $extensionName=null, $arguments=null)
injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
injectPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer)
addFlashMessage($messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)
injectDependencyUtility(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility)