TYPO3  7.6
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()] = array(
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  $this->availableExtensions = null;
132  $this->packageManager->scanAvailablePackages();
133  $this->getAvailableExtensions();
134  }
135 
141  public function getExtension($extensionKey)
142  {
143  return $this->packageManager->getPackage($extensionKey);
144  }
145 
149  protected function emitPackagesMayHaveChangedSignal()
150  {
151  $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
152  }
153 
160  protected function getInstallTypeForPackage(PackageInterface $package)
161  {
162  foreach (Extension::returnInstallPaths() as $installType => $installPath) {
163  if (GeneralUtility::isFirstPartOfStr($package->getPackagePath(), $installPath)) {
164  return $installType;
165  }
166  }
167  return '';
168  }
169 
177  {
178  foreach ($this->packageManager->getActivePackages() as $extKey => $_) {
179  if (isset($availableExtensions[$extKey])) {
180  $availableExtensions[$extKey]['installed'] = true;
181  }
182  }
183  return $availableExtensions;
184  }
185 
192  public function enrichExtensionsWithEmConfAndTerInformation(array $extensions)
193  {
194  foreach ($extensions as $extensionKey => $properties) {
195  $emconf = $this->emConfUtility->includeEmConf($properties);
196  if ($emconf) {
197  $extensions[$extensionKey] = array_merge($emconf, $properties);
198  $terObject = $this->getExtensionTerData($extensionKey, $extensions[$extensionKey]['version']);
199  if ($terObject !== null) {
200  $extensions[$extensionKey]['terObject'] = $terObject;
201  $extensions[$extensionKey]['updateAvailable'] = false;
202  $extensions[$extensionKey]['updateToVersion'] = null;
203  $extensionToUpdate = $this->installUtility->getUpdateableVersion($terObject);
204  if ($extensionToUpdate !== false) {
205  $extensions[$extensionKey]['updateAvailable'] = true;
206  $extensions[$extensionKey]['updateToVersion'] = $extensionToUpdate;
207  }
208  }
209  } else {
210  unset($extensions[$extensionKey]);
211  }
212  }
213  return $extensions;
214  }
215 
225  protected function getExtensionTerData($extensionKey, $version)
226  {
227  $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
228  if (!$terObject instanceof Extension) {
229  // Version unknown in TER data, try to find extension
230  $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
231  if ($terObject instanceof Extension) {
232  // Found in TER now, set version information to the known ones, so we can look if there is a newer one
233  // Use a cloned object, otherwise wrong information is stored in persistenceManager
234  $terObject = clone $terObject;
235  $terObject->setVersion($version);
236  $terObject->setIntegerVersion(
238  );
239  } else {
240  $terObject = null;
241  }
242  }
243 
244  return $terObject;
245  }
246 
253  public function enrichExtensionsWithIconInformation(array $extensions)
254  {
255  foreach ($extensions as &$properties) {
256  $iInfo = @getimagesize(PATH_site . $properties['siteRelPath'] . $properties['ext_icon']);
257  if ($iInfo !== false) {
258  $properties['ext_icon_width'] = $iInfo[0];
259  $properties['ext_icon_height'] = $iInfo[1];
260  } else {
261  $properties['ext_icon_width'] = 0;
262  $properties['ext_icon_height'] = 0;
263  }
264  }
265  unset($properties);
266  return $extensions;
267  }
268 
276  {
278  $availableAndInstalledExtensions = $this->getAvailableAndInstalledExtensions($availableExtensions);
279  $availableAndInstalledExtensions = $this->enrichExtensionsWithIconInformation($availableAndInstalledExtensions);
280  return $this->enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
281  }
282 }