‪TYPO3CMS  ‪main
ExtensionStatus.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
30 
36 {
37  protected string ‪$ok = '';
38  protected string ‪$error = '';
39 
41 
42  public function ‪__construct(
43  protected readonly ‪RemoteRegistry $remoteRegistry,
44  protected readonly ‪ListUtility $listUtility,
45  protected readonly ‪LanguageServiceFactory $languageServiceFactory,
46  ) {
47  $this->languageService = $this->languageServiceFactory->createFromUserPreferences(‪$GLOBALS['BE_USER'] ?? null);
48  }
49 
55  public function ‪getStatus(): array
56  {
57  ‪$status = [];
58 
60  ‪$status['mainRepositoryStatus'] = $this->‪getMainRepositoryStatus();
61  }
62 
64  ‪$status['extensionsSecurityStatusInstalled'] = ‪$extensionStatus->loaded ?? [];
65  ‪$status['extensionsSecurityStatusNotInstalled'] = ‪$extensionStatus->existing ?? [];
66  ‪$status['extensionsOutdatedStatusInstalled'] = ‪$extensionStatus->loadedoutdated ?? [];
67  ‪$status['extensionsOutdatedStatusNotInstalled'] = ‪$extensionStatus->existingoutdated ?? [];
68 
69  return ‪$status;
70  }
71 
72  public function ‪getLabel(): string
73  {
74  return 'Extension Manager';
75  }
76 
82  protected function ‪getMainRepositoryStatus()
83  {
84  if (!$this->remoteRegistry->hasDefaultRemote()) {
85  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.value');
86  $message = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notFound.message');
87  $severity = ContextualFeedbackSeverity::ERROR;
88  } elseif ($this->remoteRegistry->getDefaultRemote()->needsUpdate()) {
89  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.value');
90  $message = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.notUpToDate.message');
91  $severity = ContextualFeedbackSeverity::NOTICE;
92  } else {
93  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.upToDate.value');
94  $message = '';
95  $severity = ContextualFeedbackSeverity::OK;
96  }
97 
98  ‪$status = GeneralUtility::makeInstance(
99  Status::class,
100  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.mainRepository.title'),
101  $value,
102  $message,
103  $severity
104  );
105 
106  return ‪$status;
107  }
108 
114  protected function ‪getSecurityStatusOfExtensions()
115  {
116  $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
117  $loadedInsecure = [];
118  $existingInsecure = [];
119  $loadedOutdated = [];
120  $existingOutdated = [];
121  foreach ($extensionInformation as $extensionKey => $information) {
122  if (
123  array_key_exists('terObject', $information)
124  && $information['terObject'] instanceof ‪Extension
125  ) {
126  $terObject = $information['terObject'];
127  $insecureStatus = $terObject->getReviewState();
128  if ($insecureStatus === -1) {
129  if (
130  array_key_exists('installed', $information)
131  && $information['installed'] === true
132  ) {
133  $loadedInsecure[] = [
134  'extensionKey' => $extensionKey,
135  'version' => $terObject->getVersion(),
136  ];
137  } else {
138  $existingInsecure[] = [
139  'extensionKey' => $extensionKey,
140  'version' => $terObject->getVersion(),
141  ];
142  }
143  } elseif ($insecureStatus === -2) {
144  if (
145  array_key_exists('installed', $information)
146  && $information['installed'] === true
147  ) {
148  $loadedOutdated[] = [
149  'extensionKey' => $extensionKey,
150  'version' => $terObject->getVersion(),
151  ];
152  } else {
153  $existingOutdated[] = [
154  'extensionKey' => $extensionKey,
155  'version' => $terObject->getVersion(),
156  ];
157  }
158  }
159  }
160  }
161 
162  $result = new \stdClass();
163 
164  if (empty($loadedInsecure)) {
165  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.noInsecureExtensionLoaded.value');
166  $message = '';
167  $severity = ContextualFeedbackSeverity::OK;
168  } else {
169  $value = sprintf(
170  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.value'),
171  count($loadedInsecure)
172  );
173  $extensionList = [];
174  foreach ($loadedInsecure as $insecureExtension) {
175  $extensionList[] = sprintf(
176  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
177  $insecureExtension['extensionKey'],
178  $insecureExtension['version']
179  );
180  }
181  $message = sprintf(
182  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.insecureExtensionLoaded.message'),
183  implode('', $extensionList)
184  );
185  $severity = ContextualFeedbackSeverity::ERROR;
186  }
187  $result->loaded = GeneralUtility::makeInstance(
188  Status::class,
189  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedExtensions.title'),
190  $value,
191  $message,
192  $severity
193  );
194 
195  if (empty($existingInsecure)) {
196  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.noInsecureExtensionExists.value');
197  $message = '';
198  $severity = ContextualFeedbackSeverity::OK;
199  } else {
200  $value = sprintf(
201  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.value'),
202  count($existingInsecure)
203  );
204  $extensionList = [];
205  foreach ($existingInsecure as $insecureExtension) {
206  $extensionList[] = sprintf(
207  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message.extension'),
208  $insecureExtension['extensionKey'],
209  $insecureExtension['version']
210  );
211  }
212  $message = sprintf(
213  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.insecureExtensionExists.message'),
214  implode('', $extensionList)
215  );
216  $severity = ContextualFeedbackSeverity::WARNING;
217  }
218  $result->existing = GeneralUtility::makeInstance(
219  Status::class,
220  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingExtensions.title'),
221  $value,
222  $message,
223  $severity
224  );
225 
226  if (empty($loadedOutdated)) {
227  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.noOutdatedExtensionLoaded.value');
228  $message = '';
229  $severity = ContextualFeedbackSeverity::OK;
230  } else {
231  $value = sprintf(
232  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.value'),
233  count($loadedOutdated)
234  );
235  $extensionList = [];
236  foreach ($loadedOutdated as $outdatedExtension) {
237  $extensionList[] = sprintf(
238  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message.extension'),
239  $outdatedExtension['extensionKey'],
240  $outdatedExtension['version']
241  );
242  }
243  $message = sprintf(
244  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message'),
245  implode('', $extensionList)
246  );
247  $severity = ContextualFeedbackSeverity::WARNING;
248  }
249  $result->loadedoutdated = GeneralUtility::makeInstance(
250  Status::class,
251  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.loadedOutdatedExtensions.title'),
252  $value,
253  $message,
254  $severity
255  );
256 
257  if (empty($existingOutdated)) {
258  $value = $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.noOutdatedExtensionExists.value');
259  $message = '';
260  $severity = ContextualFeedbackSeverity::OK;
261  } else {
262  $value = sprintf(
263  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.value'),
264  count($existingOutdated)
265  );
266  $extensionList = [];
267  foreach ($existingOutdated as $outdatedExtension) {
268  $extensionList[] = sprintf(
269  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.message.extension'),
270  $outdatedExtension['extensionKey'],
271  $outdatedExtension['version']
272  );
273  }
274  $message = sprintf(
275  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.outdatedExtensionExists.message'),
276  implode('', $extensionList)
277  );
278  $severity = ContextualFeedbackSeverity::WARNING;
279  }
280  $result->existingoutdated = GeneralUtility::makeInstance(
281  Status::class,
282  $this->languageService->sL('LLL:EXT:extensionmanager/Resources/Private/Language/locallang.xlf:report.status.existingOutdatedExtensions.title'),
283  $value,
284  $message,
285  $severity
286  );
287 
288  return $result;
289  }
290 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:22
‪TYPO3\CMS\Extensionmanager\Report
Definition: ExtensionComposerStatus.php:18
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$extensionStatus
‪$extensionStatus
Definition: ExtensionStatus.php:63
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$status
‪$status['extensionsSecurityStatusInstalled']
Definition: ExtensionStatus.php:64
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:30
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$status
‪return $status
Definition: ExtensionStatus.php:69
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\__construct
‪__construct(protected readonly RemoteRegistry $remoteRegistry, protected readonly ListUtility $listUtility, protected readonly LanguageServiceFactory $languageServiceFactory,)
Definition: ExtensionStatus.php:42
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$languageService
‪LanguageService $languageService
Definition: ExtensionStatus.php:40
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$ok
‪string $ok
Definition: ExtensionStatus.php:37
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Reports\StatusProviderInterface\getStatus
‪Status[] getStatus()
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$error
‪string $error
Definition: ExtensionStatus.php:38
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getMainRepositoryStatus
‪array< string, getStatus():array { $status=[];if(!Environment::isComposerMode()) { $status[ 'mainRepositoryStatus']=$this-> getMainRepositoryStatus()
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getSecurityStatusOfExtensions
‪stdClass getSecurityStatusOfExtensions()
Definition: ExtensionStatus.php:114
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getLabel
‪getLabel()
Definition: ExtensionStatus.php:72
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getMainRepositoryStatus
‪Status getMainRepositoryStatus()
Definition: ExtensionStatus.php:82
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus
Definition: ExtensionStatus.php:36