[TASK] Deprecate TSFE constructor with no_cache parameter 34/58034/3
authorBenni Mack <benni@typo3.org>
Fri, 24 Aug 2018 22:30:16 +0000 (00:30 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Tue, 28 Aug 2018 11:53:43 +0000 (13:53 +0200)
Instantiating TypoScriptFrontendController with the fourth
parameter set (except null) will now trigger a deprecation
message, as it is recommended to use the method `set_no_cache`
instead.

Resolves: #86002
Releases: master
Change-Id: I6d8bbdd79d6b6169d358b5d17b036006d3c3205e
Reviewed-on: https://review.typo3.org/58034
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Gorges <daniel.gorges@b13.de>
Tested-by: Daniel Gorges <daniel.gorges@b13.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-86002-TSFEConstructorWithNo_cacheArgument.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Classes/Middleware/TypoScriptFrontendInitialization.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodArgumentUnusedMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86002-TSFEConstructorWithNo_cacheArgument.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86002-TSFEConstructorWithNo_cacheArgument.rst
new file mode 100644 (file)
index 0000000..5c96ad0
--- /dev/null
@@ -0,0 +1,36 @@
+.. include:: ../../Includes.txt
+
+=============================================================
+Deprecation: #86002 - TSFE constructor with no_cache argument
+=============================================================
+
+See :issue:`86002`
+
+Description
+===========
+
+The fourth constructor argument of the PHP class :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController`
+(a.k.a. "TSFE") was previously used to determine if the GET/POST parameter "no_cache" was set, which is
+moved to a PSR-15 middleware now, making the argument obsolete. This argument is now set to "null" by default.
+
+
+Impact
+======
+
+If anything other than the null value is given to the constructor method, a deprecation message is thrown.
+
+
+Affected Installations
+======================
+
+TYPO3 installations with extensions that instantiate the PHP class manually and setting the fourth
+constructor argument.
+
+
+Migration
+=========
+
+Set the constructor argument to "null" when instantiating the class manually, use `$tsfe->set_no_cache()` instead
+to manually disable the caching mechanism.
+
+.. index:: Frontend, PHP-API, FullyScanned
\ No newline at end of file
index d1897c1..7a90527 100644 (file)
@@ -807,27 +807,29 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      * @param array $_ unused, previously defined to set TYPO3_CONF_VARS
      * @param mixed $id The value of GeneralUtility::_GP('id')
      * @param int $type The value of GeneralUtility::_GP('type')
-     * @param bool|string $no_cache The value of GeneralUtility::_GP('no_cache'), evaluated to 1/0
+     * @param bool|string $no_cache The value of GeneralUtility::_GP('no_cache'), evaluated to 1/0, will be unused in TYPO3 v10.0.
      * @param string $cHash The value of GeneralUtility::_GP('cHash')
      * @param string $_2 previously was used to define the jumpURL
      * @param string $MP The value of GeneralUtility::_GP('MP')
-     * @see \TYPO3\CMS\Frontend\Http\RequestHandler
      */
-    public function __construct($_ = null, $id, $type, $no_cache = '', $cHash = '', $_2 = null, $MP = '')
+    public function __construct($_ = null, $id, $type, $no_cache = null, $cHash = '', $_2 = null, $MP = '')
     {
         // Setting some variables:
         $this->id = $id;
         $this->type = $type;
-        if ($no_cache) {
-            if ($GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter']) {
-                $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
-                $this->getTimeTracker()->setTSlogMessage($warning, 2);
-            } else {
-                $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
-                $this->disableCache();
+        if ($no_cache !== null) {
+            trigger_error('Calling TypoScriptFrontendController->__construct() with $no_cache argument set will be removed in TYPO3 v10.0. Use ->set_no_cache() instead.', E_USER_DEPRECATED);
+            if ($no_cache) {
+                if ($GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter']) {
+                    $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
+                    $this->getTimeTracker()->setTSlogMessage($warning, 2);
+                } else {
+                    $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
+                    $this->disableCache();
+                }
+                // note: we need to instantiate the logger manually here since the injection happens after the constructor
+                GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__)->warning($warning);
             }
-            // note: we need to instantiate the logger manually here since the injection happens after the constructor
-            GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__)->warning($warning);
         }
         $this->cHash = $cHash;
         $this->MP = $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] ? (string)$MP : '';
@@ -4350,7 +4352,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
             $warning .= ' Caching is disabled!';
             $this->disableCache();
         }
-        if ($internal && isset($GLOBALS['BE_USER'])) {
+        if ($internal && $this->isBackendUserLoggedIn()) {
             $this->logger->notice($warning);
         } else {
             $this->logger->warning($warning);
index 0838cec..503d4ee 100644 (file)
@@ -56,11 +56,14 @@ class TypoScriptFrontendInitialization implements MiddlewareInterface, LoggerAwa
             null,
             GeneralUtility::_GP('id'),
             GeneralUtility::_GP('type'),
-            GeneralUtility::_GP('no_cache'),
+            null,
             GeneralUtility::_GP('cHash'),
             null,
             GeneralUtility::_GP('MP')
         );
+        if (GeneralUtility::_GP('no_cache')) {
+            $GLOBALS['TSFE']->set_no_cache('&no_cache=1 has been supplied, so caching is disabled! URL: "' . (string)$request->getUri() . '"');
+        }
 
         // Set up the database connection and see if the connection can be established
         try {
index e3762fd..ae76a16 100644 (file)
@@ -33,4 +33,10 @@ return [
             'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
         ],
     ],
+    'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->__construct' => [
+        'unusedArgumentNumbers' => [ 4 ],
+        'restFiles' => [
+            'Deprecation-86002-TSFEConstructorWithNo_cacheArgument.rst',
+        ],
+    ],
 ];