‪TYPO3CMS  11.5
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;
26 use ‪TYPO3\CMS\Reports\Status as ReportStatus;
28 
33 {
37  protected ‪$statusProviders = [];
38 
42  public function ‪__construct()
43  {
44  $this->‪getLanguageService()->‪includeLLFile('EXT:reports/Resources/Private/Language/locallang_reports.xlf');
45  $this->‪getStatusProviders();
46  }
47 
54  public function ‪getReport(ServerRequestInterface $request = null)
55  {
56  $status = $this->‪getSystemStatus($request);
57  $registry = GeneralUtility::makeInstance(Registry::class);
58  $registry->set('tx_reports', 'status.highestSeverity', $this->‪getHighestSeverity($status));
59  return $this->‪renderStatus($status);
60  }
61 
65  protected function ‪getStatusProviders()
66  {
67  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
68  $this->statusProviders[$key] = [];
69  foreach ($statusProvidersList as $statusProvider) {
70  $statusProviderInstance = GeneralUtility::makeInstance($statusProvider);
71  if ($statusProviderInstance instanceof ‪StatusProviderInterface) {
72  $this->statusProviders[$key][] = $statusProviderInstance;
73  }
74  }
75  }
76  }
77 
84  public function ‪getSystemStatus(ServerRequestInterface $request = null)
85  {
86  $status = [];
87  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
88  $status[$statusProviderId] = [];
89  foreach ($statusProviderList as $statusProvider) {
90  if ($statusProvider instanceof ‪RequestAwareStatusProviderInterface) {
91  $statuses = $statusProvider->getStatus($request);
92  } else {
93  $statuses = $statusProvider->getStatus();
94  }
95  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
96  }
97  }
98  return $status;
99  }
100 
106  public function ‪getDetailedSystemStatus()
107  {
108  $status = [];
109  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
110  $status[$statusProviderId] = [];
111  foreach ($statusProviderList as $statusProvider) {
112  if ($statusProvider instanceof ‪ExtendedStatusProviderInterface) {
113  $statuses = $statusProvider->getDetailedStatus();
114  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
115  }
116  }
117  }
118  return $status;
119  }
120 
127  public function ‪getHighestSeverity(array $statusCollection)
128  {
129  $highestSeverity = ReportStatus::NOTICE;
130  foreach ($statusCollection as $statusProvider => $providerStatuses) {
132  foreach ($providerStatuses as $status) {
133  if ($status->getSeverity() > $highestSeverity) {
134  $highestSeverity = $status->getSeverity();
135  }
136  // Reached the highest severity level, no need to go on
137  if ($highestSeverity == ReportStatus::ERROR) {
138  break;
139  }
140  }
141  }
142  return $highestSeverity;
143  }
144 
151  protected function ‪renderStatus(array $statusCollection)
152  {
153  // Apply sorting to collection and the providers
154  $statusCollection = $this->‪sortStatusProviders($statusCollection);
155  foreach ($statusCollection as &$statuses) {
156  $statuses = $this->‪sortStatuses($statuses);
157  }
158  unset($statuses);
159 
160  $view = GeneralUtility::makeInstance(StandaloneView::class);
161  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
162  'EXT:reports/Resources/Private/Templates/StatusReport.html'
163  ));
164 
165  return $view->assignMultiple([
166  'statusCollection' => $statusCollection,
167  'severityClassMapping' => [
168  ReportStatus::NOTICE => 'notice',
169  ReportStatus::INFO => 'info',
170  ReportStatus::OK => 'success',
171  ReportStatus::WARNING => 'warning',
172  ReportStatus::ERROR => 'danger',
173  ],
174  ])->render();
175  }
176 
183  protected function ‪sortStatusProviders(array $statusCollection)
184  {
185  // Extract the primary status collections, i.e. the status groups
186  // that must appear on top of the status report
187  // Change their keys to localized collection titles
188  $primaryStatuses = [
189  $this->‪getLanguageService()->‪getLL('status_typo3') => $statusCollection['typo3'],
190  $this->‪getLanguageService()->‪getLL('status_system') => $statusCollection['system'],
191  $this->‪getLanguageService()->‪getLL('status_security') => $statusCollection['security'],
192  $this->‪getLanguageService()->‪getLL('status_configuration') => $statusCollection['configuration'],
193  ];
194  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
195  // Assemble list of secondary status collections with left-over collections
196  // Change their keys using localized labels if available
197  // @todo extract into getLabel() method
198  $secondaryStatuses = [];
199  foreach ($statusCollection as $statusProviderId => $collection) {
200  if (strpos($statusProviderId, 'LLL:') === 0) {
201  // Label provided by extension
202  $label = $this->‪getLanguageService()->‪sL($statusProviderId);
203  } else {
204  // Generic label
205  $label = $this->‪getLanguageService()->‪getLL('status_' . $statusProviderId);
206  }
207  $providerLabel = empty($label) ? $statusProviderId : $label;
208  $secondaryStatuses[$providerLabel] = $collection;
209  }
210  // Sort the secondary status collections alphabetically
211  ksort($secondaryStatuses);
212  $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
213  return $orderedStatusCollection;
214  }
215 
222  protected function ‪sortStatuses(array $statusCollection)
223  {
224  $statuses = [];
225  $sortTitle = [];
226  $header = null;
228  foreach ($statusCollection as $status) {
229  if ($status->getTitle() === 'TYPO3') {
230  $header = $status;
231  continue;
232  }
233  $statuses[] = $status;
234  $sortTitle[] = $status->getSeverity();
235  }
236  array_multisort($sortTitle, SORT_DESC, $statuses);
237  // Making sure that the core version information is always on the top
238  if (is_object($header)) {
239  array_unshift($statuses, $header);
240  }
241  return $statuses;
242  }
243 
247  protected function ‪getLanguageService()
248  {
249  return ‪$GLOBALS['LANG'];
250  }
251 }
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:22
‪TYPO3\CMS\Reports\ReportInterface\getReport
‪string getReport()
‪TYPO3\CMS\Reports\Report\Status\Status\getHighestSeverity
‪int getHighestSeverity(array $statusCollection)
Definition: Status.php:126
‪TYPO3\CMS\Reports\Report\Status\Status\getLanguageService
‪LanguageService getLanguageService()
Definition: Status.php:246
‪TYPO3\CMS\Reports\Report\Status\Status\$statusProviders
‪StatusProviderInterface[][] $statusProviders
Definition: Status.php:36
‪TYPO3\CMS\Reports\Report\Status\Status\getStatusProviders
‪getStatusProviders()
Definition: Status.php:64
‪TYPO3\CMS\Reports\Report\Status\Status
Definition: Status.php:33
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Reports\Report\Status\Status\getSystemStatus
‪TYPO3 CMS Reports Status[][] getSystemStatus(ServerRequestInterface $request=null)
Definition: Status.php:83
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Reports\RequestAwareReportInterface
Definition: RequestAwareReportInterface.php:26
‪TYPO3\CMS\Reports\Report\Status\Status\getDetailedSystemStatus
‪TYPO3 CMS Reports Status[][] getDetailedSystemStatus()
Definition: Status.php:105
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatuses
‪array sortStatuses(array $statusCollection)
Definition: Status.php:221
‪TYPO3\CMS\Reports\Report\Status\Status\getReport
‪string getReport(ServerRequestInterface $request=null)
Definition: Status.php:53
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Reports\Report\Status\Status\renderStatus
‪string renderStatus(array $statusCollection)
Definition: Status.php:150
‪TYPO3\CMS\Reports\Report\Status
Definition: ConfigurationStatus.php:16
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef)
Definition: LanguageService.php:271
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Reports\ExtendedStatusProviderInterface
Definition: ExtendedStatusProviderInterface.php:22
‪TYPO3\CMS\Reports\RequestAwareStatusProviderInterface
Definition: RequestAwareStatusProviderInterface.php:26
‪TYPO3\CMS\Reports\Report\Status\Status\__construct
‪__construct()
Definition: Status.php:41
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatusProviders
‪array sortStatusProviders(array $statusCollection)
Definition: Status.php:182