‪TYPO3CMS  10.4
ExtensionStatus.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 
26 
32 {
36  protected ‪$ok = '';
37 
41  protected ‪$upToDate = '';
42 
46  protected ‪$error = '';
47 
51  protected ‪$objectManager;
52 
56  protected ‪$repositoryRepository;
57 
61  protected ‪$listUtility;
62 
66  protected ‪$languageService;
67 
71  public function ‪__construct()
72  {
73  $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
74  $this->repositoryRepository = $this->objectManager->get(RepositoryRepository::class);
75  $this->listUtility = $this->objectManager->get(ListUtility::class);
76  $this->languageService = $this->objectManager->get(LanguageService::class);
77  $this->languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
78  }
79 
85  public function ‪getStatus()
86  {
87  $status = [];
88  $status['mainRepositoryStatus'] = $this->‪getMainRepositoryStatus();
89 
90  $extensionStatus = $this->‪getSecurityStatusOfExtensions();
91  $status['extensionsSecurityStatusInstalled'] = $extensionStatus->loaded ?? [];
92  $status['extensionsSecurityStatusNotInstalled'] = $extensionStatus->existing ?? [];
93  $status['extensionsOutdatedStatusInstalled'] = $extensionStatus->loadedoutdated ?? [];
94  $status['extensionsOutdatedStatusNotInstalled'] = $extensionStatus->existingoutdated ?? [];
95 
96  return $status;
97  }
98 
104  protected function ‪getMainRepositoryStatus()
105  {
107  $mainRepository = $this->repositoryRepository->findOneTypo3OrgRepository();
108 
109  if ($mainRepository === null) {
110  $value = $this->languageService->getLL('report.status.mainRepository.notFound.value');
111  $message = $this->languageService->getLL('report.status.mainRepository.notFound.message');
112  $severity = ‪Status::ERROR;
113  } elseif ($mainRepository->getLastUpdate()->getTimestamp() < ‪$GLOBALS['EXEC_TIME'] - 24 * 60 * 60 * 7) {
114  $value = $this->languageService->getLL('report.status.mainRepository.notUpToDate.value');
115  $message = $this->languageService->getLL('report.status.mainRepository.notUpToDate.message');
116  $severity = ‪Status::NOTICE;
117  } else {
118  $value = $this->languageService->getLL('report.status.mainRepository.upToDate.value');
119  $message = '';
120  $severity = ‪Status::OK;
121  }
122 
124  $status = $this->objectManager->get(
125  Status::class,
126  $this->languageService->getLL('report.status.mainRepository.title'),
127  $value,
128  $message,
129  $severity
130  );
131 
132  return $status;
133  }
134 
140  protected function ‪getSecurityStatusOfExtensions()
141  {
142  $extensionInformation = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
143  $loadedInsecure = [];
144  $existingInsecure = [];
145  $loadedOutdated = [];
146  $existingOutdated = [];
147  foreach ($extensionInformation as $extensionKey => $information) {
148  if (
149  array_key_exists('terObject', $information)
150  && $information['terObject'] instanceof ‪Extension
151  ) {
153  $terObject = $information['terObject'];
154  $insecureStatus = $terObject->getReviewState();
155  if ($insecureStatus === -1) {
156  if (
157  array_key_exists('installed', $information)
158  && $information['installed'] === true
159  ) {
160  $loadedInsecure[] = [
161  'extensionKey' => $extensionKey,
162  'version' => $terObject->getVersion(),
163  ];
164  } else {
165  $existingInsecure[] = [
166  'extensionKey' => $extensionKey,
167  'version' => $terObject->getVersion(),
168  ];
169  }
170  } elseif ($insecureStatus === -2) {
171  if (
172  array_key_exists('installed', $information)
173  && $information['installed'] === true
174  ) {
175  $loadedOutdated[] = [
176  'extensionKey' => $extensionKey,
177  'version' => $terObject->getVersion(),
178  ];
179  } else {
180  $existingOutdated[] = [
181  'extensionKey' => $extensionKey,
182  'version' => $terObject->getVersion(),
183  ];
184  }
185  }
186  }
187  }
188 
189  $result = new \stdClass();
190 
191  if (empty($loadedInsecure)) {
192  $value = $this->languageService->getLL('report.status.loadedExtensions.noInsecureExtensionLoaded.value');
193  $message = '';
194  $severity = ‪Status::OK;
195  } else {
196  $value = sprintf(
197  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.value'),
198  count($loadedInsecure)
199  );
200  $extensionList = [];
201  foreach ($loadedInsecure as $insecureExtension) {
202  $extensionList[] = sprintf(
203  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message.extension'),
204  $insecureExtension['extensionKey'],
205  $insecureExtension['version']
206  );
207  }
208  $message = sprintf(
209  $this->languageService->getLL('report.status.loadedExtensions.insecureExtensionLoaded.message'),
210  implode('', $extensionList)
211  );
212  $severity = ‪Status::ERROR;
213  }
214  $result->loaded = $this->objectManager->get(
215  Status::class,
216  $this->languageService->getLL('report.status.loadedExtensions.title'),
217  $value,
218  $message,
219  $severity
220  );
221 
222  if (empty($existingInsecure)) {
223  $value = $this->languageService->getLL('report.status.existingExtensions.noInsecureExtensionExists.value');
224  $message = '';
225  $severity = ‪Status::OK;
226  } else {
227  $value = sprintf(
228  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.value'),
229  count($existingInsecure)
230  );
231  $extensionList = [];
232  foreach ($existingInsecure as $insecureExtension) {
233  $extensionList[] = sprintf(
234  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message.extension'),
235  $insecureExtension['extensionKey'],
236  $insecureExtension['version']
237  );
238  }
239  $message = sprintf(
240  $this->languageService->getLL('report.status.existingExtensions.insecureExtensionExists.message'),
241  implode('', $extensionList)
242  );
243  $severity = ‪Status::WARNING;
244  }
245  $result->existing = $this->objectManager->get(
246  Status::class,
247  $this->languageService->getLL('report.status.existingExtensions.title'),
248  $value,
249  $message,
250  $severity
251  );
252 
253  if (empty($loadedOutdated)) {
254  $value = $this->languageService->getLL('report.status.loadedOutdatedExtensions.noOutdatedExtensionLoaded.value');
255  $message = '';
256  $severity = ‪Status::OK;
257  } else {
258  $value = sprintf(
259  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.value'),
260  count($loadedOutdated)
261  );
262  $extensionList = [];
263  foreach ($loadedOutdated as $outdatedExtension) {
264  $extensionList[] = sprintf(
265  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message.extension'),
266  $outdatedExtension['extensionKey'],
267  $outdatedExtension['version']
268  );
269  }
270  $message = sprintf(
271  $this->languageService->getLL('report.status.loadedOutdatedExtensions.outdatedExtensionLoaded.message'),
272  implode('', $extensionList)
273  );
274  $severity = ‪Status::WARNING;
275  }
276  $result->loadedoutdated = $this->objectManager->get(
277  Status::class,
278  $this->languageService->getLL('report.status.loadedOutdatedExtensions.title'),
279  $value,
280  $message,
281  $severity
282  );
283 
284  if (empty($existingOutdated)) {
285  $value = $this->languageService->getLL('report.status.existingOutdatedExtensions.noOutdatedExtensionExists.value');
286  $message = '';
287  $severity = ‪Status::OK;
288  } else {
289  $value = sprintf(
290  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.value'),
291  count($existingOutdated)
292  );
293  $extensionList = [];
294  foreach ($existingOutdated as $outdatedExtension) {
295  $extensionList[] = sprintf(
296  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message.extension'),
297  $outdatedExtension['extensionKey'],
298  $outdatedExtension['version']
299  );
300  }
301  $message = sprintf(
302  $this->languageService->getLL('report.status.existingOutdatedExtensions.outdatedExtensionExists.message'),
303  implode('', $extensionList)
304  );
305  $severity = ‪Status::WARNING;
306  }
307  $result->existingoutdated = $this->objectManager->get(
308  Status::class,
309  $this->languageService->getLL('report.status.existingOutdatedExtensions.title'),
310  $value,
311  $message,
312  $severity
313  );
314 
315  return $result;
316  }
317 }
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:22
‪TYPO3\CMS\Extensionmanager\Report
Definition: ExtensionComposerStatus.php:18
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$repositoryRepository
‪RepositoryRepository $repositoryRepository
Definition: ExtensionStatus.php:51
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Reports\Status\NOTICE
‪const NOTICE
Definition: Status.php:25
‪TYPO3\CMS\Reports\Status\ERROR
‪const ERROR
Definition: Status.php:29
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$languageService
‪LanguageService $languageService
Definition: ExtensionStatus.php:59
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$ok
‪string $ok
Definition: ExtensionStatus.php:35
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\__construct
‪__construct()
Definition: ExtensionStatus.php:64
‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
Definition: RepositoryRepository.php:26
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Reports\Status\OK
‪const OK
Definition: Status.php:27
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$listUtility
‪ListUtility $listUtility
Definition: ExtensionStatus.php:55
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$error
‪string $error
Definition: ExtensionStatus.php:43
‪TYPO3\CMS\Reports\Status\WARNING
‪const WARNING
Definition: Status.php:28
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getSecurityStatusOfExtensions
‪stdClass getSecurityStatusOfExtensions()
Definition: ExtensionStatus.php:133
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$objectManager
‪ObjectManager $objectManager
Definition: ExtensionStatus.php:47
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getMainRepositoryStatus
‪Status getMainRepositoryStatus()
Definition: ExtensionStatus.php:97
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\$upToDate
‪string $upToDate
Definition: ExtensionStatus.php:39
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus\getStatus
‪array getStatus()
Definition: ExtensionStatus.php:78
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus
Definition: ExtensionStatus.php:32