‪TYPO3CMS  10.4
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;
25 use ‪TYPO3\CMS\Reports\Status as ReportStatus;
27 
32 {
36  protected ‪$statusProviders = [];
37 
41  public function ‪__construct()
42  {
43  $this->‪getLanguageService()->‪includeLLFile('EXT:reports/Resources/Private/Language/locallang_reports.xlf');
44  $this->‪getStatusProviders();
45  }
46 
53  public function ‪getReport(ServerRequestInterface $request = null)
54  {
55  $content = '';
56  $status = $this->‪getSystemStatus($request);
57  $highestSeverity = $this->‪getHighestSeverity($status);
58  // Updating the registry
59  $registry = GeneralUtility::makeInstance(Registry::class);
60  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
61  $content .= '<p class="lead">' . $this->‪getLanguageService()->‪getLL('status_report_explanation') . '</p>';
62  return $content . $this->‪renderStatus($status);
63  }
64 
68  protected function ‪getStatusProviders()
69  {
70  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers'] as $key => $statusProvidersList) {
71  $this->statusProviders[$key] = [];
72  foreach ($statusProvidersList as $statusProvider) {
73  $statusProviderInstance = GeneralUtility::makeInstance($statusProvider);
74  if ($statusProviderInstance instanceof ‪StatusProviderInterface) {
75  $this->statusProviders[$key][] = $statusProviderInstance;
76  }
77  }
78  }
79  }
80 
87  public function ‪getSystemStatus(ServerRequestInterface $request = null)
88  {
89  $status = [];
90  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
91  $status[$statusProviderId] = [];
92  foreach ($statusProviderList as $statusProvider) {
93  if ($statusProvider instanceof ‪RequestAwareStatusProviderInterface) {
94  $statuses = $statusProvider->getStatus($request);
95  } else {
96  $statuses = $statusProvider->getStatus();
97  }
98  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
99  }
100  }
101  return $status;
102  }
103 
109  public function ‪getDetailedSystemStatus()
110  {
111  $status = [];
112  foreach ($this->statusProviders as $statusProviderId => $statusProviderList) {
113  $status[$statusProviderId] = [];
114  foreach ($statusProviderList as $statusProvider) {
115  if ($statusProvider instanceof ‪ExtendedStatusProviderInterface) {
116  $statuses = $statusProvider->getDetailedStatus();
117  $status[$statusProviderId] = array_merge($status[$statusProviderId], $statuses);
118  }
119  }
120  }
121  return $status;
122  }
123 
130  public function ‪getHighestSeverity(array $statusCollection)
131  {
132  $highestSeverity = ReportStatus::NOTICE;
133  foreach ($statusCollection as $statusProvider => $providerStatuses) {
135  foreach ($providerStatuses as $status) {
136  if ($status->getSeverity() > $highestSeverity) {
137  $highestSeverity = $status->getSeverity();
138  }
139  // Reached the highest severity level, no need to go on
140  if ($highestSeverity == ReportStatus::ERROR) {
141  break;
142  }
143  }
144  }
145  return $highestSeverity;
146  }
147 
154  protected function ‪renderStatus(array $statusCollection)
155  {
156  $content = '';
157  $template = '
158  <tr>
159  <td class="###CLASS### col-xs-6">###HEADER###</td>
160  <td class="###CLASS### col-xs-6">###STATUS###<br>###CONTENT###</td>
161  </tr>
162  ';
163  $statuses = $this->‪sortStatusProviders($statusCollection);
164  $id = 0;
165  foreach ($statuses as $provider => $providerStatus) {
166  $providerState = $this->‪sortStatuses($providerStatus);
167  $id++;
168  $classes = [
169  ReportStatus::NOTICE => 'notice',
170  ReportStatus::INFO => 'info',
171  ReportStatus::OK => 'success',
172  ReportStatus::WARNING => 'warning',
173  ReportStatus::ERROR => 'danger'
174  ];
175  $messages = '';
177  foreach ($providerState as $status) {
178  $severity = $status->getSeverity();
179  $messages .= strtr($template, [
180  '###CLASS###' => $classes[$severity],
181  '###HEADER###' => $status->getTitle(),
182  '###STATUS###' => $status->getValue(),
183  '###CONTENT###' => $status->getMessage()
184  ]);
185  }
186  $header = '<h2>' . $provider . '</h2>';
187  $table = '<table class="table table-striped table-hover">';
188  $table .= '<tbody>' . $messages . '</tbody>';
189  $table .= '</table>';
190 
191  $content .= $header . $table;
192  }
193  return $content;
194  }
195 
202  protected function ‪sortStatusProviders(array $statusCollection)
203  {
204  // Extract the primary status collections, i.e. the status groups
205  // that must appear on top of the status report
206  // Change their keys to localized collection titles
207  $primaryStatuses = [
208  $this->‪getLanguageService()->‪getLL('status_typo3') => $statusCollection['typo3'],
209  $this->‪getLanguageService()->‪getLL('status_system') => $statusCollection['system'],
210  $this->‪getLanguageService()->‪getLL('status_security') => $statusCollection['security'],
211  $this->‪getLanguageService()->‪getLL('status_configuration') => $statusCollection['configuration']
212  ];
213  unset($statusCollection['typo3'], $statusCollection['system'], $statusCollection['security'], $statusCollection['configuration']);
214  // Assemble list of secondary status collections with left-over collections
215  // Change their keys using localized labels if available
216  // @todo extract into getLabel() method
217  $secondaryStatuses = [];
218  foreach ($statusCollection as $statusProviderId => $collection) {
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:22
‪TYPO3\CMS\Reports\ReportInterface\getReport
‪string getReport()
‪TYPO3\CMS\Reports\Report\Status\Status\getHighestSeverity
‪int getHighestSeverity(array $statusCollection)
Definition: Status.php:129
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪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:35
‪TYPO3\CMS\Reports\Report\Status\Status\getStatusProviders
‪getStatusProviders()
Definition: Status.php:67
‪TYPO3\CMS\Reports\Report\Status\Status
Definition: Status.php:32
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪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:240
‪TYPO3\CMS\Reports\Report\Status\Status\getDetailedSystemStatus
‪TYPO3 CMS Reports Status[] getDetailedSystemStatus()
Definition: Status.php:108
‪TYPO3\CMS\Reports\Report\Status\Status\getReport
‪string getReport(ServerRequestInterface $request=null)
Definition: Status.php:52
‪$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:153
‪TYPO3\CMS\Reports\Report\Status
Definition: ConfigurationStatus.php:16
‪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:40
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:154
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Reports\Report\Status\Status\getSystemStatus
‪TYPO3 CMS Reports Status[] getSystemStatus(ServerRequestInterface $request=null)
Definition: Status.php:86
‪TYPO3\CMS\Reports\Report\Status\Status\sortStatusProviders
‪array sortStatusProviders(array $statusCollection)
Definition: Status.php:201