TYPO3 CMS  TYPO3_7-6
SystemStatus.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 
21 {
27  public function getStatus()
28  {
29  $this->executeAdminCommand();
30  $statuses = [
31  'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(),
32  'PhpModules' => $this->getMissingPhpModulesOfExtensions()
33  ];
34  return $statuses;
35  }
36 
42  protected function executeAdminCommand()
43  {
44  $command = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('adminCmd');
45  switch ($command) {
46  case 'clear_peak_memory_usage_flag':
48  $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
49  $registry->remove('core', 'reports-peakMemoryUsage');
50  break;
51  default:
52  // Do nothing
53  }
54  }
55 
61  protected function getPhpPeakMemoryStatus()
62  {
64  $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
65  $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage');
66  $memoryLimit = \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
67  $value = $GLOBALS['LANG']->getLL('status_ok');
68  $message = '';
70  $bytesUsed = $peakMemoryUsage['used'];
71  $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?';
72  $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']);
73  $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>';
74  $clearFlagUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=clear_peak_memory_usage_flag';
75  if ($peakMemoryUsage['used']) {
76  $message = sprintf($GLOBALS['LANG']->getLL('status_phpPeakMemoryTooHigh'), \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($peakMemoryUsage['used']), $percentageUsed, \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($memoryLimit), $dateOfPeak, $urlOfPeak);
77  $message .= ' <a href="' . $clearFlagUrl . '">' . $GLOBALS['LANG']->getLL('status_phpPeakMemoryClearFlag') . '</a>.';
79  $value = $percentageUsed;
80  }
81  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Status::class, $GLOBALS['LANG']->getLL('status_phpPeakMemory'), $value, $message, $severity);
82  }
83 
89  protected function getMissingPhpModulesOfExtensions()
90  {
91  $modules = [];
92  if (is_array(${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']})) {
93  foreach (${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']} as $classData) {
95  $modules = $hookObject->setRequiredPhpModules($modules, $this);
96  }
97  }
98  $missingPhpModules = [];
99  foreach ($modules as $module) {
100  if (is_array($module)) {
101  $detectedSubmodules = false;
102  foreach ($module as $submodule) {
103  if (extension_loaded($submodule)) {
104  $detectedSubmodules = true;
105  }
106  }
107  if ($detectedSubmodules === false) {
108  $missingPhpModules[] = sprintf($GLOBALS['LANG']->getLL('status_phpModulesGroup'), '(' . implode(', ', $module) . ')');
109  }
110  } elseif (!extension_loaded($module)) {
111  $missingPhpModules[] = $module;
112  }
113  }
114  if (!empty($missingPhpModules)) {
115  $value = $GLOBALS['LANG']->getLL('status_phpModulesMissing');
116  $message = sprintf($GLOBALS['LANG']->getLL('status_phpModulesList'), implode(', ', $missingPhpModules));
117  $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpModulesInfo');
119  } else {
120  $value = $GLOBALS['LANG']->getLL('status_phpModulesPresent');
121  $message = '';
122  $severity = \TYPO3\CMS\Reports\Status::OK;
123  }
124  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Status::class, $GLOBALS['LANG']->getLL('status_phpModules'), $value, $message, $severity);
125  }
126 }
static getBytesFromSizeMeasurement($measurement)
static formatSize($sizeInBytes, $labels='', $base=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']