diff --git a/typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php b/typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php new file mode 100644 index 0000000000000000000000000000000000000000..2278f20ffa36b13b288121c8659d77673a92327e --- /dev/null +++ b/typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php @@ -0,0 +1,96 @@ +<?php +namespace TYPO3\CMS\Compatibility7\Report\Status; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Core\Registry; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Lang\LanguageService; +use TYPO3\CMS\Reports\Status as ReportStatus; +use TYPO3\CMS\Reports\StatusProviderInterface; + +/** + * Adds peak memory stats from frontend call. + */ +class SystemStatus implements StatusProviderInterface +{ + /** + * Main API method + * + * @return array List of statuses + */ + public function getStatus() + { + $this->executeAdminCommand(); + $statuses = [ + 'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(), + ]; + return $statuses; + } + + /** + * Executes commands like clearing the memory status flag + * + * @return void + */ + protected function executeAdminCommand() + { + $command = GeneralUtility::_GET('adminCmd'); + switch ($command) { + case 'clear_peak_memory_usage_flag': + /** @var Registry $registry */ + $registry = GeneralUtility::makeInstance(Registry::class); + $registry->remove('core', 'reports-peakMemoryUsage'); + break; + default: + // Do nothing + } + } + + /** + * Checks if there was a request in the past which approached the memory limit + * + * @return \TYPO3\CMS\Reports\Status A status of whether the memory limit was approached by one of the requests + */ + protected function getPhpPeakMemoryStatus() + { + /** @var Registry $registry */ + $registry = GeneralUtility::makeInstance(Registry::class); + $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage'); + $memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit')); + $value = $this->getLanguageService()->getLL('status_ok'); + $message = ''; + $severity = ReportStatus::OK; + $bytesUsed = $peakMemoryUsage['used']; + $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?'; + $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']); + $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>'; + $clearFlagUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&adminCmd=clear_peak_memory_usage_flag'; + if ($peakMemoryUsage['used']) { + $message = sprintf($this->getLanguageService()->getLL('status_phpPeakMemoryTooHigh'), GeneralUtility::formatSize($peakMemoryUsage['used']), $percentageUsed, GeneralUtility::formatSize($memoryLimit), $dateOfPeak, $urlOfPeak); + $message .= ' <a href="' . $clearFlagUrl . '">' . $this->getLanguageService()->getLL('status_phpPeakMemoryClearFlag') . '</a>.'; + $severity = ReportStatus::WARNING; + $value = $percentageUsed; + } + return GeneralUtility::makeInstance(ReportStatus::class, $this->getLanguageService()->getLL('status_phpPeakMemory'), $value, $message, $severity); + } + + /** + * @return LanguageService + */ + protected function getLanguageService() + { + return $GLOBALS['LANG']; + } +} diff --git a/typo3/sysext/core/Classes/Utility/MonitorUtility.php b/typo3/sysext/compatibility7/Classes/Utility/MonitorUtility.php similarity index 83% rename from typo3/sysext/core/Classes/Utility/MonitorUtility.php rename to typo3/sysext/compatibility7/Classes/Utility/MonitorUtility.php index 2ee1b1e74e4840fe3265c1678075e3fa6c826493..57965ebf43b70506e0c274309ecff6773ab0f8fe 100644 --- a/typo3/sysext/core/Classes/Utility/MonitorUtility.php +++ b/typo3/sysext/compatibility7/Classes/Utility/MonitorUtility.php @@ -1,5 +1,5 @@ <?php -namespace TYPO3\CMS\Core\Utility; +namespace TYPO3\CMS\Compatibility7\Utility; /* * This file is part of the TYPO3 CMS project. @@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Utility; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; + /** * Class to handle monitoring actions. */ @@ -41,4 +43,14 @@ class MonitorUtility } } } + + /** + * Hook called by TypoScriptFrontendController + * + * @return void + */ + public function monitorUtilityFrontendHook() + { + self::peakMemoryUsage(); + } } diff --git a/typo3/sysext/compatibility7/Migrations/Code/ClassAliasMap.php b/typo3/sysext/compatibility7/Migrations/Code/ClassAliasMap.php index c31620c31a31bb6e65d4cc13e4a1c203210a46c9..410b5a3cc72a6c98db0f01e250ea12c4c5c8508b 100644 --- a/typo3/sysext/compatibility7/Migrations/Code/ClassAliasMap.php +++ b/typo3/sysext/compatibility7/Migrations/Code/ClassAliasMap.php @@ -1,5 +1,6 @@ <?php return [ + 'TYPO3\\CMS\\Core\\Utility\\MonitorUtility' => \TYPO3\CMS\Compatibility7\Utility\MonitorUtility::class, 'TYPO3\\CMS\\IndexedSearch\\Controller\\SearchFormController' => \TYPO3\CMS\Compatibility7\Controller\SearchFormController::class, 'TYPO3\\CMS\\Version\\ContextMenu\\ItemProvider' => \TYPO3\CMS\Compatibility7\ContextMenu\ItemProvider::class, 'TYPO3\\CMS\\Version\\Controller\\VersionModuleController' => \TYPO3\CMS\Compatibility7\Controller\VersionModuleController::class, diff --git a/typo3/sysext/compatibility7/ext_localconf.php b/typo3/sysext/compatibility7/ext_localconf.php index e2603a8b1b0e37f126e49950b2b3224cd53b6eff..78f1c96b2336a8cc2c0a30ea9065635a4551d86d 100644 --- a/typo3/sysext/compatibility7/ext_localconf.php +++ b/typo3/sysext/compatibility7/ext_localconf.php @@ -105,3 +105,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLa // Enable TypoScript functionality config.beLoginLinkIPList $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']['compatibility7_backendloginlink'] = \TYPO3\CMS\Compatibility7\Hooks\BackendLoginLinkHook::class . '->renderBackendLoginLink'; + +// Call MonitorUtility peakMemoryUsage +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']['compatibility7_monitorutility'] + = \TYPO3\CMS\Compatibility7\Utility\MonitorUtility::class . '->monitorUtilityFrontendHook'; diff --git a/typo3/sysext/compatibility7/ext_tables.php b/typo3/sysext/compatibility7/ext_tables.php index 5536a4dbb39c1a1d21867161a4c3e6caceccc1cc..d6404b1189f1aac7a091bd016589ede2b3736294 100644 --- a/typo3/sysext/compatibility7/ext_tables.php +++ b/typo3/sysext/compatibility7/ext_tables.php @@ -11,4 +11,6 @@ if (TYPO3_MODE === 'BE') { !\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) { $GLOBALS['TYPO3_CONF_VARS']['BE']['ContextMenu']['ItemProviders'][1486418676] = \TYPO3\CMS\Compatibility7\ContextMenu\ItemProvider::class; } + + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['reports']['tx_reports']['status']['providers']['system'][] = \TYPO3\CMS\Compatibility7\Report\Status\SystemStatus::class; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-80450-MonitorUtilityMovedToCompatibility.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-80450-MonitorUtilityMovedToCompatibility.rst new file mode 100644 index 0000000000000000000000000000000000000000..6f792ce7140ae3d2d9b1d817db4fa22696f8f7f8 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Important-80450-MonitorUtilityMovedToCompatibility.rst @@ -0,0 +1,16 @@ +.. include:: ../../Includes.txt + +====================================================== +Important: #80450 - MonitorUtilityMovedToCompatibility +====================================================== + +See :issue:`80450` + +Description +=========== + +The "peak memory measurement" in the frontend has been moved to extension compatiblity7. The functionality +is semi useful and should live a happy life in an extension for people who may need it, but there is no need +to have that within the core on each frontend call. + +.. index:: Backend, Frontend, PHP-API \ No newline at end of file diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index ef30c09a7f05e1744df252d2aab83a717fdfc865..59a53c52e2705c232de39aba07d36f52e3cbecce 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -21,7 +21,6 @@ use TYPO3\CMS\Core\Http\RequestHandlerInterface; use TYPO3\CMS\Core\TimeTracker\TimeTracker; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; -use TYPO3\CMS\Core\Utility\MonitorUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Page\PageGenerator; use TYPO3\CMS\Frontend\Utility\CompressionUtility; @@ -255,8 +254,6 @@ class RequestHandler implements RequestHandlerInterface $this->controller->hook_eofe(); // Finish timetracking $this->timeTracker->pull(); - // Check memory usage - MonitorUtility::peakMemoryUsage(); // Admin panel if ($this->controller->isBackendUserLoggedIn() && $GLOBALS['BE_USER'] instanceof FrontendBackendUserAuthentication) { diff --git a/typo3/sysext/reports/Classes/Report/Status/SystemStatus.php b/typo3/sysext/reports/Classes/Report/Status/SystemStatus.php index 9c5a1deb55ce68ef354f9e7fa8c31f7796c20d42..d95f11def0a52e203c5516ebc6742c69b60c6924 100644 --- a/typo3/sysext/reports/Classes/Report/Status/SystemStatus.php +++ b/typo3/sysext/reports/Classes/Report/Status/SystemStatus.php @@ -13,7 +13,7 @@ namespace TYPO3\CMS\Reports\Report\Status; * * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\Registry; + use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Lang\LanguageService; use TYPO3\CMS\Reports\Status as ReportStatus; @@ -31,61 +31,12 @@ class SystemStatus implements StatusProviderInterface */ public function getStatus() { - $this->executeAdminCommand(); $statuses = [ - 'PhpPeakMemory' => $this->getPhpPeakMemoryStatus(), 'PhpModules' => $this->getMissingPhpModulesOfExtensions() ]; return $statuses; } - /** - * Executes commands like clearing the memory status flag - * - * @return void - */ - protected function executeAdminCommand() - { - $command = GeneralUtility::_GET('adminCmd'); - switch ($command) { - case 'clear_peak_memory_usage_flag': - /** @var Registry $registry */ - $registry = GeneralUtility::makeInstance(Registry::class); - $registry->remove('core', 'reports-peakMemoryUsage'); - break; - default: - // Do nothing - } - } - - /** - * Checks if there was a request in the past which approached the memory limit - * - * @return \TYPO3\CMS\Reports\Status A status of whether the memory limit was approached by one of the requests - */ - protected function getPhpPeakMemoryStatus() - { - /** @var Registry $registry */ - $registry = GeneralUtility::makeInstance(Registry::class); - $peakMemoryUsage = $registry->get('core', 'reports-peakMemoryUsage'); - $memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit')); - $value = $this->getLanguageService()->getLL('status_ok'); - $message = ''; - $severity = ReportStatus::OK; - $bytesUsed = $peakMemoryUsage['used']; - $percentageUsed = $memoryLimit ? number_format($bytesUsed / $memoryLimit * 100, 1) . '%' : '?'; - $dateOfPeak = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $peakMemoryUsage['tstamp']); - $urlOfPeak = '<a href="' . htmlspecialchars($peakMemoryUsage['url']) . '">' . htmlspecialchars($peakMemoryUsage['url']) . '</a>'; - $clearFlagUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '&adminCmd=clear_peak_memory_usage_flag'; - if ($peakMemoryUsage['used']) { - $message = sprintf($this->getLanguageService()->getLL('status_phpPeakMemoryTooHigh'), GeneralUtility::formatSize($peakMemoryUsage['used']), $percentageUsed, GeneralUtility::formatSize($memoryLimit), $dateOfPeak, $urlOfPeak); - $message .= ' <a href="' . $clearFlagUrl . '">' . $this->getLanguageService()->getLL('status_phpPeakMemoryClearFlag') . '</a>.'; - $severity = ReportStatus::WARNING; - $value = $percentageUsed; - } - return GeneralUtility::makeInstance(ReportStatus::class, $this->getLanguageService()->getLL('status_phpPeakMemory'), $value, $message, $severity); - } - /** * Reports whether extensions need additional PHP modules different from standard core requirements *