[TASK] Move MonitorUtility to compatiblity7 64/52164/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 25 Mar 2017 23:09:16 +0000 (00:09 +0100)
committerBenni Mack <benni@typo3.org>
Sat, 25 Mar 2017 23:53:30 +0000 (00:53 +0100)
Move the MonitorUtility to ext:compatibility7, implement the static call
as eofe hook and move the reports system status to compat7, too.

Change-Id: I152a726d9d47e9a1f38dc2416384551727bbcc88
Resolves: #80450
Releases: master
Reviewed-on: https://review.typo3.org/52164
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php [new file with mode: 0644]
typo3/sysext/compatibility7/Classes/Utility/MonitorUtility.php [new file with mode: 0644]
typo3/sysext/compatibility7/Migrations/Code/ClassAliasMap.php
typo3/sysext/compatibility7/ext_localconf.php
typo3/sysext/compatibility7/ext_tables.php
typo3/sysext/core/Classes/Utility/MonitorUtility.php [deleted file]
typo3/sysext/core/Documentation/Changelog/master/Important-80450-MonitorUtilityMovedToCompatibility.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Http/RequestHandler.php
typo3/sysext/reports/Classes/Report/Status/SystemStatus.php

diff --git a/typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php b/typo3/sysext/compatibility7/Classes/Report/Status/SystemStatus.php
new file mode 100644 (file)
index 0000000..2278f20
--- /dev/null
@@ -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') . '&amp;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/compatibility7/Classes/Utility/MonitorUtility.php b/typo3/sysext/compatibility7/Classes/Utility/MonitorUtility.php
new file mode 100644 (file)
index 0000000..57965eb
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+namespace TYPO3\CMS\Compatibility7\Utility;
+
+/*
+ * 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\Utility\GeneralUtility;
+
+/**
+ * Class to handle monitoring actions.
+ */
+class MonitorUtility
+{
+    /**
+     * Checks peak memory usage and stores data in cache for use in the report module
+     *
+     * @return void
+     */
+    public static function peakMemoryUsage()
+    {
+        $peakUsage = memory_get_peak_usage(true);
+        $memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
+        if (is_float($memoryLimit) && $memoryLimit != 0) {
+            if ($peakUsage / $memoryLimit >= 0.9) {
+                /** @var $registry \TYPO3\CMS\Core\Registry */
+                $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
+                $data = [
+                    'used' => $peakUsage,
+                    'tstamp' => $GLOBALS['EXEC_TIME'],
+                    'url' => GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')
+                ];
+                $registry->set('core', 'reports-peakMemoryUsage', $data);
+            }
+        }
+    }
+
+    /**
+     * Hook called by TypoScriptFrontendController
+     *
+     * @return void
+     */
+    public function monitorUtilityFrontendHook()
+    {
+        self::peakMemoryUsage();
+    }
+}
index c31620c..410b5a3 100644 (file)
@@ -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,
index e2603a8..78f1c96 100644 (file)
@@ -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';
index 5536a4d..d6404b1 100644 (file)
@@ -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/Classes/Utility/MonitorUtility.php b/typo3/sysext/core/Classes/Utility/MonitorUtility.php
deleted file mode 100644 (file)
index 2ee1b1e..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Utility;
-
-/*
- * 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!
- */
-
-/**
- * Class to handle monitoring actions.
- */
-class MonitorUtility
-{
-    /**
-     * Checks peak memory usage and stores data in cache for use in the report module
-     *
-     * @return void
-     */
-    public static function peakMemoryUsage()
-    {
-        $peakUsage = memory_get_peak_usage(true);
-        $memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit'));
-        if (is_float($memoryLimit) && $memoryLimit != 0) {
-            if ($peakUsage / $memoryLimit >= 0.9) {
-                /** @var $registry \TYPO3\CMS\Core\Registry */
-                $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
-                $data = [
-                    'used' => $peakUsage,
-                    'tstamp' => $GLOBALS['EXEC_TIME'],
-                    'url' => GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')
-                ];
-                $registry->set('core', 'reports-peakMemoryUsage', $data);
-            }
-        }
-    }
-}
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 (file)
index 0000000..6f792ce
--- /dev/null
@@ -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
index ef30c09..59a53c5 100644 (file)
@@ -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) {
index 9c5a1de..d95f11d 100644 (file)
@@ -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,62 +31,13 @@ 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') . '&amp;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
      *
      * @return \TYPO3\CMS\Reports\Status A status of missing PHP modules