‪TYPO3CMS  9.5
ListUtility.php
Go to the documentation of this file.
1 <?php
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 
24 
35 {
39  protected ‪$emConfUtility;
40 
44  protected ‪$extensionRepository;
45 
49  protected ‪$installUtility;
50 
54  protected ‪$packageManager;
55 
59  protected ‪$signalSlotDispatcher;
60 
64  protected ‪$availableExtensions;
65 
69  public function ‪injectEmConfUtility(\‪TYPO3\CMS\Extensionmanager\Utility\EmConfUtility ‪$emConfUtility)
70  {
71  $this->emConfUtility = ‪$emConfUtility;
72  }
73 
77  public function ‪injectExtensionRepository(\‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository ‪$extensionRepository)
78  {
79  $this->extensionRepository = ‪$extensionRepository;
80  }
81 
85  public function ‪injectInstallUtility(\‪TYPO3\CMS\Extensionmanager\Utility\‪InstallUtility ‪$installUtility)
86  {
87  $this->installUtility = ‪$installUtility;
88  }
89 
93  public function ‪injectPackageManager(\‪TYPO3\CMS\Core\Package\PackageManager ‪$packageManager)
94  {
95  $this->packageManager = ‪$packageManager;
96  }
97 
101  public function ‪injectSignalSlotDispatcher(\‪TYPO3\CMS\‪Extbase\SignalSlot\Dispatcher ‪$signalSlotDispatcher)
102  {
103  $this->signalSlotDispatcher = ‪$signalSlotDispatcher;
104  }
105 
111  public function ‪getAvailableExtensions()
112  {
113  if ($this->availableExtensions === null) {
114  $this->availableExtensions = [];
116  foreach ($this->packageManager->getAvailablePackages() as $package) {
117  $installationType = $this->‪getInstallTypeForPackage($package);
118  $this->availableExtensions[$package->getPackageKey()] = [
119  'siteRelPath' => str_replace(‪Environment::getPublicPath() . '/', '', $package->getPackagePath()),
120  'type' => $installationType,
121  'key' => $package->getPackageKey(),
122  'ext_icon' => ‪ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
123  ];
124  }
125  }
126 
128  }
129 
133  public function ‪reloadAvailableExtensions()
134  {
135  $this->availableExtensions = null;
136  $this->packageManager->scanAvailablePackages();
137  $this->‪getAvailableExtensions();
138  }
139 
145  public function ‪getExtension($extensionKey)
146  {
147  return $this->packageManager->getPackage($extensionKey);
148  }
149 
153  protected function ‪emitPackagesMayHaveChangedSignal()
154  {
155  $this->signalSlotDispatcher->dispatch('PackageManagement', 'packagesMayHaveChanged');
156  }
157 
164  protected function ‪getInstallTypeForPackage(PackageInterface $package)
165  {
166  foreach (‪Extension::returnInstallPaths() as $installType => $installPath) {
167  if (GeneralUtility::isFirstPartOfStr($package->getPackagePath(), $installPath)) {
168  return $installType;
169  }
170  }
171  return '';
172  }
173 
181  {
182  foreach ($this->packageManager->getActivePackages() as $extKey => $_) {
183  if (isset(‪$availableExtensions[$extKey])) {
184  ‪$availableExtensions[$extKey]['installed'] = true;
185  }
186  }
188  }
189 
196  public function ‪enrichExtensionsWithEmConfInformation(array $extensions)
197  {
198  foreach ($extensions as $extensionKey => $properties) {
199  $emconf = $this->emConfUtility->includeEmConf($properties);
200  if ($emconf) {
201  $extensions[$extensionKey] = array_merge($emconf, $properties);
202  } else {
203  unset($extensions[$extensionKey]);
204  }
205  }
206  return $extensions;
207  }
208 
215  public function ‪enrichExtensionsWithEmConfAndTerInformation(array $extensions)
216  {
217  $extensions = $this->‪enrichExtensionsWithEmConfInformation($extensions);
218  foreach ($extensions as $extensionKey => $properties) {
219  $terObject = $this->‪getExtensionTerData($extensionKey, $extensions[$extensionKey]['version'] ?? '');
220  if ($terObject !== null) {
221  $extensions[$extensionKey]['terObject'] = $terObject;
222  $extensions[$extensionKey]['updateAvailable'] = false;
223  $extensions[$extensionKey]['updateToVersion'] = null;
224  $extensionToUpdate = $this->installUtility->getUpdateableVersion($terObject);
225  if ($extensionToUpdate !== false) {
226  $extensions[$extensionKey]['updateAvailable'] = true;
227  $extensions[$extensionKey]['updateToVersion'] = $extensionToUpdate;
228  }
229  }
230  }
231  return $extensions;
232  }
233 
243  protected function ‪getExtensionTerData($extensionKey, $version)
244  {
245  $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
246  if (!$terObject instanceof Extension) {
247  // Version unknown in TER data, try to find extension
248  $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
249  if ($terObject instanceof Extension) {
250  // Found in TER now, set version information to the known ones, so we can look if there is a newer one
251  // Use a cloned object, otherwise wrong information is stored in persistenceManager
252  $terObject = clone $terObject;
253  $terObject->‪setVersion($version);
254  $terObject->setIntegerVersion(
256  );
257  } else {
258  $terObject = null;
259  }
260  }
261 
262  return $terObject;
263  }
264 
271  public function ‪enrichExtensionsWithIconInformation(array $extensions)
272  {
273  foreach ($extensions as &$properties) {
274  $extIconPath = ‪Environment::getPublicPath() . '/' . $properties['siteRelPath'] . $properties['ext_icon'];
275  if (@is_file($extIconPath)) {
276  $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $extIconPath);
277  $properties['ext_icon_width'] = $imageInfo->getWidth();
278  $properties['ext_icon_height'] = $imageInfo->getHeight();
279  } else {
280  $properties['ext_icon_width'] = 0;
281  $properties['ext_icon_height'] = 0;
282  }
283  }
284  unset($properties);
285  return $extensions;
286  }
287 
295  {
297  $availableAndInstalledExtensions = $this->‪getAvailableAndInstalledExtensions($availableExtensions);
298  $availableAndInstalledExtensions = $this->‪enrichExtensionsWithIconInformation($availableAndInstalledExtensions);
299  return $this->‪enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
300  }
301 }
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\reloadAvailableExtensions
‪reloadAvailableExtensions()
Definition: ListUtility.php:127
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:21
‪TYPO3\CMS\Extensionmanager\Utility
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\setVersion
‪setVersion($version)
Definition: Extension.php:382
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectSignalSlotDispatcher
‪injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
Definition: ListUtility.php:95
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:24
‪TYPO3
‪TYPO3\CMS\Core\Package\PackageInterface\getPackagePath
‪string getPackagePath()
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$extensionRepository
‪TYPO3 CMS Extensionmanager Domain Repository ExtensionRepository $extensionRepository
Definition: ListUtility.php:42
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$signalSlotDispatcher
‪TYPO3 CMS Extbase SignalSlot Dispatcher $signalSlotDispatcher
Definition: ListUtility.php:54
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$emConfUtility
‪TYPO3 CMS Extensionmanager Utility EmConfUtility $emConfUtility
Definition: ListUtility.php:38
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:35
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\enrichExtensionsWithEmConfInformation
‪array enrichExtensionsWithEmConfInformation(array $extensions)
Definition: ListUtility.php:190
‪TYPO3\CMS\Core\Package\PackageInterface
Definition: PackageInterface.php:21
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:28
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:32
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$installUtility
‪TYPO3 CMS Extensionmanager Utility InstallUtility $installUtility
Definition: ListUtility.php:46
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\enrichExtensionsWithIconInformation
‪array enrichExtensionsWithIconInformation(array $extensions)
Definition: ListUtility.php:265
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectEmConfUtility
‪injectEmConfUtility(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility)
Definition: ListUtility.php:63
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\emitPackagesMayHaveChangedSignal
‪emitPackagesMayHaveChangedSignal()
Definition: ListUtility.php:147
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\enrichExtensionsWithEmConfAndTerInformation
‪array enrichExtensionsWithEmConfAndTerInformation(array $extensions)
Definition: ListUtility.php:209
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectExtensionRepository
‪injectExtensionRepository(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository $extensionRepository)
Definition: ListUtility.php:71
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getExtensionTerData
‪Extension null getExtensionTerData($extensionKey, $version)
Definition: ListUtility.php:237
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableAndInstalledExtensions
‪array getAvailableAndInstalledExtensions(array $availableExtensions)
Definition: ListUtility.php:174
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectInstallUtility
‪injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
Definition: ListUtility.php:79
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$availableExtensions
‪array $availableExtensions
Definition: ListUtility.php:58
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableAndInstalledExtensionsWithAdditionalInformation
‪array getAvailableAndInstalledExtensionsWithAdditionalInformation()
Definition: ListUtility.php:288
‪TYPO3\CMS\Core\Type\File\ImageInfo
Definition: ImageInfo.php:25
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableExtensions
‪array[] getAvailableExtensions()
Definition: ListUtility.php:105
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getExtension
‪TYPO3 CMS Core Package PackageInterface getExtension($extensionKey)
Definition: ListUtility.php:139
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getInstallTypeForPackage
‪string getInstallTypeForPackage(PackageInterface $package)
Definition: ListUtility.php:158
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$packageManager
‪TYPO3 CMS Core Package PackageManager $packageManager
Definition: ListUtility.php:50
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getExtensionIcon
‪static string getExtensionIcon($extensionPath, $returnFullPath=false)
Definition: ExtensionManagementUtility.php:1511
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectPackageManager
‪injectPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
Definition: ListUtility.php:87
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\returnInstallPaths
‪static array returnInstallPaths()
Definition: Extension.php:433