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