‪TYPO3CMS  ‪main
Status.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\Http\Message\ServerRequestInterface;
29 
34 {
38  public function ‪__construct(
39  protected readonly ‪BackendViewFactory $backendViewFactory,
40  protected readonly ‪StatusRegistry $statusRegistry
41  ) {
42  // This needs to be kept during v12 as backwards-compatibility for people still using getLL() in their status reports
43  $this->‪getLanguageService()->includeLLFile('EXT:reports/Resources/Private/Language/locallang_reports.xlf');
44  }
45 
52  public function ‪getReport(ServerRequestInterface $request = null): string
53  {
54  $status = $this->‪getSystemStatus($request);
55  $registry = GeneralUtility::makeInstance(Registry::class);
56  $registry->set('tx_reports', 'status.highestSeverity', $this->‪getHighestSeverity($status));
57  return $this->‪renderStatus($request, $status);
58  }
59 
60  public function ‪getIdentifier(): string
61  {
62  return 'status';
63  }
64 
65  public function ‪getTitle(): string
66  {
67  return 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_title';
68  }
69 
70  public function ‪getDescription(): string
71  {
72  return 'LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_report_description';
73  }
74 
75  public function ‪getIconIdentifier(): string
76  {
77  return 'module-reports';
78  }
79 
86  public function ‪getSystemStatus(ServerRequestInterface $request = null): array
87  {
88  $status = [];
89  foreach ($this->statusRegistry->getProviders() as $statusProvider) {
90  $statusProviderId = $statusProvider->getLabel();
91  $status[$statusProviderId] ??= [];
92  if ($statusProvider instanceof ‪RequestAwareStatusProviderInterface) {
93  $statuses = $statusProvider->getStatus($request);
94  } else {
95  $statuses = $statusProvider->getStatus();
96  }
97  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
98  }
99  return $status;
100  }
101 
107  public function ‪getDetailedSystemStatus(): array
108  {
109  $status = [];
110  foreach ($this->statusRegistry->getProviders() as $statusProvider) {
111  $statusProviderId = $statusProvider->getLabel();
112  if ($statusProvider instanceof ‪ExtendedStatusProviderInterface) {
113  $statuses = $statusProvider->getDetailedStatus();
114  $status[$statusProviderId] = array_merge($status[$statusProviderId] ?? [], $statuses);
115  }
116  }
117  return $status;
118  }
119 
126  public function ‪getHighestSeverity(array $statusCollection): int
127  {
128  $highestSeverity = ContextualFeedbackSeverity::NOTICE;
129  foreach ($statusCollection as $providerStatuses) {
131  foreach ($providerStatuses as $status) {
132  if ($status->getSeverity()->value > $highestSeverity->value) {
133  $highestSeverity = $status->getSeverity();
134  }
135  // Reached the highest severity level, no need to go on
136  if ($highestSeverity === ContextualFeedbackSeverity::ERROR) {
137  break;
138  }
139  }
140  }
141  return $highestSeverity->value;
142  }
143 
151  protected function ‪renderStatus(ServerRequestInterface $request, array $statusCollection): string
152  {
153  // Apply sorting to collection and the providers
154  $statusCollection = $this->‪sortStatusProviders($statusCollection);
155 
156  foreach ($statusCollection as &$statuses) {
157  $statuses = $this->‪sortStatuses($statuses);
158  }
159  unset($statuses);
160 
161  $view = $this->backendViewFactory->create($request);
162  return $view->assignMultiple([
163  'statusCollection' => $statusCollection,
164  'severityIconMapping' => [
165  ContextualFeedbackSeverity::NOTICE->value => 'actions-info',
166  ContextualFeedbackSeverity::INFO->value => 'actions-info',
167  ContextualFeedbackSeverity::OK->value => 'actions-check',
168  ContextualFeedbackSeverity::WARNING->value => 'actions-exclamation',
169  ContextualFeedbackSeverity::ERROR->value => 'actions-exclamation',
170  ],
171  ])->render('StatusReport');
172  }
173 
180  protected function ‪sortStatusProviders(array $statusCollection): array
181  {
182  // Extract the primary status collections, i.e. the status groups
183  // that must appear on top of the status report
184  // Change their keys to localized collection titles
185  $primaryStatuses = [
186  $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_typo3') => $statusCollection['typo3'],
187  $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_system') => $statusCollection['system'],
188  $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_security') => $statusCollection['security'],
189  $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_configuration') => $statusCollection['configuration'],
190  ];
191  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
192  // Assemble list of secondary status collections with left-over collections
193  // Change their keys using localized labels if available
194  $secondaryStatuses = [];
195  foreach ($statusCollection as $statusProviderId => $collection) {
196  if (str_starts_with($statusProviderId, 'LLL:')) {
197  // Label provided by extension
198  $label = $this->‪getLanguageService()->sL($statusProviderId);
199  } else {
200  // Generic label
201  // @todo phase this out
202  $label = $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_' . $statusProviderId);
203  }
204  $providerLabel = empty($label) ? $statusProviderId : $label;
205  $secondaryStatuses[$providerLabel] = $collection;
206  }
207  // Sort the secondary status collections alphabetically
208  ksort($secondaryStatuses);
209  return array_merge($primaryStatuses, $secondaryStatuses);
210  }
211 
218  protected function ‪sortStatuses(array $statusCollection): array
219  {
220  $statuses = [];
221  $sortTitle = [];
222  $header = null;
224  foreach ($statusCollection as $status) {
225  if ($status->getTitle() === 'TYPO3') {
226  $header = $status;
227  continue;
228  }
229  $statuses[] = $status;
230  $sortTitle[] = $status->getSeverity();
231  }
232  array_multisort($sortTitle, SORT_DESC, $statuses);
233  // Making sure that the core version information is always on the top
234  if (is_object($header)) {
235  array_unshift($statuses, $header);
236  }
237  return $statuses;
238  }
239 
241  {
242  return ‪$GLOBALS['LANG'];
243  }
244 }
‪TYPO3\CMS\Reports\Report\Status\Status\getIconIdentifier
‪getIconIdentifier()
Definition: Status.php:75
‪TYPO3\CMS\Reports\Report\Status\Status\getHighestSeverity
‪int getHighestSeverity(array $statusCollection)
Definition: Status.php:126
‪TYPO3\CMS\Reports\Report\Status\Status\getDescription
‪getDescription()
Definition: Status.php:70
‪TYPO3\CMS\Reports\Report\Status\Status\getTitle
‪getTitle()
Definition: Status.php:65
‪TYPO3\CMS\Reports\Report\Status\Status
Definition: Status.php:34
‪TYPO3\CMS\Backend\View\BackendViewFactory
Definition: BackendViewFactory.php:35
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Reports\Report\Status\Status\getLanguageService
‪getLanguageService()
Definition: Status.php:240
‪TYPO3\CMS\Reports\Report\Status\Status\getSystemStatus
‪ReportStatus[][] getSystemStatus(ServerRequestInterface $request=null)
Definition: Status.php:86
‪TYPO3\CMS\Reports\Report\Status\Status\__construct
‪__construct(protected readonly BackendViewFactory $backendViewFactory, protected readonly StatusRegistry $statusRegistry)
Definition: Status.php:38
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Security\ContentSecurityPolicy\Reporting\ReportStatus
‪ReportStatus
Definition: ReportStatus.php:24
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Reports\RequestAwareReportInterface
Definition: RequestAwareReportInterface.php:26
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatuses
‪array sortStatuses(array $statusCollection)
Definition: Status.php:218
‪TYPO3\CMS\Reports\Report\Status\Status\renderStatus
‪string renderStatus(ServerRequestInterface $request, array $statusCollection)
Definition: Status.php:151
‪TYPO3\CMS\Reports\Report\Status\Status\getReport
‪string getReport(ServerRequestInterface $request=null)
Definition: Status.php:52
‪TYPO3\CMS\Reports\Report\Status\Status\getIdentifier
‪getIdentifier()
Definition: Status.php:60
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Reports\Report\Status
Definition: ConfigurationStatus.php:16
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Reports\Registry\StatusRegistry
Definition: StatusRegistry.php:29
‪TYPO3\CMS\Reports\ExtendedStatusProviderInterface
Definition: ExtendedStatusProviderInterface.php:22
‪TYPO3\CMS\Reports\RequestAwareStatusProviderInterface
Definition: RequestAwareStatusProviderInterface.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Reports\Report\Status\Status\getDetailedSystemStatus
‪ReportStatus[][] getDetailedSystemStatus()
Definition: Status.php:107
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatusProviders
‪array sortStatusProviders(array $statusCollection)
Definition: Status.php:180