TYPO3 CMS  TYPO3_7-6
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 
116  protected function initializeView(ViewInterface $view)
117  {
118  if ($view instanceof BackendTemplateView) {
120  parent::initializeView($view);
121  $this->generateMenu();
122  $this->registerDocheaderButtons();
123  }
124  }
125 
129  protected function addComposerModeNotification()
130  {
132  $this->addFlashMessage(
134  'composerMode.message',
135  'extensionmanager'
136  ),
138  'composerMode.title',
139  'extensionmanager'
140  ),
142  );
143  }
144  }
145 
151  public function indexAction()
152  {
154  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
155  ksort($availableAndInstalledExtensions);
156  $this->view->assign('extensions', $availableAndInstalledExtensions);
157  $this->handleTriggerArguments();
158  }
159 
167  public function unresolvedDependenciesAction($extensionKey)
168  {
169  $availableExtensions = $this->listUtility->getAvailableExtensions();
170  if (isset($availableExtensions[$extensionKey])) {
171  $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
172  [
173  $extensionKey => $availableExtensions[$extensionKey]
174  ]
175  );
177  $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
178  $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
179  } else {
180  throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
181  }
182  $this->dependencyUtility->checkDependencies($extension);
183  $this->view->assign('extension', $extension);
184  $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
185  }
186 
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 
215  public function distributionsAction($showUnsuitableDistributions = false)
216  {
218  $importExportInstalled = ExtensionManagementUtility::isLoaded('impexp');
219  if ($importExportInstalled) {
220  try {
222  $repositoryHelper = $this->objectManager->get(Helper::class);
223  // Check if a TER update has been done at all, if not, fetch it directly
224  // Repository needs an update, but not because of the extension hash has changed
225  $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
226  if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
227  $repositoryHelper->updateExtList();
228  }
229  } catch (ExtensionManagerException $e) {
230  $this->addFlashMessage($e->getMessage(), $e->getCode(), FlashMessage::ERROR);
231  }
232 
233  $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
234  $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
235 
236  $officialDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($officialDistributions->toArray(), $showUnsuitableDistributions);
237  $communityDistributions = $this->dependencyUtility->filterYoungestVersionOfExtensionList($communityDistributions->toArray(), $showUnsuitableDistributions);
238 
239  $this->view->assign('officialDistributions', $officialDistributions);
240  $this->view->assign('communityDistributions', $communityDistributions);
241  }
242  $this->view->assign('enableDistributionsView', $importExportInstalled);
243  $this->view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
244  }
245 
252  public function showAllVersionsAction($extensionKey)
253  {
254  $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
255  $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
256 
257  $this->view->assignMultiple(
258  [
259  'extensionKey' => $extensionKey,
260  'currentVersion' => $currentVersion,
261  'extensions' => $extensions
262  ]
263  );
264  }
265 
271  protected function registerDocheaderButtons()
272  {
274  return;
275  }
276 
277  if (!in_array($this->actionMethodName, ['indexAction', 'terAction', 'showAllVersionsAction'], true)) {
278  return;
279  }
280 
282  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
283  $uriBuilder = $this->controllerContext->getUriBuilder();
284 
285  if ($this->actionMethodName === 'showAllVersionsAction') {
286  $uri = $uriBuilder->reset()->uriFor('ter', [], 'List');
287  $title = $this->translate('extConfTemplate.backToList');
288  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL);
289  $classes = '';
290  } else {
291  $uri = $uriBuilder->reset()->uriFor('form', [], 'UploadExtensionFile');
292  $title = $this->translate('extensionList.uploadExtension');
293  $icon = $this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-edit-upload', Icon::SIZE_SMALL);
294  $classes = 't3js-upload';
295  }
296  $button = $buttonBar->makeLinkButton()
297  ->setHref($uri)
298  ->setTitle($title)
299  ->setClasses($classes)
300  ->setIcon($icon);
301  $buttonBar->addButton($button, ButtonBar::BUTTON_POSITION_LEFT);
302  }
303 }
static translate($key, $extensionName, $arguments=null)
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
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)