[TASK] Enable EM offline mode when using composer
[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\Core\Bootstrap;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
21 use TYPO3\CMS\Extensionmanager\Domain\Model\Dependency;
22 use TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException;
23 use TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility;
24 use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper;
25
26 /**
27 * Controller for extension listings (TER or local extensions)
28 */
29 class ListController extends AbstractController
30 {
31 /**
32 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
33 */
34 protected $extensionRepository;
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
38 */
39 protected $listUtility;
40
41 /**
42 * @var \TYPO3\CMS\Core\Page\PageRenderer
43 */
44 protected $pageRenderer;
45
46 /**
47 * @var \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
48 */
49 protected $dependencyUtility;
50
51 /**
52 * @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility
53 */
54 protected $configurationUtility;
55
56 /**
57 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
58 */
59 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
60 {
61 $this->extensionRepository = $extensionRepository;
62 }
63
64 /**
65 * @param \TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility
66 */
67 public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
68 {
69 $this->listUtility = $listUtility;
70 }
71
72 /**
73 * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer
74 */
75 public function injectPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer)
76 {
77 $this->pageRenderer = $pageRenderer;
78 }
79
80 /**
81 * @param \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility
82 */
83 public function injectDependencyUtility(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility $dependencyUtility)
84 {
85 $this->dependencyUtility = $dependencyUtility;
86 }
87
88 /**
89 * @param \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility
90 */
91 public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
92 {
93 $this->configurationUtility = $configurationUtility;
94 }
95
96 /**
97 * Add the needed JavaScript files for all actions
98 */
99 public function initializeAction()
100 {
101 $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
102 if ($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value']) {
103 $this->settings['offlineMode'] = true;
104 }
105 if (Bootstrap::usesComposerClassLoading()) {
106 $this->settings['composerMode'] = true;
107 }
108 }
109
110 /**
111 * Adds an information about composer mode
112 */
113 protected function addComposerModeNotification()
114 {
115 if (Bootstrap::usesComposerClassLoading()) {
116 $this->addFlashMessage(
117 LocalizationUtility::translate(
118 'composerMode.message',
119 'extensionmanager'
120 ),
121 LocalizationUtility::translate(
122 'composerMode.title',
123 'extensionmanager'
124 ),
125 FlashMessage::WARNING
126 );
127 }
128 }
129
130 /**
131 * Shows list of extensions present in the system
132 *
133 * @return void
134 */
135 public function indexAction()
136 {
137 $this->addComposerModeNotification();
138 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
139 $this->view->assign('extensions', $availableAndInstalledExtensions);
140 $this->handleTriggerArguments();
141 }
142
143 /**
144 * Shows a list of unresolved dependency errors with the possibility to bypass the dependency check
145 *
146 * @param string $extensionKey
147 * @throws ExtensionManagerException
148 * @return void
149 */
150 public function unresolvedDependenciesAction($extensionKey)
151 {
152 $availableExtensions = $this->listUtility->getAvailableExtensions();
153 if (isset($availableExtensions[$extensionKey])) {
154 $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
155 array(
156 $extensionKey => $availableExtensions[$extensionKey]
157 )
158 );
159 /** @var ExtensionModelUtility $extensionModelUtility */
160 $extensionModelUtility = $this->objectManager->get(ExtensionModelUtility::class);
161 $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
162 } else {
163 throw new ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
164 }
165 $this->dependencyUtility->checkDependencies($extension);
166 $this->view->assign('extension', $extension);
167 $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
168 }
169
170 /**
171 * Shows extensions from TER
172 * Either all extensions or depending on a search param
173 *
174 * @param string $search
175 * @return void
176 */
177 public function terAction($search = '')
178 {
179 $this->addComposerModeNotification();
180 $search = trim($search);
181 if (!empty($search)) {
182 $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
183 } else {
184 $extensions = $this->extensionRepository->findAll();
185 }
186 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($this->listUtility->getAvailableExtensions());
187 $this->view->assign('extensions', $extensions)
188 ->assign('search', $search)
189 ->assign('availableAndInstalled', $availableAndInstalledExtensions);
190 }
191
192 /**
193 * Action for listing all possible distributions
194 *
195 * @param bool $showUnsuitableDistributions
196 * @return void
197 */
198 public function distributionsAction($showUnsuitableDistributions = false)
199 {
200 $this->addComposerModeNotification();
201 $importExportInstalled = ExtensionManagementUtility::isLoaded('impexp');
202 if ($importExportInstalled) {
203 try {
204 /** @var $repositoryHelper Helper */
205 $repositoryHelper = $this->objectManager->get(Helper::class);
206 // Check if a TER update has been done at all, if not, fetch it directly
207 // Repository needs an update, but not because of the extension hash has changed
208 $isExtListUpdateNecessary = $repositoryHelper->isExtListUpdateNecessary();
209 if ($isExtListUpdateNecessary > 0 && ($isExtListUpdateNecessary & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
210 $repositoryHelper->updateExtList();
211 }
212 } catch (ExtensionManagerException $e) {
213 $this->addFlashMessage($e->getMessage(), $e->getCode(), FlashMessage::ERROR);
214 }
215
216 $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
217 $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
218
219 if (!$showUnsuitableDistributions) {
220 $suitableOfficialDistributions = $this->dependencyUtility->getExtensionsSuitableForTypo3Version($officialDistributions);
221 $this->view->assign('officialDistributions', $suitableOfficialDistributions);
222 $suitableCommunityDistributions = $this->dependencyUtility->getExtensionsSuitableForTypo3Version($communityDistributions);
223 $this->view->assign('communityDistributions', $suitableCommunityDistributions);
224 } else {
225 $this->view->assign('officialDistributions', $officialDistributions);
226 $this->view->assign('communityDistributions', $communityDistributions);
227 }
228 }
229 $this->view->assign('enableDistributionsView', $importExportInstalled);
230 $this->view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
231 }
232
233 /**
234 * Shows all versions of a specific extension
235 *
236 * @param string $extensionKey
237 * @return void
238 */
239 public function showAllVersionsAction($extensionKey)
240 {
241 $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
242 $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
243
244 $this->view->assignMultiple(
245 array(
246 'extensionKey' => $extensionKey,
247 'currentVersion' => $currentVersion,
248 'extensions' => $extensions
249 )
250 );
251 }
252 }