‪TYPO3CMS  9.5
Status.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ServerRequestInterface;
24 use ‪TYPO3\CMS\Reports\Status as ReportStatus;
26 
31 {
35  protected ‪$statusProviders = [];
36 
40  public function ‪__construct()
41  {
42  $this->‪getLanguageService()->‪includeLLFile('EXT:reports/Resources/Private/Language/locallang_reports.xlf');
43  $this->‪getStatusProviders();
44  }
45 
52  public function ‪getReport(ServerRequestInterface $request = null)
53  {
54  $content = '';
55  $status = $this->‪getSystemStatus($request);
56  $highestSeverity = $this->‪getHighestSeverity($status);
57  // Updating the registry
58  $registry = GeneralUtility::makeInstance(Registry::class);
59  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
60  $content .= '<p class="lead">' . $this->‪getLanguageService()->‪getLL('status_report_explanation') . '</p>';
61  return $content . $this->‪renderStatus($status);
62  }
63 
67  protected function ‪getStatusProviders()
68  {
69  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
70  $this->statusProviders[$key] = [];
71  foreach ($statusProvidersList as $statusProvider) {
72  $statusProviderInstance = GeneralUtility::makeInstance($statusProvider);
73  if ($statusProviderInstance instanceof ‪StatusProviderInterface) {
74  $this->statusProviders[$key][] = $statusProviderInstance;
75  }
76  }
77  }
78  }
79 
86  public function ‪getSystemStatus(ServerRequestInterface $request = null)
87  {
88  $status = [];
89  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
90  $status[$statusProviderId] = [];
91  foreach ($statusProviderList as $statusProvider) {
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  }
100  return $status;
101  }
102 
108  public function ‪getDetailedSystemStatus()
109  {
110  $status = [];
111  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
112  $status[$statusProviderId] = [];
113  foreach ($statusProviderList as $statusProvider) {
114  if ($statusProvider instanceof ‪ExtendedStatusProviderInterface) {
115  $statuses = $statusProvider->getDetailedStatus();
116  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
117  }
118  }
119  }
120  return $status;
121  }
122 
129  public function ‪getHighestSeverity(array $statusCollection)
130  {
131  $highestSeverity = ReportStatus::NOTICE;
132  foreach ($statusCollection as $statusProvider => $providerStatuses) {
134  foreach ($providerStatuses as $status) {
135  if ($status->getSeverity() > $highestSeverity) {
136  $highestSeverity = $status->getSeverity();
137  }
138  // Reached the highest severity level, no need to go on
139  if ($highestSeverity == ReportStatus::ERROR) {
140  break;
141  }
142  }
143  }
144  return $highestSeverity;
145  }
146 
153  protected function ‪renderStatus(array $statusCollection)
154  {
155  $content = '';
156  $template = '
157  <tr>
158  <td class="###CLASS### col-xs-6">###HEADER###</td>
159  <td class="###CLASS### col-xs-6">###STATUS###<br>###CONTENT###</td>
160  </tr>
161  ';
162  $statuses = $this->‪sortStatusProviders($statusCollection);
163  $id = 0;
164  foreach ($statuses as $provider => $providerStatus) {
165  $providerState = $this->‪sortStatuses($providerStatus);
166  $id++;
167  $classes = [
168  ReportStatus::NOTICE => 'notice',
169  ReportStatus::INFO => 'info',
170  ReportStatus::OK => 'success',
171  ReportStatus::WARNING => 'warning',
172  ReportStatus::ERROR => 'danger'
173  ];
174  $messages = '';
176  foreach ($providerState as $status) {
177  $severity = $status->getSeverity();
178  $messages .= strtr($template, [
179  '###CLASS###' => $classes[$severity],
180  '###HEADER###' => $status->getTitle(),
181  '###STATUS###' => $status->getValue(),
182  '###CONTENT###' => $status->getMessage()
183  ]);
184  }
185  $header = '<h2>' . $provider . '</h2>';
186  $table = '<table class="table table-striped table-hover">';
187  $table .= '<tbody>' . $messages . '</tbody>';
188  $table .= '</table>';
189 
190  $content .= $header . $table;
191  }
192  return $content;
193  }
194 
201  protected function ‪sortStatusProviders(array $statusCollection)
202  {
203  // Extract the primary status collections, i.e. the status groups
204  // that must appear on top of the status report
205  // Change their keys to localized collection titles
206  $primaryStatuses = [
207  $this->‪getLanguageService()->‪getLL('status_typo3') => $statusCollection['typo3'],
208  $this->‪getLanguageService()->‪getLL('status_system') => $statusCollection['system'],
209  $this->‪getLanguageService()->‪getLL('status_security') => $statusCollection['security'],
210  $this->‪getLanguageService()->‪getLL('status_configuration') => $statusCollection['configuration']
211  ];
212  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
213  // Assemble list of secondary status collections with left-over collections
214  // Change their keys using localized labels if available
215  // @todo extract into getLabel() method
216  $secondaryStatuses = [];
217  foreach ($statusCollection as $statusProviderId => $collection) {
218  $label = '';
219  if (strpos($statusProviderId, 'LLL:') === 0) {
220  // Label provided by extension
221  $label = $this->‪getLanguageService()->‪sL($statusProviderId);
222  } else {
223  // Generic label
224  $label = $this->‪getLanguageService()->‪getLL('status_' . $statusProviderId);
225  }
226  $providerLabel = empty($label) ? $statusProviderId : $label;
227  $secondaryStatuses[$providerLabel] = $collection;
228  }
229  // Sort the secondary status collections alphabetically
230  ksort($secondaryStatuses);
231  $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
232  return $orderedStatusCollection;
233  }
234 
241  protected function ‪sortStatuses(array $statusCollection)
242  {
243  $statuses = [];
244  $sortTitle = [];
245  $header = null;
247  foreach ($statusCollection as $status) {
248  if ($status->getTitle() === 'TYPO3') {
249  $header = $status;
250  continue;
251  }
252  $statuses[] = $status;
253  $sortTitle[] = $status->getSeverity();
254  }
255  array_multisort($sortTitle, SORT_DESC, $statuses);
256  // Making sure that the core version information is always on the top
257  if (is_object($header)) {
258  array_unshift($statuses, $header);
259  }
260  return $statuses;
261  }
262 
266  protected function ‪getLanguageService()
267  {
268  return ‪$GLOBALS['LANG'];
269  }
270 }
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:21
‪TYPO3\CMS\Reports\ReportInterface\getReport
‪string getReport()
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Reports\Report\Status\Status\getHighestSeverity
‪int getHighestSeverity(array $statusCollection)
Definition: Status.php:128
‪TYPO3\CMS\Reports\Report\Status\Status\getLanguageService
‪LanguageService getLanguageService()
Definition: Status.php:265
‪TYPO3\CMS\Reports\Report\Status\Status\$statusProviders
‪StatusProviderInterface[][] $statusProviders
Definition: Status.php:34
‪TYPO3\CMS\Reports\Report\Status\Status\getStatusProviders
‪getStatusProviders()
Definition: Status.php:66
‪TYPO3\CMS\Reports\Report\Status\Status
Definition: Status.php:31
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:32
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:158
‪TYPO3\CMS\Reports\Status
Definition: Status.php:22
‪TYPO3\CMS\Reports\RequestAwareReportInterface
Definition: RequestAwareReportInterface.php:24
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatuses
‪array sortStatuses(array $statusCollection)
Definition: Status.php:240
‪TYPO3\CMS\Reports\Report\Status\Status\getDetailedSystemStatus
‪TYPO3 CMS Reports Status[] getDetailedSystemStatus()
Definition: Status.php:107
‪TYPO3\CMS\Reports\Report\Status\Status\getReport
‪string getReport(ServerRequestInterface $request=null)
Definition: Status.php:51
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Report\Status\Status\renderStatus
‪string renderStatus(array $statusCollection)
Definition: Status.php:152
‪TYPO3\CMS\Reports\Report\Status
Definition: ConfigurationStatus.php:2
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Reports\ExtendedStatusProviderInterface
Definition: ExtendedStatusProviderInterface.php:21
‪TYPO3\CMS\Reports\RequestAwareStatusProviderInterface
Definition: RequestAwareStatusProviderInterface.php:24
‪TYPO3\CMS\Reports\Report\Status\Status\__construct
‪__construct()
Definition: Status.php:39
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Reports\Report\Status\Status\getSystemStatus
‪TYPO3 CMS Reports Status[] getSystemStatus(ServerRequestInterface $request=null)
Definition: Status.php:85
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatusProviders
‪array sortStatusProviders(array $statusCollection)
Definition: Status.php:200