‪TYPO3CMS  11.5
SystemInformationToolbarItem.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\EventDispatcher\EventDispatcherInterface;
27 use TYPO3\CMS\Core\Page\PageRenderer;
32 
37 {
43  protected ‪$totalCount = 0;
44 
50  protected ‪$highestSeverity;
51 
57  protected ‪$severityBadgeClass = '';
58 
62  protected ‪$systemInformation = [];
63 
67  protected ‪$systemMessages = [];
68 
72  protected ‪$eventDispatcher;
73 
77  protected ‪$maximumCountInBadge = 99;
78 
82  protected ‪$typo3Version;
83 
84  public function ‪__construct(EventDispatcherInterface ‪$eventDispatcher = null)
85  {
86  $this->eventDispatcher = ‪$eventDispatcher ?? GeneralUtility::makeInstance(EventDispatcherInterface::class);
87  $this->typo3Version = GeneralUtility::makeInstance(Typo3Version::class);
88  $this->‪getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu');
90  }
91 
102  public function ‪addSystemMessage($text, $status = ‪InformationStatus::STATUS_OK, $count = 0, $module = '', $params = '')
103  {
104  $this->totalCount += (int)$count;
105 
106  $messageSeverity = ‪InformationStatus::cast($status);
107  // define the severity for the badge
108  if ($messageSeverity->isGreaterThan($this->highestSeverity)) {
109  $this->highestSeverity = $messageSeverity;
110  }
111 
112  $this->systemMessages[] = [
113  'module' => $module,
114  'params' => $params,
115  'count' => (int)$count,
116  'status' => $messageSeverity,
117  'text' => $text,
118  ];
119  }
120 
130  public function ‪addSystemInformation($title, $value, $iconIdentifier, $status = ‪InformationStatus::STATUS_NOTICE)
131  {
132  $this->systemInformation[] = [
133  'title' => $title,
134  'value' => $value,
135  'iconIdentifier' => $iconIdentifier,
136  'status' => $status,
137  ];
138  }
139 
145  public function ‪checkAccess()
146  {
148  }
149 
155  public function ‪getItem()
156  {
157  return $this->‪getFluidTemplateObject('SystemInformationToolbarItem.html')->‪render();
158  }
159 
165  public function ‪getDropDown()
166  {
167  if (!$this->‪checkAccess()) {
168  return '';
169  }
170 
171  $this->‪collectInformation();
172 
173  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
174  $view = $this->‪getFluidTemplateObject('SystemInformationDropDown.html');
175 
176  try {
177  $environmentToolUrl = (string)$uriBuilder->buildUriFromRoute('tools_toolsenvironment');
178  } catch (RouteNotFoundException $e) {
179  $environmentToolUrl = '';
180  }
181 
182  $view->assignMultiple([
183  'environmentToolUrl' => $environmentToolUrl,
184  'messages' => $this->systemMessages,
185  'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount,
186  'severityBadgeClass' => $this->severityBadgeClass,
187  'systemInformation' => $this->systemInformation,
188  ]);
189  return $view->render();
190  }
191 
197  public function ‪getAdditionalAttributes()
198  {
199  return [];
200  }
201 
207  public function ‪hasDropDown()
208  {
209  return true;
210  }
211 
217  public function ‪getIndex()
218  {
219  return 75;
220  }
221 
225  protected function ‪collectInformation()
226  {
227  $this->‪getTypo3Version();
228  $this->‪getWebServer();
229  $this->‪getPhpVersion();
230  $this->‪getDebugger();
231  $this->‪getDatabase();
232  $this->‪getApplicationContext();
233  $this->‪getComposerMode();
234  $this->‪getGitRevision();
235  $this->‪getOperatingSystem();
236 
237  $this->eventDispatcher->dispatch(new ‪SystemInformationToolbarCollectorEvent($this));
238 
239  $this->severityBadgeClass = !$this->highestSeverity->equals(‪InformationStatus::STATUS_NOTICE) ? 'badge-' . (string)$this->highestSeverity : '';
240  }
241 
245  protected function ‪getTypo3Version()
246  {
247  $this->systemInformation[] = [
248  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version',
249  'value' => $this->typo3Version->getVersion(),
250  'iconIdentifier' => 'information-typo3-version',
251  ];
252  }
253 
257  protected function ‪getWebServer()
258  {
259  $this->systemInformation[] = [
260  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver',
261  'value' => $_SERVER['SERVER_SOFTWARE'],
262  'iconIdentifier' => 'information-webserver',
263  ];
264  }
265 
269  protected function ‪getPhpVersion()
270  {
271  $this->systemInformation[] = [
272  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.phpversion',
273  'value' => PHP_VERSION,
274  'iconIdentifier' => 'information-php-version',
275  ];
276  }
277 
278  protected function ‪getDebugger(): void
279  {
280  $knownDebuggers = ['xdebug', 'Zend Debugger'];
281  foreach ($knownDebuggers as $debugger) {
282  if (extension_loaded($debugger)) {
283  $debuggerVersion = phpversion($debugger) ?: '';
284  $this->systemInformation[] = [
285  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.debugger',
286  'value' => sprintf('%s %s', $debugger, $debuggerVersion),
287  'iconIdentifier' => 'information-debugger',
288  ];
289  }
290  }
291  }
292 
296  protected function ‪getDatabase()
297  {
298  foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
299  $serverVersion = '[' . $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database.offline') . ']';
300  $success = true;
301  try {
302  $serverVersion = GeneralUtility::makeInstance(ConnectionPool::class)
303  ->getConnectionByName($connectionName)
304  ->getServerVersion();
305  } catch (\Exception $exception) {
306  $success = false;
307  }
308  $this->systemInformation[] = [
309  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database',
310  'titleAddition' => $connectionName,
311  'value' => $serverVersion,
312  'status' => $success ?: ‪InformationStatus::STATUS_WARNING,
313  'iconIdentifier' => 'information-database',
314  ];
315  }
316  }
317 
321  protected function ‪getApplicationContext()
322  {
323  $applicationContext = ‪Environment::getContext();
324  $this->systemInformation[] = [
325  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.applicationcontext',
326  'value' => (string)$applicationContext,
327  'status' => $applicationContext->isProduction() ? ‪InformationStatus::STATUS_OK : ‪InformationStatus::STATUS_WARNING,
328  'iconIdentifier' => 'information-application-context',
329  ];
330  }
331 
335  protected function ‪getComposerMode()
336  {
338  return;
339  }
340 
341  $this->systemInformation[] = [
342  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.composerMode',
343  'value' => $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enabled'),
344  'iconIdentifier' => 'information-composer-mode',
345  ];
346  }
347 
351  protected function ‪getGitRevision()
352  {
353  if (!str_ends_with($this->typo3Version->getVersion(), '-dev') || $this->isFunctionDisabled('exec')) {
354  return;
355  }
356  // check if git exists
357  ‪CommandUtility::exec('git --version', $_, $returnCode);
358  if ((int)$returnCode !== 0) {
359  // git is not available
360  return;
361  }
362 
363  $revision = trim(‪CommandUtility::exec('git rev-parse --short HEAD'));
364  $branch = trim(‪CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
365  if (!empty($revision) && !empty($branch)) {
366  $this->systemInformation[] = [
367  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.gitrevision',
368  'value' => sprintf('%s [%s]', $revision, $branch),
369  'iconIdentifier' => 'information-git',
370  ];
371  }
372  }
373 
377  protected function ‪getOperatingSystem()
378  {
379  switch (PHP_OS_FAMILY) {
380  case 'Linux':
381  $icon = 'linux';
382  break;
383  case 'Darwin':
384  $icon = 'apple';
385  break;
386  case 'Windows':
387  $icon = 'windows';
388  break;
389  default:
390  $icon = 'unknown';
391  }
392  $this->systemInformation[] = [
393  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.operatingsystem',
394  'value' => PHP_OS . ' ' . php_uname('r'),
395  'iconIdentifier' => 'information-os-' . $icon,
396  ];
397  }
398 
405  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
406  {
407  $view = GeneralUtility::makeInstance(StandaloneView::class);
408  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
409  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']);
410  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']);
411 
412  $view->setTemplate($filename);
413 
414  $view->getRequest()->setControllerExtensionName('Backend');
415  return $view;
416  }
417 
424  protected function ‪isFunctionDisabled(string $functionName): bool
425  {
426  $disabledFunctions = ‪GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'));
427  if (!empty($disabledFunctions)) {
428  return in_array($functionName, $disabledFunctions, true);
429  }
430  return false;
431  }
432 
438  protected function ‪getBackendUserAuthentication()
439  {
440  return ‪$GLOBALS['BE_USER'];
441  }
442 
446  protected function ‪getLanguageService(): ?‪LanguageService
447  {
448  return ‪$GLOBALS['LANG'] ?? null;
449  }
450 
456  protected function ‪getPageRenderer()
457  {
458  return GeneralUtility::makeInstance(PageRenderer::class);
459  }
460 }
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_INFO
‪const STATUS_INFO
Definition: InformationStatus.php:35
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$typo3Version
‪Typo3Version $typo3Version
Definition: SystemInformationToolbarItem.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$highestSeverity
‪InformationStatus $highestSeverity
Definition: SystemInformationToolbarItem.php:48
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:22
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getItem
‪string getItem()
Definition: SystemInformationToolbarItem.php:147
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$totalCount
‪int $totalCount
Definition: SystemInformationToolbarItem.php:42
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getIndex
‪int getIndex()
Definition: SystemInformationToolbarItem.php:209
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\isFunctionDisabled
‪bool isFunctionDisabled(string $functionName)
Definition: SystemInformationToolbarItem.php:416
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent
Definition: SystemInformationToolbarCollectorEvent.php:27
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\__construct
‪__construct(EventDispatcherInterface $eventDispatcher=null)
Definition: SystemInformationToolbarItem.php:76
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getWebServer
‪getWebServer()
Definition: SystemInformationToolbarItem.php:249
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getApplicationContext
‪getApplicationContext()
Definition: SystemInformationToolbarItem.php:313
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:245
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getOperatingSystem
‪getOperatingSystem()
Definition: SystemInformationToolbarItem.php:369
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:161
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:25
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_OK
‪const STATUS_OK
Definition: InformationStatus.php:40
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemMessages
‪array $systemMessages
Definition: SystemInformationToolbarItem.php:62
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:141
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$severityBadgeClass
‪string $severityBadgeClass
Definition: SystemInformationToolbarItem.php:54
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_WARNING
‪const STATUS_WARNING
Definition: InformationStatus.php:45
‪TYPO3\CMS\Core\Utility\CommandUtility\exec
‪static string exec($command, &$output=null, &$returnValue=0)
Definition: CommandUtility.php:81
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDatabase
‪getDatabase()
Definition: SystemInformationToolbarItem.php:288
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\collectInformation
‪collectInformation()
Definition: SystemInformationToolbarItem.php:217
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Backend\Backend\ToolbarItems
Definition: ClearCacheToolbarItem.php:16
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$maximumCountInBadge
‪int $maximumCountInBadge
Definition: SystemInformationToolbarItem.php:70
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getBackendUserAuthentication
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUserAuthentication()
Definition: SystemInformationToolbarItem.php:430
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem
Definition: SystemInformationToolbarItem.php:37
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getGitRevision
‪getGitRevision()
Definition: SystemInformationToolbarItem.php:343
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getTypo3Version
‪getTypo3Version()
Definition: SystemInformationToolbarItem.php:237
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: SystemInformationToolbarItem.php:397
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: SystemInformationToolbarItem.php:199
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemInformation
‪array $systemInformation
Definition: SystemInformationToolbarItem.php:58
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus
Definition: InformationStatus.php:24
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemInformation
‪addSystemInformation($title, $value, $iconIdentifier, $status=InformationStatus::STATUS_NOTICE)
Definition: SystemInformationToolbarItem.php:122
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: SystemInformationToolbarItem.php:189
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemMessage
‪addSystemMessage($text, $status=InformationStatus::STATUS_OK, $count=0, $module='', $params='')
Definition: SystemInformationToolbarItem.php:94
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: SystemInformationToolbarItem.php:448
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPhpVersion
‪getPhpVersion()
Definition: SystemInformationToolbarItem.php:261
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: SystemInformationToolbarItem.php:66
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\checkAccess
‪bool checkAccess()
Definition: SystemInformationToolbarItem.php:137
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDropDown
‪string getDropDown()
Definition: SystemInformationToolbarItem.php:157
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_NOTICE
‪const STATUS_NOTICE
Definition: InformationStatus.php:30
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDebugger
‪getDebugger()
Definition: SystemInformationToolbarItem.php:270
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getComposerMode
‪getComposerMode()
Definition: SystemInformationToolbarItem.php:327
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getLanguageService
‪LanguageService null getLanguageService()
Definition: SystemInformationToolbarItem.php:438