TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
extensionmanager/Classes/Utility/ListUtility.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
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 
22 
32 {
36  protected $emConfUtility;
37 
42 
46  protected $installUtility;
47 
51  protected $packageManager;
52 
57 
61  protected $availableExtensions = null;
62 
66  public function injectEmConfUtility(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility)
67  {
68  $this->emConfUtility = $emConfUtility;
69  }
70 
74  public function injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
75  {
76  $this->extensionRepository = $extensionRepository;
77  }
78 
82  public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
83  {
84  $this->installUtility = $installUtility;
85  }
86 
90  public function injectPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
91  {
92  $this->packageManager = $packageManager;
93  }
94 
98  public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
99  {
100  $this->signalSlotDispatcher = $signalSlotDispatcher;
101  }
102 
108  public function getAvailableExtensions()
109  {
110  if ($this->availableExtensions === null) {
111  $this->availableExtensions = [];
113  foreach ($this->packageManager->getAvailablePackages() as $package) {
114  $installationType = $this->getInstallTypeForPackage($package);
115  $this->availableExtensions[$package->getPackageKey()] = [
116  'siteRelPath' => str_replace(PATH_site, '', $package->getPackagePath()),
117  'type' => $installationType,
118  'key' => $package->getPackageKey(),
119  'ext_icon' => ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
120  ];
121  }
122  }
123 
125  }
126 
130  public function reloadAvailableExtensions()
131  {
132  $this->availableExtensions = null;
133  $this->packageManager->scanAvailablePackages();
134  $this->getAvailableExtensions();
135  }
136 
142  public function getExtension($extensionKey)
143  {
144  return $this->packageManager->getPackage($extensionKey);
145  }
146 
150  protected function emitPackagesMayHaveChangedSignal()
151  {
152  $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
153  }
154 
161  protected function getInstallTypeForPackage(PackageInterface $package)
162  {
163  foreach (Extension::returnInstallPaths() as $installType => $installPath) {
164  if (GeneralUtility::isFirstPartOfStr($package->getPackagePath(), $installPath)) {
165  return $installType;
166  }
167  }
168  return '';
169  }
170 
178  {
179  foreach ($this->packageManager->getActivePackages() as $extKey => $_) {
180  if (isset($availableExtensions[$extKey])) {
181  $availableExtensions[$extKey]['installed'] = true;
182  }
183  }
184  return $availableExtensions;
185  }
186 
193  public function enrichExtensionsWithEmConfInformation(array $extensions)
194  {
195  foreach ($extensions as $extensionKey => $properties) {
196  $emconf = $this->emConfUtility->includeEmConf($properties);
197  if ($emconf) {
198  $extensions[$extensionKey] = array_merge($emconf, $properties);
199  } else {
200  unset($extensions[$extensionKey]);
201  }
202  }
203  return $extensions;
204  }
205 
212  public function enrichExtensionsWithEmConfAndTerInformation(array $extensions)
213  {
214  $extensions = $this->enrichExtensionsWithEmConfInformation($extensions);
215  foreach ($extensions as $extensionKey => $properties) {
216  $terObject = $this->getExtensionTerData($extensionKey, $extensions[$extensionKey]['version']);
217  if ($terObject !== null) {
218  $extensions[$extensionKey]['terObject'] = $terObject;
219  $extensions[$extensionKey]['updateAvailable'] = false;
220  $extensions[$extensionKey]['updateToVersion'] = null;
221  $extensionToUpdate = $this->installUtility->getUpdateableVersion($terObject);
222  if ($extensionToUpdate !== false) {
223  $extensions[$extensionKey]['updateAvailable'] = true;
224  $extensions[$extensionKey]['updateToVersion'] = $extensionToUpdate;
225  }
226  }
227  }
228  return $extensions;
229  }
230 
240  protected function getExtensionTerData($extensionKey, $version)
241  {
242  $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
243  if (!$terObject instanceof Extension) {
244  // Version unknown in TER data, try to find extension
245  $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
246  if ($terObject instanceof Extension) {
247  // Found in TER now, set version information to the known ones, so we can look if there is a newer one
248  // Use a cloned object, otherwise wrong information is stored in persistenceManager
249  $terObject = clone $terObject;
250  $terObject->setVersion($version);
251  $terObject->setIntegerVersion(
253  );
254  } else {
255  $terObject = null;
256  }
257  }
258 
259  return $terObject;
260  }
261 
268  public function enrichExtensionsWithIconInformation(array $extensions)
269  {
270  foreach ($extensions as &$properties) {
271  $iInfo = @getimagesize(PATH_site . $properties['siteRelPath'] . $properties['ext_icon']);
272  if ($iInfo !== false) {
273  $properties['ext_icon_width'] = $iInfo[0];
274  $properties['ext_icon_height'] = $iInfo[1];
275  } else {
276  $properties['ext_icon_width'] = 0;
277  $properties['ext_icon_height'] = 0;
278  }
279  }
280  unset($properties);
281  return $extensions;
282  }
283 
291  {
293  $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
294  $availableAndInstalledExtensions = $this->enrichExtensionsWithIconInformation($availableAndInstalledExtensions);
295  return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
296  }
297 }
static isFirstPartOfStr($str, $partStr)
injectPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
injectEmConfUtility(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility)
injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
static getExtensionIcon($extensionPath, $returnFullPath=false)