‪TYPO3CMS  10.4
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;
33 
38 {
44  protected ‪$totalCount = 0;
45 
51  protected ‪$highestSeverity;
52 
58  protected ‪$severityBadgeClass = '';
59 
63  protected ‪$systemInformation = [];
64 
68  protected ‪$systemMessages = [];
69 
73  protected ‪$eventDispatcher;
74 
78  protected ‪$maximumCountInBadge = 99;
79 
83  protected ‪$typo3Version;
84 
85  public function ‪__construct(EventDispatcherInterface ‪$eventDispatcher = null)
86  {
87  $this->eventDispatcher = ‪$eventDispatcher ?? GeneralUtility::getContainer()->get(EventDispatcherInterface::class);
88  $this->typo3Version = GeneralUtility::makeInstance(Typo3Version::class);
89  $this->‪getPageRenderer()->‪loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu');
91  }
92 
103  public function ‪addSystemMessage($text, $status = ‪InformationStatus::STATUS_OK, $count = 0, $module = '', $params = '')
104  {
105  $this->totalCount += (int)$count;
106 
108  $messageSeverity = ‪InformationStatus::cast($status);
109  // define the severity for the badge
110  if ($messageSeverity->isGreaterThan($this->highestSeverity)) {
111  $this->highestSeverity = $messageSeverity;
112  }
113 
114  $this->systemMessages[] = [
115  'module' => $module,
116  'params' => $params,
117  'count' => (int)$count,
118  'status' => $messageSeverity,
119  'text' => $text
120  ];
121  }
122 
132  public function ‪addSystemInformation($title, $value, $iconIdentifier, $status = ‪InformationStatus::STATUS_NOTICE)
133  {
134  $this->systemInformation[] = [
135  'title' => $title,
136  'value' => $value,
137  'iconIdentifier' => $iconIdentifier,
138  'status' => $status
139  ];
140  }
141 
147  public function ‪checkAccess()
148  {
150  }
151 
157  public function ‪getItem()
158  {
159  return $this->‪getFluidTemplateObject('SystemInformationToolbarItem.html')->‪render();
160  }
161 
167  public function ‪getDropDown()
168  {
169  if (!$this->‪checkAccess()) {
170  return '';
171  }
172 
173  $this->‪collectInformation();
174 
175  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
176  $view = $this->‪getFluidTemplateObject('SystemInformationDropDown.html');
177 
178  try {
179  $environmentToolUrl = (string)$uriBuilder->buildUriFromRoute('tools_toolsenvironment');
180  } catch (RouteNotFoundException $e) {
181  $environmentToolUrl = '';
182  }
183 
184  $view->assignMultiple([
185  'environmentToolUrl' => $environmentToolUrl,
186  'messages' => $this->systemMessages,
187  'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount,
188  'severityBadgeClass' => $this->severityBadgeClass,
189  'systemInformation' => $this->systemInformation
190  ]);
191  return $view->render();
192  }
193 
199  public function ‪getAdditionalAttributes()
200  {
201  return [];
202  }
203 
209  public function ‪hasDropDown()
210  {
211  return true;
212  }
213 
219  public function ‪getIndex()
220  {
221  return 75;
222  }
223 
227  protected function ‪collectInformation()
228  {
229  $this->‪getTypo3Version();
230  $this->‪getWebServer();
231  $this->‪getPhpVersion();
232  $this->‪getDatabase();
233  $this->‪getApplicationContext();
234  $this->‪getComposerMode();
235  $this->‪getGitRevision();
236  $this->‪getOperatingSystem();
237 
238  $this->eventDispatcher->dispatch(new ‪SystemInformationToolbarCollectorEvent($this));
239 
240  $this->severityBadgeClass = !$this->highestSeverity->equals(‪InformationStatus::STATUS_NOTICE) ? 'badge-' . (string)$this->highestSeverity : '';
241  }
242 
246  protected function ‪getTypo3Version()
247  {
248  $this->systemInformation[] = [
249  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version',
250  'value' => $this->typo3Version->getVersion(),
251  'iconIdentifier' => 'information-typo3-version'
252  ];
253  }
254 
258  protected function ‪getWebServer()
259  {
260  $this->systemInformation[] = [
261  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver',
262  'value' => $_SERVER['SERVER_SOFTWARE'],
263  'iconIdentifier' => 'information-webserver'
264  ];
265  }
266 
270  protected function ‪getPhpVersion()
271  {
272  $this->systemInformation[] = [
273  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.phpversion',
274  'value' => PHP_VERSION,
275  'iconIdentifier' => 'information-php-version'
276  ];
277  }
278 
282  protected function ‪getDatabase()
283  {
284  foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
285  $serverVersion = '[' . $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database.offline') . ']';
286  $success = true;
287  try {
288  $serverVersion = GeneralUtility::makeInstance(ConnectionPool::class)
289  ->getConnectionByName($connectionName)
290  ->getServerVersion();
291  } catch (\‪Exception $exception) {
292  $success = false;
293  }
294  $this->systemInformation[] = [
295  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database',
296  'titleAddition' => $connectionName,
297  'value' => $serverVersion,
298  'status' => $success ?: ‪InformationStatus::STATUS_WARNING,
299  'iconIdentifier' => 'information-database'
300  ];
301  }
302  }
303 
307  protected function ‪getApplicationContext()
308  {
309  $applicationContext = ‪Environment::getContext();
310  $this->systemInformation[] = [
311  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.applicationcontext',
312  'value' => (string)$applicationContext,
313  'status' => $applicationContext->isProduction() ? ‪InformationStatus::STATUS_OK : ‪InformationStatus::STATUS_WARNING,
314  'iconIdentifier' => 'information-application-context'
315  ];
316  }
317 
321  protected function ‪getComposerMode()
322  {
324  return;
325  }
326 
327  $this->systemInformation[] = [
328  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.composerMode',
329  'value' => $this->‪getLanguageService()->‪sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enabled'),
330  'iconIdentifier' => 'information-composer-mode'
331  ];
332  }
333 
337  protected function ‪getGitRevision()
338  {
339  if (!‪StringUtility::endsWith($this->typo3Version->getVersion(), '-dev') || $this->isFunctionDisabled('exec')) {
340  return;
341  }
342  // check if git exists
343  ‪CommandUtility::exec('git --version', $_, $returnCode);
344  if ((int)$returnCode !== 0) {
345  // git is not available
346  return;
347  }
348 
349  $revision = trim(‪CommandUtility::exec('git rev-parse --short HEAD'));
350  $branch = trim(‪CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
351  if (!empty($revision) && !empty($branch)) {
352  $this->systemInformation[] = [
353  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.gitrevision',
354  'value' => sprintf('%s [%s]', $revision, $branch),
355  'iconIdentifier' => 'information-git'
356  ];
357  }
358  }
359 
363  protected function ‪getOperatingSystem()
364  {
365  switch (PHP_OS_FAMILY) {
366  case 'Linux':
367  $icon = 'linux';
368  break;
369  case 'Darwin':
370  $icon = 'apple';
371  break;
372  case 'Windows':
373  $icon = 'windows';
374  break;
375  default:
376  $icon = 'unknown';
377  }
378  $this->systemInformation[] = [
379  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.operatingsystem',
380  'value' => PHP_OS . ' ' . php_uname('r'),
381  'iconIdentifier' => 'information-os-' . $icon
382  ];
383  }
384 
391  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
392  {
393  $view = GeneralUtility::makeInstance(StandaloneView::class);
394  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
395  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']);
396  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']);
397 
398  $view->setTemplate($filename);
399 
400  $view->getRequest()->setControllerExtensionName('Backend');
401  return $view;
402  }
403 
410  protected function ‪isFunctionDisabled(string $functionName): bool
411  {
412  $disabledFunctions = ‪GeneralUtility::trimExplode(',', (string)ini_get('disable_functions'));
413  if (!empty($disabledFunctions)) {
414  return in_array($functionName, $disabledFunctions, true);
415  }
416  return false;
417  }
418 
424  protected function ‪getBackendUserAuthentication()
425  {
426  return ‪$GLOBALS['BE_USER'];
427  }
428 
432  protected function ‪getLanguageService(): ?‪LanguageService
433  {
434  return ‪$GLOBALS['LANG'] ?? null;
435  }
436 
442  protected function ‪getPageRenderer()
443  {
444  return GeneralUtility::makeInstance(PageRenderer::class);
445  }
446 }
‪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:75
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$highestSeverity
‪InformationStatus $highestSeverity
Definition: SystemInformationToolbarItem.php:49
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:25
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getItem
‪string getItem()
Definition: SystemInformationToolbarItem.php:149
‪TYPO3\CMS\Core\Utility\StringUtility\endsWith
‪static bool endsWith($haystack, $needle)
Definition: StringUtility.php:61
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$totalCount
‪int $totalCount
Definition: SystemInformationToolbarItem.php:43
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getIndex
‪int getIndex()
Definition: SystemInformationToolbarItem.php:211
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\isFunctionDisabled
‪bool isFunctionDisabled(string $functionName)
Definition: SystemInformationToolbarItem.php:402
‪TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent
Definition: SystemInformationToolbarCollectorEvent.php:27
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\__construct
‪__construct(EventDispatcherInterface $eventDispatcher=null)
Definition: SystemInformationToolbarItem.php:77
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getWebServer
‪getWebServer()
Definition: SystemInformationToolbarItem.php:250
‪TYPO3\CMS\Backend\Exception
Definition: Exception.php:24
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getApplicationContext
‪getApplicationContext()
Definition: SystemInformationToolbarItem.php:299
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:292
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getOperatingSystem
‪getOperatingSystem()
Definition: SystemInformationToolbarItem.php:355
‪TYPO3\CMS\Core\Localization\LanguageService\sL
‪string sL($input)
Definition: LanguageService.php:194
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:26
‪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:63
‪TYPO3\CMS\Core\Page\PageRenderer\loadRequireJsModule
‪loadRequireJsModule($mainModuleName, $callBackFunction=null)
Definition: PageRenderer.php:1493
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:133
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$severityBadgeClass
‪string $severityBadgeClass
Definition: SystemInformationToolbarItem.php:55
‪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:274
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\collectInformation
‪collectInformation()
Definition: SystemInformationToolbarItem.php:219
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Backend\ToolbarItems
Definition: ClearCacheToolbarItem.php:16
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$maximumCountInBadge
‪int $maximumCountInBadge
Definition: SystemInformationToolbarItem.php:71
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getBackendUserAuthentication
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUserAuthentication()
Definition: SystemInformationToolbarItem.php:416
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem
Definition: SystemInformationToolbarItem.php:38
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getGitRevision
‪getGitRevision()
Definition: SystemInformationToolbarItem.php:329
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getTypo3Version
‪getTypo3Version()
Definition: SystemInformationToolbarItem.php:238
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: SystemInformationToolbarItem.php:383
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: SystemInformationToolbarItem.php:201
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemInformation
‪array $systemInformation
Definition: SystemInformationToolbarItem.php:59
‪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:124
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:144
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: SystemInformationToolbarItem.php:191
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemMessage
‪addSystemMessage($text, $status=InformationStatus::STATUS_OK, $count=0, $module='', $params='')
Definition: SystemInformationToolbarItem.php:95
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: SystemInformationToolbarItem.php:434
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPhpVersion
‪getPhpVersion()
Definition: SystemInformationToolbarItem.php:262
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: SystemInformationToolbarItem.php:67
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\checkAccess
‪bool checkAccess()
Definition: SystemInformationToolbarItem.php:139
‪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:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:49
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDropDown
‪string getDropDown()
Definition: SystemInformationToolbarItem.php:159
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_NOTICE
‪const STATUS_NOTICE
Definition: InformationStatus.php:30
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getComposerMode
‪getComposerMode()
Definition: SystemInformationToolbarItem.php:313
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getLanguageService
‪LanguageService null getLanguageService()
Definition: SystemInformationToolbarItem.php:424