‪TYPO3CMS  10.4
ListUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\EventDispatcher\EventDispatcherInterface;
22 use TYPO3\CMS\Core\Package\PackageManager;
30 
41 {
45  protected ‪$emConfUtility;
46 
50  protected ‪$extensionRepository;
51 
55  protected ‪$installUtility;
56 
60  protected ‪$packageManager;
61 
65  protected ‪$availableExtensions;
66 
70  protected ‪$eventDispatcher;
71 
72  public function ‪injectEventDispatcher(EventDispatcherInterface ‪$eventDispatcher)
73  {
74  $this->eventDispatcher = ‪$eventDispatcher;
75  }
76 
80  public function ‪injectEmConfUtility(EmConfUtility ‪$emConfUtility)
81  {
82  $this->emConfUtility = ‪$emConfUtility;
83  }
84 
89  {
90  $this->extensionRepository = ‪$extensionRepository;
91  }
92 
97  {
98  $this->installUtility = ‪$installUtility;
99  }
100 
104  public function ‪injectPackageManager(PackageManager ‪$packageManager)
105  {
106  $this->packageManager = ‪$packageManager;
107  }
108 
115  public function ‪getAvailableExtensions(string $filter = ''): array
116  {
117  if ($this->availableExtensions === null) {
118  $this->availableExtensions = [];
119  $this->eventDispatcher->dispatch(new PackagesMayHaveChangedEvent());
120  foreach ($this->packageManager->getAvailablePackages() as $package) {
121  $installationType = $this->‪getInstallTypeForPackage($package);
122  if ($filter === '' || $filter === $installationType) {
123  $this->availableExtensions[$package->getPackageKey()] = [
124  'siteRelPath' => str_replace(‪Environment::getPublicPath() . '/', '', $package->getPackagePath()),
125  'type' => $installationType,
126  'key' => $package->getPackageKey(),
127  'icon' => ‪PathUtility::getAbsoluteWebPath($package->getPackagePath() . ‪ExtensionManagementUtility::getExtensionIcon($package->getPackagePath())),
128  ];
129  }
130  }
131  }
132 
134  }
135 
139  public function ‪reloadAvailableExtensions()
140  {
141  $this->availableExtensions = null;
142  $this->packageManager->scanAvailablePackages();
143  $this->‪getAvailableExtensions();
144  }
145 
151  public function ‪getExtension($extensionKey)
152  {
153  return $this->packageManager->getPackage($extensionKey);
154  }
155 
162  protected function ‪getInstallTypeForPackage(‪PackageInterface $package)
163  {
164  foreach (‪Extension::returnInstallPaths() as $installType => $installPath) {
165  if (GeneralUtility::isFirstPartOfStr($package->‪getPackagePath(), $installPath)) {
166  return $installType;
167  }
168  }
169  return '';
170  }
171 
179  {
180  foreach ($this->packageManager->getActivePackages() as $extKey => $_) {
181  if (isset(‪$availableExtensions[$extKey])) {
182  ‪$availableExtensions[$extKey]['installed'] = true;
183  }
184  }
186  }
187 
194  public function ‪enrichExtensionsWithEmConfInformation(array $extensions)
195  {
196  foreach ($extensions as $extensionKey => $properties) {
197  $emconf = $this->emConfUtility->includeEmConf($extensionKey, $properties);
198  if (is_array($emconf)) {
199  $extensions[$extensionKey] = array_merge($emconf, $properties);
200  } else {
201  unset($extensions[$extensionKey]);
202  }
203  }
204  return $extensions;
205  }
206 
213  public function ‪enrichExtensionsWithEmConfAndTerInformation(array $extensions)
214  {
215  $extensions = $this->‪enrichExtensionsWithEmConfInformation($extensions);
216  foreach ($extensions as $extensionKey => $properties) {
217  $terObject = $this->‪getExtensionTerData($extensionKey, $extensions[$extensionKey]['version'] ?? '');
218  if ($terObject !== null) {
219  $extensions[$extensionKey]['terObject'] = $terObject;
220  $extensions[$extensionKey]['updateAvailable'] = false;
221  $extensions[$extensionKey]['updateToVersion'] = null;
222  $extensionToUpdate = $this->installUtility->getUpdateableVersion($terObject);
223  if ($extensionToUpdate !== false) {
224  $extensions[$extensionKey]['updateAvailable'] = true;
225  $extensions[$extensionKey]['updateToVersion'] = $extensionToUpdate;
226  }
227  }
228  }
229  return $extensions;
230  }
231 
241  protected function ‪getExtensionTerData($extensionKey, $version)
242  {
243  $terObject = $this->extensionRepository->findOneByExtensionKeyAndVersion($extensionKey, $version);
244  if (!$terObject instanceof Extension) {
245  // Version unknown in TER data, try to find extension
246  $terObject = $this->extensionRepository->findHighestAvailableVersion($extensionKey);
247  if ($terObject instanceof Extension) {
248  // Found in TER now, set version information to the known ones, so we can look if there is a newer one
249  // Use a cloned object, otherwise wrong information is stored in persistenceManager
250  $terObject = clone $terObject;
251  $terObject->‪setVersion($version);
252  $terObject->setIntegerVersion(
254  );
255  } else {
256  $terObject = null;
257  }
258  }
259 
260  return $terObject;
261  }
262 
270  public function ‪getAvailableAndInstalledExtensionsWithAdditionalInformation(string $filter = ''): array
271  {
273  $availableAndInstalledExtensions = $this->‪getAvailableAndInstalledExtensions($availableExtensions);
274  return $this->‪enrichExtensionsWithEmConfAndTerInformation($availableAndInstalledExtensions);
275  }
276 }
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\reloadAvailableExtensions
‪reloadAvailableExtensions()
Definition: ListUtility.php:133
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectEmConfUtility
‪injectEmConfUtility(EmConfUtility $emConfUtility)
Definition: ListUtility.php:74
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableExtensions
‪array[] getAvailableExtensions(string $filter='')
Definition: ListUtility.php:109
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$packageManager
‪PackageManager $packageManager
Definition: ListUtility.php:56
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableAndInstalledExtensionsWithAdditionalInformation
‪array getAvailableAndInstalledExtensionsWithAdditionalInformation(string $filter='')
Definition: ListUtility.php:264
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Extensionmanager\Utility
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\setVersion
‪setVersion($version)
Definition: Extension.php:391
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectInstallUtility
‪injectInstallUtility(InstallUtility $installUtility)
Definition: ListUtility.php:90
‪TYPO3\CMS\Core\Package\PackageInterface\getPackagePath
‪string getPackagePath()
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectPackageManager
‪injectPackageManager(PackageManager $packageManager)
Definition: ListUtility.php:98
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\enrichExtensionsWithEmConfInformation
‪array enrichExtensionsWithEmConfInformation(array $extensions)
Definition: ListUtility.php:188
‪TYPO3\CMS\Core\Package\PackageInterface
Definition: PackageInterface.php:22
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:32
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:55
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\enrichExtensionsWithEmConfAndTerInformation
‪array enrichExtensionsWithEmConfAndTerInformation(array $extensions)
Definition: ListUtility.php:207
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getExtensionTerData
‪Extension null getExtensionTerData($extensionKey, $version)
Definition: ListUtility.php:235
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getAvailableAndInstalledExtensions
‪array getAvailableAndInstalledExtensions(array $availableExtensions)
Definition: ListUtility.php:172
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:35
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$emConfUtility
‪EmConfUtility $emConfUtility
Definition: ListUtility.php:44
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$availableExtensions
‪array $availableExtensions
Definition: ListUtility.php:60
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectExtensionRepository
‪injectExtensionRepository(ExtensionRepository $extensionRepository)
Definition: ListUtility.php:82
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: ListUtility.php:64
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Package\Event\PackagesMayHaveChangedEvent
Definition: PackagesMayHaveChangedEvent.php:24
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getExtension
‪TYPO3 CMS Core Package PackageInterface getExtension($extensionKey)
Definition: ListUtility.php:145
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$installUtility
‪InstallUtility $installUtility
Definition: ListUtility.php:52
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\injectEventDispatcher
‪injectEventDispatcher(EventDispatcherInterface $eventDispatcher)
Definition: ListUtility.php:66
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\getInstallTypeForPackage
‪string getInstallTypeForPackage(PackageInterface $package)
Definition: ListUtility.php:156
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\getExtensionIcon
‪static string getExtensionIcon($extensionPath, $returnFullPath=false)
Definition: ExtensionManagementUtility.php:1518
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\returnInstallPaths
‪static array returnInstallPaths()
Definition: Extension.php:442
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility\$extensionRepository
‪ExtensionRepository $extensionRepository
Definition: ListUtility.php:48