[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Report / Status / SystemStatus.php
1 <?php
2 namespace TYPO3\CMS\Reports\Report\Status;
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 /**
17 * Performs several checks about the system's health
18 *
19 * @author Ingo Renner <ingo@typo3.org>
20 */
21 class SystemStatus implements \TYPO3\CMS\Reports\StatusProviderInterface {
22
23 /**
24 * Determines the Install Tool's status, mainly concerning its protection.
25 *
26 * @return array List of statuses
27 */
28 public function getStatus() {
29 $this->executeAdminCommand();
30 $statuses = array(
31 'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(),
32 'PhpModules' => $this->getMissingPhpModulesOfExtensions()
33 );
34 return $statuses;
35 }
36
37 /**
38 * Executes commands like clearing the memory status flag
39 *
40 * @return void
41 */
42 protected function executeAdminCommand() {
43 $command = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('adminCmd');
44 switch ($command) {
45 case 'clear_peak_memory_usage_flag':
46 /** @var $registry \TYPO3\CMS\Core\Registry */
47 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
48 $registry->remove('core', 'reports-peakMemoryUsage');
49 break;
50 default:
51 // Do nothing
52 }
53 }
54
55 /**
56 * Checks if there was a request in the past which approached the memory limit
57 *
58 * @return \TYPO3\CMS\Reports\Status A status of whether the memory limit was approached by one of the requests
59 */
60 protected function getPhpPeakMemoryStatus() {
61 /** @var $registry \TYPO3\CMS\Core\Registry */
62 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
63 $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage');
64 $memoryLimit = \TYPO3\CMS\Core\Utility\GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
65 $value = $GLOBALS['LANG']->getLL('status_ok');
66 $message = '';
67 $severity = \TYPO3\CMS\Reports\Status::OK;
68 $bytesUsed = $peakMemoryUsage['used'];
69 $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?';
70 $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']);
71 $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>';
72 $clearFlagUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&amp;adminCmd=clear_peak_memory_usage_flag';
73 if ($peakMemoryUsage['used']) {
74 $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);
75 $message .= ' <a href="' . $clearFlagUrl . '">' . $GLOBALS['LANG']->getLL('status_phpPeakMemoryClearFlag') . '</a>.';
76 $severity = \TYPO3\CMS\Reports\Status::WARNING;
77 $value = $percentageUsed;
78 }
79 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpPeakMemory'), $value, $message, $severity);
80 }
81
82 /**
83 * Reports whether extensions need additional PHP modules different from standard core requirements
84 *
85 * @return \TYPO3\CMS\Reports\Status A status of missing PHP modules
86 */
87 protected function getMissingPhpModulesOfExtensions() {
88 $modules = array();
89 if (is_array(${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']})) {
90 foreach (${$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['requiredPhpModules']} as $classData) {
91 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
92 $modules = $hookObject->setRequiredPhpModules($modules, $this);
93 }
94 }
95 $missingPhpModules = array();
96 foreach ($modules as $module) {
97 if (is_array($module)) {
98 $detectedSubmodules = FALSE;
99 foreach ($module as $submodule) {
100 if (extension_loaded($submodule)) {
101 $detectedSubmodules = TRUE;
102 }
103 }
104 if ($detectedSubmodules === FALSE) {
105 $missingPhpModules[] = sprintf($GLOBALS['LANG']->getLL('status_phpModulesGroup'), '(' . implode(', ', $module) . ')');
106 }
107 } elseif (!extension_loaded($module)) {
108 $missingPhpModules[] = $module;
109 }
110 }
111 if (count($missingPhpModules) > 0) {
112 $value = $GLOBALS['LANG']->getLL('status_phpModulesMissing');
113 $message = sprintf($GLOBALS['LANG']->getLL('status_phpModulesList'), implode(', ', $missingPhpModules));
114 $message .= ' ' . $GLOBALS['LANG']->getLL('status_phpModulesInfo');
115 $severity = \TYPO3\CMS\Reports\Status::ERROR;
116 } else {
117 $value = $GLOBALS['LANG']->getLL('status_phpModulesPresent');
118 $message = '';
119 $severity = \TYPO3\CMS\Reports\Status::OK;
120 }
121 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_phpModules'), $value, $message, $severity);
122 }
123
124 }