72b5f35ee95ada4a81bd4aab83dc0746a460c832
[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 * @author Susanne Moog <typo3@susannemoog.de>
33 * @package Extension Manager
34 * @subpackage Utility
35 */
36 class ListUtility implements \TYPO3\CMS\Core\SingletonInterface {
37
38 /**
39 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
40 */
41 public $objectManager;
42
43 /**
44 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
45 * @return void
46 */
47 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
48 $this->objectManager = $objectManager;
49 }
50
51 /**
52 * @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility
53 */
54 public $emConfUtility;
55
56 /**
57 * Inject emConfUtility
58 *
59 * @param \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility
60 * @return void
61 */
62 public function injectEmConfUtility(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility) {
63 $this->emConfUtility = $emConfUtility;
64 }
65
66 /**
67 * @var \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
68 */
69 public $extensionRepository;
70
71 /**
72 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
73 */
74 protected $installUtility;
75
76 /**
77 * @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
78 * @return void
79 */
80 public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility) {
81 $this->installUtility = $installUtility;
82 }
83
84 /**
85 * Inject emConfUtility
86 *
87 * @param \TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository
88 * @return void
89 */
90 public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository) {
91 $this->extensionRepository = $extensionRepository;
92 }
93
94 /**
95 * Returns the list of available (installed) extensions
96 *
97 * @return array Array with two sub-arrays, list array (all extensions with info) and category index
98 * @see getInstExtList()
99 */
100 public function getAvailableExtensions() {
101 $extensions = array();
102 $paths = \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnInstallPaths();
103 foreach ($paths as $installationType => $path) {
104 try {
105 if (is_dir($path)) {
106 $extList = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($path);
107 if (is_array($extList)) {
108 foreach ($extList as $extKey) {
109 $extensions[$extKey] = array(
110 'siteRelPath' => str_replace(PATH_site, '', $path . $extKey),
111 'type' => $installationType,
112 'key' => $extKey,
113 'ext_icon' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($path . $extKey . '/')
114 );
115 }
116 }
117 }
118 } catch (\Exception $e) {
119 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($e->getMessage(), 'extensionmanager');
120 }
121 }
122 return $extensions;
123 }
124
125 /**
126 * Reduce the available extensions list to only loaded extensions
127 *
128 * @param array $availableExtensions
129 * @return array
130 */
131 public function getAvailableAndInstalledExtensions(array $availableExtensions) {
132 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $properties) {
133 if (array_key_exists($extKey, $availableExtensions)) {
134 $availableExtensions[$extKey]['installed'] = TRUE;
135 }
136 }
137 return $availableExtensions;
138 }
139
140 /**
141 * Adds the information from the emconf array to the extension information
142 *
143 * @param array $extensions
144 * @return array
145 */
146 public function enrichExtensionsWithEmConfAndTerInformation(array $extensions) {
147 foreach ($extensions as $extensionKey => $properties) {
148 $emconf = $this->emConfUtility->includeEmConf($properties);
149 if ($emconf) {
150 $extensions[$extensionKey] = array_merge($emconf, $properties);
151 $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $extensions[$extensionKey]['version']);
152 if ($terObject instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
153 $extensions[$extensionKey]['terObject'] = $terObject;
154 $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject);
155 }
156 } else {
157 unset($extensions[$extensionKey]);
158 }
159 }
160 return $extensions;
161 }
162
163 /**
164 * Gets all available and installed extension with additional information
165 * from em_conf and TER (if available)
166 *
167 * @return array
168 */
169 public function getAvailableAndInstalledExtensionsWithAdditionalInformation() {
170 $availableExtensions = $this->getAvailableExtensions();
171 $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
172 return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
173 }
174
175 }
176
177
178 ?>