‪TYPO3CMS  9.5
SystemInformationToolbarItem.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 
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 ‪$signalSlotDispatcher;
73 
77  protected ‪$maximumCountInBadge = 99;
78 
82  public function ‪__construct()
83  {
84  $this->‪getPageRenderer()->‪loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/SystemInformationMenu');
86  }
87 
98  public function ‪addSystemMessage($text, $status = ‪InformationStatus::STATUS_OK, $count = 0, $module = '', $params = '')
99  {
100  $this->totalCount += (int)$count;
101 
103  $messageSeverity = ‪InformationStatus::cast($status);
104  // define the severity for the badge
105  if ($messageSeverity->isGreaterThan($this->highestSeverity)) {
106  $this->highestSeverity = $messageSeverity;
107  }
108 
109  $this->systemMessages[] = [
110  'module' => $module,
111  'params' => $params,
112  'count' => (int)$count,
113  'status' => $messageSeverity,
114  'text' => $text
115  ];
116  }
117 
127  public function ‪addSystemInformation($title, $value, $iconIdentifier, $status = ‪InformationStatus::STATUS_NOTICE)
128  {
129  $this->systemInformation[] = [
130  'title' => $title,
131  'value' => $value,
132  'iconIdentifier' => $iconIdentifier,
133  'status' => $status
134  ];
135  }
136 
142  public function ‪checkAccess()
143  {
144  return $this->‪getBackendUserAuthentication()->‪isAdmin();
145  }
146 
152  public function ‪getItem()
153  {
154  return $this->‪getFluidTemplateObject('SystemInformationToolbarItem.html')->‪render();
155  }
156 
162  public function ‪getDropDown()
163  {
164  if (!$this->‪checkAccess()) {
165  return '';
166  }
167 
168  $this->‪collectInformation();
169 
170  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
171  $view = $this->‪getFluidTemplateObject('SystemInformationDropDown.html');
172 
173  try {
174  $environmentToolUrl = (string)$uriBuilder->buildUriFromRoute('tools_toolsenvironment');
175  } catch (RouteNotFoundException $e) {
176  $environmentToolUrl = '';
177  }
178 
179  $view->assignMultiple([
180  'environmentToolUrl' => $environmentToolUrl,
181  'messages' => $this->systemMessages,
182  'count' => $this->totalCount > $this->maximumCountInBadge ? $this->maximumCountInBadge . '+' : $this->totalCount,
183  'severityBadgeClass' => $this->severityBadgeClass,
184  'systemInformation' => $this->systemInformation
185  ]);
186  return $view->render();
187  }
188 
194  public function ‪getAdditionalAttributes()
195  {
196  return [];
197  }
198 
204  public function ‪hasDropDown()
205  {
206  return true;
207  }
208 
214  public function ‪getIndex()
215  {
216  return 75;
217  }
218 
222  protected function ‪collectInformation()
223  {
224  $this->‪getTypo3Version();
225  $this->‪getWebServer();
226  $this->‪getPhpVersion();
227  $this->‪getDatabase();
228  $this->‪getApplicationContext();
229  $this->‪getComposerMode();
230  $this->‪getGitRevision();
231  $this->‪getOperatingSystem();
232 
234  $this->‪emitLoadMessages();
235 
236  $this->severityBadgeClass = !$this->highestSeverity->equals(‪InformationStatus::STATUS_NOTICE) ? 'badge-' . (string)$this->highestSeverity : '';
237  }
238 
242  protected function ‪getTypo3Version()
243  {
244  $this->systemInformation[] = [
245  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.typo3-version',
247  'iconIdentifier' => 'information-typo3-version'
248  ];
249  }
250 
254  protected function ‪getWebServer()
255  {
256  $this->systemInformation[] = [
257  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.webserver',
258  'value' => $_SERVER['SERVER_SOFTWARE'],
259  'iconIdentifier' => 'information-webserver'
260  ];
261  }
262 
266  protected function ‪getPhpVersion()
267  {
268  $this->systemInformation[] = [
269  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.phpversion',
270  'value' => PHP_VERSION,
271  'iconIdentifier' => 'information-php-version'
272  ];
273  }
274 
278  protected function ‪getDatabase()
279  {
280  foreach (GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionNames() as $connectionName) {
281  $this->systemInformation[] = [
282  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.database',
283  'titleAddition' => $connectionName,
284  'value' => GeneralUtility::makeInstance(ConnectionPool::class)
285  ->getConnectionByName($connectionName)
286  ->getServerVersion(),
287  'iconIdentifier' => 'information-database'
288  ];
289  }
290  }
291 
295  protected function ‪getApplicationContext()
296  {
297  $applicationContext = GeneralUtility::getApplicationContext();
298  $this->systemInformation[] = [
299  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.applicationcontext',
300  'value' => (string)$applicationContext,
301  'status' => $applicationContext->isProduction() ? ‪InformationStatus::STATUS_OK : ‪InformationStatus::STATUS_WARNING,
302  'iconIdentifier' => 'information-application-context'
303  ];
304  }
305 
309  protected function ‪getComposerMode()
310  {
312  return;
313  }
314 
315  $this->systemInformation[] = [
316  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.composerMode',
317  'value' => ‪$GLOBALS['LANG']->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.enabled'),
318  'iconIdentifier' => 'information-composer-mode'
319  ];
320  }
321 
325  protected function ‪getGitRevision()
326  {
327  if (!‪StringUtility::endsWith(TYPO3_version, '-dev') || ‪SystemEnvironmentBuilder::isFunctionDisabled('exec')) {
328  return;
329  }
330  // check if git exists
331  ‪CommandUtility::exec('git --version', $_, $returnCode);
332  if ((int)$returnCode !== 0) {
333  // git is not available
334  return;
335  }
336 
337  $revision = trim(‪CommandUtility::exec('git rev-parse --short HEAD'));
338  $branch = trim(‪CommandUtility::exec('git rev-parse --abbrev-ref HEAD'));
339  if (!empty($revision) && !empty($branch)) {
340  $this->systemInformation[] = [
341  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.gitrevision',
342  'value' => sprintf('%s [%s]', $revision, $branch),
343  'iconIdentifier' => 'information-git'
344  ];
345  }
346  }
347 
351  protected function ‪getOperatingSystem()
352  {
353  switch (PHP_OS_FAMILY) {
354  case 'Linux':
355  $icon = 'linux';
356  break;
357  case 'Darwin':
358  $icon = 'apple';
359  break;
360  case 'Windows':
361  $icon = 'windows';
362  break;
363  default:
364  $icon = 'unknown';
365  }
366  $this->systemInformation[] = [
367  'title' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:toolbarItems.sysinfo.operatingsystem',
368  'value' => PHP_OS . ' ' . php_uname('r'),
369  'iconIdentifier' => 'information-os-' . $icon
370  ];
371  }
372 
376  protected function ‪emitGetSystemInformation()
377  {
378  $this->‪getSignalSlotDispatcher()->‪dispatch(__CLASS__, 'getSystemInformation', [$this]);
379  }
380 
384  protected function ‪emitLoadMessages()
385  {
386  $this->‪getSignalSlotDispatcher()->‪dispatch(__CLASS__, 'loadMessages', [$this]);
387  }
388 
395  protected function ‪getFluidTemplateObject(string $filename): ‪StandaloneView
396  {
397  $view = GeneralUtility::makeInstance(StandaloneView::class);
398  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
399  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']);
400  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ToolbarItems']);
401 
402  $view->setTemplate($filename);
403 
404  $view->getRequest()->setControllerExtensionName('Backend');
405  return $view;
406  }
407 
413  protected function ‪getBackendUserAuthentication()
414  {
415  return ‪$GLOBALS['BE_USER'];
416  }
417 
423  protected function ‪getPageRenderer()
424  {
425  return GeneralUtility::makeInstance(PageRenderer::class);
426  }
427 
433  protected function ‪getSignalSlotDispatcher()
434  {
435  if (!isset($this->signalSlotDispatcher)) {
436  $this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class);
437  }
439  }
440 }
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_INFO
‪const STATUS_INFO
Definition: InformationStatus.php:34
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:21
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$highestSeverity
‪InformationStatus $highestSeverity
Definition: SystemInformationToolbarItem.php:48
‪TYPO3\CMS\Backend\Toolbar\ToolbarItemInterface
Definition: ToolbarItemInterface.php:24
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getItem
‪string getItem()
Definition: SystemInformationToolbarItem.php:145
‪TYPO3\CMS\Core\Utility\StringUtility\endsWith
‪static bool endsWith($haystack, $needle)
Definition: StringUtility.php:60
‪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:207
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getWebServer
‪getWebServer()
Definition: SystemInformationToolbarItem.php:247
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getApplicationContext
‪getApplicationContext()
Definition: SystemInformationToolbarItem.php:288
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:294
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\emitLoadMessages
‪emitLoadMessages()
Definition: SystemInformationToolbarItem.php:377
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\isFunctionDisabled
‪static bool isFunctionDisabled($function)
Definition: SystemEnvironmentBuilder.php:494
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getOperatingSystem
‪getOperatingSystem()
Definition: SystemInformationToolbarItem.php:344
‪TYPO3\CMS\Core\Routing\RouteNotFoundException
Definition: RouteNotFoundException.php:23
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_OK
‪const STATUS_OK
Definition: InformationStatus.php:39
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemMessages
‪array $systemMessages
Definition: SystemInformationToolbarItem.php:62
‪TYPO3\CMS\Core\Page\PageRenderer\loadRequireJsModule
‪loadRequireJsModule($mainModuleName, $callBackFunction=null)
Definition: PageRenderer.php:1593
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$severityBadgeClass
‪string $severityBadgeClass
Definition: SystemInformationToolbarItem.php:54
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\emitGetSystemInformation
‪emitGetSystemInformation()
Definition: SystemInformationToolbarItem.php:369
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getCurrentTypo3Version
‪static string getCurrentTypo3Version()
Definition: VersionNumberUtility.php:114
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_WARNING
‪const STATUS_WARNING
Definition: InformationStatus.php:44
‪TYPO3\CMS\Core\Utility\CommandUtility\exec
‪static string exec($command, &$output=null, &$returnValue=0)
Definition: CommandUtility.php:80
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDatabase
‪getDatabase()
Definition: SystemInformationToolbarItem.php:271
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\collectInformation
‪collectInformation()
Definition: SystemInformationToolbarItem.php:215
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\Backend\ToolbarItems
Definition: ClearCacheToolbarItem.php:2
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getSignalSlotDispatcher
‪Dispatcher getSignalSlotDispatcher()
Definition: SystemInformationToolbarItem.php:426
‪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:406
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem
Definition: SystemInformationToolbarItem.php:37
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getGitRevision
‪getGitRevision()
Definition: SystemInformationToolbarItem.php:318
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getTypo3Version
‪getTypo3Version()
Definition: SystemInformationToolbarItem.php:235
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $filename)
Definition: SystemInformationToolbarItem.php:388
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\hasDropDown
‪bool hasDropDown()
Definition: SystemInformationToolbarItem.php:197
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$systemInformation
‪array $systemInformation
Definition: SystemInformationToolbarItem.php:58
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher\dispatch
‪mixed dispatch($signalClassName, $signalName, array $signalArguments=[])
Definition: Dispatcher.php:115
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus
Definition: InformationStatus.php:23
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemInformation
‪addSystemInformation($title, $value, $iconIdentifier, $status=InformationStatus::STATUS_NOTICE)
Definition: SystemInformationToolbarItem.php:120
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:117
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getAdditionalAttributes
‪array getAdditionalAttributes()
Definition: SystemInformationToolbarItem.php:187
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\addSystemMessage
‪addSystemMessage($text, $status=InformationStatus::STATUS_OK, $count=0, $module='', $params='')
Definition: SystemInformationToolbarItem.php:91
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extbase\Mvc\View\ViewInterface\render
‪string render()
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPageRenderer
‪PageRenderer getPageRenderer()
Definition: SystemInformationToolbarItem.php:416
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getPhpVersion
‪getPhpVersion()
Definition: SystemInformationToolbarItem.php:259
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\checkAccess
‪bool checkAccess()
Definition: SystemInformationToolbarItem.php:135
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:21
‪TYPO3\CMS\Core\Utility\CommandUtility
Definition: CommandUtility.php:48
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getDropDown
‪string getDropDown()
Definition: SystemInformationToolbarItem.php:155
‪TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus\STATUS_NOTICE
‪const STATUS_NOTICE
Definition: InformationStatus.php:29
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\$signalSlotDispatcher
‪Dispatcher $signalSlotDispatcher
Definition: SystemInformationToolbarItem.php:66
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\__construct
‪__construct()
Definition: SystemInformationToolbarItem.php:75
‪TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem\getComposerMode
‪getComposerMode()
Definition: SystemInformationToolbarItem.php:302
‪TYPO3\CMS\Extbase\SignalSlot\Dispatcher
Definition: Dispatcher.php:28