TYPO3 CMS  TYPO3_8-7
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 
24 
28 class Status implements ReportInterface
29 {
33  protected $statusProviders = [];
34 
38  public function __construct()
39  {
40  $this->getStatusProviders();
41  $this->getLanguageService()->includeLLFile('EXT:reports/Resources/Private/Language/locallang_reports.xlf');
42  }
43 
49  public function getReport()
50  {
51  $content = '';
52  $status = $this->getSystemStatus();
53  $highestSeverity = $this->getHighestSeverity($status);
54  // Updating the registry
55  $registry = GeneralUtility::makeInstance(Registry::class);
56  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
57  $content .= '<p class="lead">' . $this->getLanguageService()->getLL('status_report_explanation') . '</p>';
58  return $content . $this->renderStatus($status);
59  }
60 
64  protected function getStatusProviders()
65  {
66  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
67  $this->statusProviders[$key] = [];
68  foreach ($statusProvidersList as $statusProvider) {
69  $statusProviderInstance = GeneralUtility::makeInstance($statusProvider);
70  if ($statusProviderInstance instanceof StatusProviderInterface) {
71  $this->statusProviders[$key][] = $statusProviderInstance;
72  }
73  }
74  }
75  }
76 
82  public function getSystemStatus()
83  {
84  $status = [];
85  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
86  $status[$statusProviderId] = [];
87  foreach ($statusProviderList as $statusProvider) {
88  $statuses = $statusProvider->getStatus();
89  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
90  }
91  }
92  return $status;
93  }
94 
100  public function getDetailedSystemStatus()
101  {
102  $status = [];
103  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
104  $status[$statusProviderId] = [];
105  foreach ($statusProviderList as $statusProvider) {
106  if ($statusProvider instanceof ExtendedStatusProviderInterface) {
107  $statuses = $statusProvider->getDetailedStatus();
108  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
109  }
110  }
111  }
112  return $status;
113  }
114 
121  public function getHighestSeverity(array $statusCollection)
122  {
123  $highestSeverity = ReportStatus::NOTICE;
124  foreach ($statusCollection as $statusProvider => $providerStatuses) {
126  foreach ($providerStatuses as $status) {
127  if ($status->getSeverity() > $highestSeverity) {
128  $highestSeverity = $status->getSeverity();
129  }
130  // Reached the highest severity level, no need to go on
131  if ($highestSeverity == ReportStatus::ERROR) {
132  break;
133  }
134  }
135  }
136  return $highestSeverity;
137  }
138 
145  protected function renderStatus(array $statusCollection)
146  {
147  $content = '';
148  $template = '
149  <tr>
150  <td class="###CLASS### col-xs-6">###HEADER###</td>
151  <td class="###CLASS### col-xs-6">###STATUS###<br>###CONTENT###</td>
152  </tr>
153  ';
154  $statuses = $this->sortStatusProviders($statusCollection);
155  $id = 0;
156  foreach ($statuses as $provider => $providerStatus) {
157  $providerState = $this->sortStatuses($providerStatus);
158  $id++;
159  $classes = [
160  ReportStatus::NOTICE => 'notice',
161  ReportStatus::INFO => 'info',
162  ReportStatus::OK => 'success',
163  ReportStatus::WARNING => 'warning',
164  ReportStatus::ERROR => 'danger'
165  ];
166  $messages = '';
168  foreach ($providerState as $status) {
169  $severity = $status->getSeverity();
170  $messages .= strtr($template, [
171  '###CLASS###' => $classes[$severity],
172  '###HEADER###' => $status->getTitle(),
173  '###STATUS###' => $status->getValue(),
174  '###CONTENT###' => $status->getMessage()
175  ]);
176  }
177  $header = '<h2>' . $provider . '</h2>';
178  $table = '<table class="table table-striped table-hover">';
179  $table .= '<tbody>' . $messages . '</tbody>';
180  $table .= '</table>';
181 
182  $content .= $header . $table;
183  }
184  return $content;
185  }
186 
193  protected function sortStatusProviders(array $statusCollection)
194  {
195  // Extract the primary status collections, i.e. the status groups
196  // that must appear on top of the status report
197  // Change their keys to localized collection titles
198  $primaryStatuses = [
199  $this->getLanguageService()->getLL('status_typo3') => $statusCollection['typo3'],
200  $this->getLanguageService()->getLL('status_system') => $statusCollection['system'],
201  $this->getLanguageService()->getLL('status_security') => $statusCollection['security'],
202  $this->getLanguageService()->getLL('status_configuration') => $statusCollection['configuration']
203  ];
204  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
205  // Assemble list of secondary status collections with left-over collections
206  // Change their keys using localized labels if available
207  // @todo extract into getLabel() method
208  $secondaryStatuses = [];
209  foreach ($statusCollection as $statusProviderId => $collection) {
210  $label = '';
211  if (strpos($statusProviderId, 'LLL:') === 0) {
212  // Label provided by extension
213  $label = $this->getLanguageService()->sL($statusProviderId);
214  } else {
215  // Generic label
216  $label = $this->getLanguageService()->getLL('status_' . $statusProviderId);
217  }
218  $providerLabel = empty($label) ? $statusProviderId : $label;
219  $secondaryStatuses[$providerLabel] = $collection;
220  }
221  // Sort the secondary status collections alphabetically
222  ksort($secondaryStatuses);
223  $orderedStatusCollection = array_merge($primaryStatuses, $secondaryStatuses);
224  return $orderedStatusCollection;
225  }
226 
233  protected function sortStatuses(array $statusCollection)
234  {
235  $statuses = [];
236  $sortTitle = [];
237  $header = null;
239  foreach ($statusCollection as $status) {
240  if ($status->getTitle() === 'TYPO3') {
241  $header = $status;
242  continue;
243  }
244  $statuses[] = $status;
245  $sortTitle[] = $status->getSeverity();
246  }
247  array_multisort($sortTitle, SORT_DESC, $statuses);
248  // Making sure that the core version information is always on the top
249  if (is_object($header)) {
250  array_unshift($statuses, $header);
251  }
252  return $statuses;
253  }
254 
258  protected function getLanguageService()
259  {
260  return $GLOBALS['LANG'];
261  }
262 }
sortStatusProviders(array $statusCollection)
Definition: Status.php:193
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']