c587fa0acbe2a811a5080ba1026a92c35049e164
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / List.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Utility for dealing with extension list related functions
30 *
31 * @author Susanne Moog <typo3@susannemoog.de>
32 * @package Extension Manager
33 * @subpackage Utility
34 */
35 class Tx_Extensionmanager_Utility_List implements t3lib_Singleton {
36
37 /**
38 * @var Tx_Extbase_Object_ObjectManager
39 */
40 public $objectManager;
41
42 /**
43 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
44 * @return void
45 */
46 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
47 $this->objectManager = $objectManager;
48 }
49
50 /**
51 * @var Tx_Extensionmanager_Utility_EmConf
52 */
53 public $emConfUtility;
54
55 /**
56 * Inject emConfUtility
57 *
58 * @param Tx_Extensionmanager_Utility_EmConf $emConfUtility
59 * @return void
60 */
61 public function injectEmConfUtility(Tx_Extensionmanager_Utility_EmConf $emConfUtility) {
62 $this->emConfUtility = $emConfUtility;
63 }
64
65 /**
66 * @var Tx_Extensionmanager_Domain_Repository_ExtensionRepository
67 */
68 public $extensionRepository;
69
70 /**
71 * @var Tx_Extensionmanager_Utility_Install
72 */
73 protected $installUtility;
74
75 /**
76 * @param Tx_Extensionmanager_Utility_Install $installUtility
77 * @return void
78 */
79 public function injectInstallUtility(Tx_Extensionmanager_Utility_Install $installUtility) {
80 $this->installUtility = $installUtility;
81 }
82
83 /**
84 * Inject emConfUtility
85 *
86 * @param Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository
87 * @return void
88 */
89 public function injectExtensionRepository(Tx_Extensionmanager_Domain_Repository_ExtensionRepository $extensionRepository) {
90 $this->extensionRepository = $extensionRepository;
91 }
92 /**
93 * Returns the list of available (installed) extensions
94 *
95 * @return array Array with two sub-arrays, list array (all extensions with info) and category index
96 * @see getInstExtList()
97 */
98 public function getAvailableExtensions() {
99 $extensions = array();
100 $paths = Tx_Extensionmanager_Domain_Model_Extension::returnInstallPaths();
101 foreach ($paths as $installationType => $path) {
102 try {
103 if (is_dir($path)) {
104 $extList = t3lib_div::get_dirs($path);
105 if (is_array($extList)) {
106 foreach ($extList as $extKey) {
107 $extensions[$extKey] = array(
108 'siteRelPath' => str_replace(PATH_site, '', $path . $extKey),
109 'type' => $installationType,
110 'key' => $extKey
111 );
112 }
113 }
114 }
115 } catch (Exception $e) {
116 t3lib_div::sysLog($e->getMessage(), 'extensionmanager');
117 }
118 }
119 return $extensions;
120 }
121
122 /**
123 * Reduce the available extensions list to only installed extensions
124 *
125 * @param array $availableExtensions
126 * @return array
127 */
128 public function getAvailableAndInstalledExtensions(array $availableExtensions) {
129 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $properties) {
130 if (array_key_exists($extKey, $availableExtensions)) {
131 $availableExtensions[$extKey]['installed'] = TRUE;
132 }
133 }
134 return $availableExtensions;
135 }
136
137 /**
138 * Adds the information from the emconf array to the extension information
139 *
140 * @param array $extensions
141 * @return array
142 */
143 public function enrichExtensionsWithEmConfAndTerInformation(array $extensions) {
144 foreach ($extensions as $extensionKey => $properties) {
145 $emconf = $this->emConfUtility->includeEmConf($properties);
146 if ($emconf) {
147 $extensions[$extensionKey] = array_merge($emconf, $properties);
148 $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion(
149 $extensionKey,
150 $extensions[$extensionKey]['version']
151 );
152 if ($terObject instanceof Tx_Extensionmanager_Domain_Model_Extension) {
153 $extensions[$extensionKey]['terObject'] = $terObject;
154 $extensions[$extensionKey]['updateAvailable'] = $this->installUtility->isUpdateAvailable($terObject);
155 }
156
157 } else {
158 unset($extensions[$extensionKey]);
159 }
160 }
161 return $extensions;
162 }
163
164 /**
165 * Gets all available and installed extension with additional information
166 * from em_conf and TER (if available)
167 *
168 * @return array
169 */
170 public function getAvailableAndInstalledExtensionsWithAdditionalInformation() {
171 $availableExtensions = $this->getAvailableExtensions();
172 $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
173 return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
174 }
175 }
176
177 ?>