[TASK] Re-implement extension status for reports module
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / ListUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012
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 textfile 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 * Utility for dealing with extension list related functions
31 *
32 * @TODO: Refactor this API class:
33 * - The methods depend on each other, they take each others result, that could be done internally
34 * - There is no good wording to distinguish existing and loaded extensions
35 * - The name 'listUtility' is not good, the methods could be moved to some 'extensionInformationUtility', or a repository?
36 *
37 * @author Susanne Moog <typo3@susannemoog.de>
38 * @package Extension Manager
39 * @subpackage Utility
40 */
41 class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
42
43 /**
44 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
45 */
46 public $objectManager;
47
48 /**
49 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
50 * @return void
51 */
52 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
53 $this->objectManager = $objectManager;
54 }
55
56 /**
57 * @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility
58 */
59 public $emConfUtility;
60
61 /**
62 * Inject emConfUtility
63 *
64 * @param \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility
65 * @return void
66 */
67 public function injectEmConfUtility(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility) {
68 $this->emConfUtility = $emConfUtility;
69 }
70
71 /**
72 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
73 */
74 public $extensionRepository;
75
76 /**
77 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
78 */
79 protected $installUtility;
80
81 /**
82 * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
83 * @return void
84 */
85 public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
86 $this->installUtility = $installUtility;
87 }
88
89 /**
90 * Inject emConfUtility
91 *
92 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
93 * @return void
94 */
95 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
96 $this->extensionRepository = $extensionRepository;
97 }
98
99 /**
100 * Returns the list of available, but not necessarily loaded extensions
101 *
102 * @return array Array with two sub-arrays, list array (all extensions with info) and category index
103 * @see getInstExtList()
104 */
105 public function getAvailableExtensions() {
106 $extensions = array();
107 $paths = \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnInstallPaths();
108 foreach ($paths as $installationType => $path) {
109 try {
110 if (is_dir($path)) {
111 $extList = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($path);
112 if (is_array($extList)) {
113 foreach ($extList as $extKey) {
114 $extensions[$extKey] = array(
115 'siteRelPath' => str_replace(PATH_site, '', $path . $extKey),
116 'type' => $installationType,
117 'key' => $extKey,
118 'ext_icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($path . $extKey . '/')
119 );
120 }
121 }
122 }
123 } catch (\Exception $e) {
124 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), 'extensionmanager');
125 }
126 }
127 return $extensions;
128 }
129
130 /**
131 * Enrich the output of getAvailableExtensions() with an array key installed = 1 if an extension is loaded.
132 *
133 * @param array $availableExtensions
134 * @return array
135 */
136 public function getAvailableAndInstalledExtensions(array $availableExtensions) {
137 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $properties) {
138 if (array_key_exists($extKey, $availableExtensions)) {
139 $availableExtensions[$extKey]['installed'] = TRUE;
140 }
141 }
142 return $availableExtensions;
143 }
144
145 /**
146 * Adds the information from the emconf array to the extension information
147 *
148 * @param array $extensions
149 * @return array
150 */
151 public function enrichExtensionsWithEmConfAndTerInformation(array $extensions) {
152 foreach ($extensions as $extensionKey => $properties) {
153 $emconf = $this->emConfUtility->includeEmConf($properties);
154 if ($emconf) {
155 $extensions[$extensionKey] = array_merge($emconf, $properties);
156 $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $extensions[$extensionKey]['version']);
157 if ($terObject instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
158 $extensions[$extensionKey]['terObject'] = $terObject;
159 $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject);
160 }
161 } else {
162 unset($extensions[$extensionKey]);
163 }
164 }
165 return $extensions;
166 }
167
168 /**
169 * Gets all available and installed extension with additional information
170 * from em_conf and TER (if available)
171 *
172 * @return array
173 */
174 public function getAvailableAndInstalledExtensionsWithAdditionalInformation() {
175 $availableExtensions = $this->getAvailableExtensions();
176 $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
177 return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
178 }
179
180 }
181
182
183 ?>