[TASK] Improve retrieving distribution list
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ListController.php
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
17 use TYPO3\CMS\Core\Messaging\FlashMessage;
18 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
20 use TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility;
21 use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper;
22
23 /**
24 * Controller for extension listings (TER or local extensions)
25 *
26 * @author Susanne Moog <typo3@susannemoog.de>
27 */
28 class ListController extends AbstractController {
29
30 /**
31 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
32 * @inject
33 */
34 protected $extensionRepository;
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
38 * @inject
39 */
40 protected $listUtility;
41
42 /**
43 * @var \TYPO3\CMS\Core\Page\PageRenderer
44 * @inject
45 */
46 protected $pageRenderer;
47
48 /**
49 * @var \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
50 * @inject
51 */
52 protected $dependencyUtility;
53
54 /**
55 * Add the needed JavaScript files for all actions
56 */
57 public function initializeAction() {
58 $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
59 }
60
61 /**
62 * Shows list of extensions present in the system
63 *
64 * @return void
65 */
66 public function indexAction() {
67 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
68 $this->view->assign('extensions', $availableAndInstalledExtensions);
69 $this->handleTriggerArguments();
70 }
71
72 /**
73 * Shows a list of unresolved dependency errors with the possibility to bypass the dependency check
74 *
75 * @param string $extensionKey
76 * @throws ExtensionManagerException
77 * @return void
78 */
79 public function unresolvedDependenciesAction($extensionKey) {
80 $availableExtensions = $this->listUtility->getAvailableExtensions();
81 if (isset($availableExtensions[$extensionKey])) {
82 $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
83 array(
84 $extensionKey => $availableExtensions[$extensionKey]
85 )
86 );
87 /** @var ExtensionModelUtility $extensionModelUtility */
88 $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
89 $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
90 } else {
91 throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
92 }
93 $this->dependencyUtility->checkDependencies($extension);
94 $this->view->assign('extension', $extension);
95 $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
96 }
97
98 /**
99 * Shows extensions from TER
100 * Either all extensions or depending on a search param
101 *
102 * @param string $search
103 * @return void
104 */
105 public function terAction($search = '') {
106 if (!empty($search)) {
107 $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
108 } else {
109 $extensions = $this->extensionRepository->findAll();
110 }
111 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
112 $this->view->assign('extensions', $extensions)
113 ->assign('search', $search)
114 ->assign('availableAndInstalled', $availableAndInstalledExtensions);
115 }
116
117 /**
118 * Action for listing all possible distributions
119 *
120 * @return void
121 */
122 public function distributionsAction() {
123 $importExportInstalled = ExtensionManagementUtility::isLoaded('impexp');
124 if ($importExportInstalled) {
125 try {
126 /** @var $repositoryHelper Helper */
127 $repositoryHelper = $this->objectManager->get(Helper::class);
128 // Check if a TER update has been done at all, if not, fetch it directly
129 // Repository needs an update, but not because of the extension hash has changed
130 $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
131 if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
132 $repositoryHelper->updateExtList();
133 }
134 } catch (ExtensionManagerException $e) {
135 $this->addFlashMessage(htmlspecialchars($e->getMessage()), $e->getCode(), FlashMessage::ERROR);
136 }
137
138 $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
139 $this->view->assign('officialDistributions', $officialDistributions);
140
141 $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
142 $this->view->assign('communityDistributions', $communityDistributions);
143 }
144 $this->view->assign('enableDistributionsView', $importExportInstalled);
145 }
146
147 /**
148 * Shows all versions of a specific extension
149 *
150 * @param string $extensionKey
151 * @return void
152 */
153 public function showAllVersionsAction($extensionKey) {
154 $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
155 $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
156
157 $this->view->assignMultiple(
158 array(
159 'extensionKey' => $extensionKey,
160 'currentVersion' => $currentVersion,
161 'extensions' => $extensions
162 )
163 );
164 }
165
166 }