2bcd27f9f44cc924f666d856594d440bddb52de9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ListController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Controller for extension listings (TER or local extensions)
31 *
32 * @author Susanne Moog <typo3@susannemoog.de>
33 */
34 class ListController extends AbstractController {
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
38 * @inject
39 */
40 protected $extensionRepository;
41
42 /**
43 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
44 * @inject
45 */
46 protected $listUtility;
47
48 /**
49 * @var \TYPO3\CMS\Core\Page\PageRenderer
50 * @inject
51 */
52 protected $pageRenderer;
53
54 /**
55 * @var \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
56 * @inject
57 */
58 protected $dependencyUtility;
59
60 /**
61 * Add the needed JavaScript files for all actions
62 */
63 public function initializeAction() {
64 $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/notifications.js');
65 $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
66 }
67
68 /**
69 * Shows list of extensions present in the system
70 *
71 * @return void
72 */
73 public function indexAction() {
74 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
75 $this->view->assign('extensions', $availableAndInstalledExtensions);
76 $this->handleTriggerArguments();
77 }
78
79 /**
80 * Shows a list of unresolved dependency errors with the possibility to bypass the dependency check
81 *
82 * @param string $extensionKey
83 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
84 * @return void
85 */
86 public function unresolvedDependenciesAction($extensionKey) {
87 $availableExtensions = $this->listUtility->getAvailableExtensions();
88 if (isset($availableExtensions[$extensionKey])) {
89 $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
90 array(
91 $extensionKey => $availableExtensions[$extensionKey]
92 )
93 );
94 /** @var \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility $extensionModelUtility */
95 $extensionModelUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
96 $extension = $extensionModelUtility->mapExtensionArrayToModel($extensionArray[$extensionKey]);
97 } else {
98 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
99 }
100 $this->dependencyUtility->checkDependencies($extension);
101 $this->view->assign('extension', $extension);
102 $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
103 }
104
105 /**
106 * Shows extensions from TER
107 * Either all extensions or depending on a search param
108 *
109 * @param string $search
110 * @return void
111 */
112 public function terAction($search = '') {
113 if (!empty($search)) {
114 $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
115 } else {
116 $extensions = $this->extensionRepository->findAll();
117 }
118 $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
119 $this->view->assign('extensions', $extensions)
120 ->assign('search', $search)
121 ->assign('availableAndInstalled', $availableAndInstalledExtensions);
122 }
123
124 /**
125 * Action for listing all possible distributions
126 *
127 * @return void
128 */
129 public function distributionsAction() {
130 $importExportInstalled = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp');
131 if ($importExportInstalled) {
132 // check if a TER update has been done at all, if not, fetch it directly
133 /** @var $repositoryHelper \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper */
134 $repositoryHelper = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\Repository\\Helper');
135 // repository needs an update, but not because of the extension hash has changed
136 if ($repositoryHelper->isExtListUpdateNecessary() > 0 && ($repositoryHelper->isExtListUpdateNecessary() & $repositoryHelper::PROBLEM_EXTENSION_HASH_CHANGED) === 0) {
137 $repositoryHelper->fetchExtListFile();
138 $repositoryHelper->updateExtList();
139 }
140
141 $officialDistributions = $this->extensionRepository->findAllOfficialDistributions();
142 $this->view->assign('officialDistributions', $officialDistributions);
143
144 $communityDistributions = $this->extensionRepository->findAllCommunityDistributions();
145 $this->view->assign('communityDistributions', $communityDistributions);
146 }
147 $this->view->assign('enableDistributionsView', $importExportInstalled);
148 }
149
150 /**
151 * Shows all versions of a specific extension
152 *
153 * @param string $extensionKey
154 * @return void
155 */
156 public function showAllVersionsAction($extensionKey) {
157 $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
158 $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
159
160 $this->view->assignMultiple(
161 array(
162 'extensionKey' => $extensionKey,
163 'currentVersion' => $currentVersion,
164 'extensions' => $extensions
165 )
166 );
167 }
168 }