From de39313b55963a2952bac7efb94673ba23afb73d Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Sat, 11 Aug 2018 20:16:17 +0200 Subject: [PATCH] [TASK] Deprecate EidUtility and methods within TSFE EidUtility is a poor-mans middleware functionality with lots of side-effects, and is marked as deprecated. On top, the following methods in TypoScriptFrontendController are deprecated: - initFEuser() - storeSessionData() - previewInfo() - hook_eofe() - addTempContentHttpHeaders() - sendCacheHeaders() Additionally, the PreviewInfo Hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_previewInfo'] is deprecated, as the eofe hook solves the same issues. Resolves: #85878 Releases: master Change-Id: I49cdb8c9c0b3cdf08fa90ce54cc5e570cfd13dce Reviewed-on: https://review.typo3.org/57876 Tested-by: TYPO3com Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn Reviewed-by: Wouter Wolters Tested-by: Wouter Wolters --- ...-85878-EidUtilityAndVariousTSFEMethods.rst | 50 +++++++++++++++++++ .../TypoScriptFrontendController.php | 36 +++++++++++-- .../frontend/Classes/Http/RequestHandler.php | 14 ++++-- .../frontend/Classes/Utility/EidUtility.php | 41 +++++++++++++-- .../Php/ArrayDimensionMatcher.php | 5 ++ .../Php/MethodCallMatcher.php | 36 +++++++++++++ .../Php/MethodCallStaticMatcher.php | 23 ++++++++- 7 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst new file mode 100644 index 000000000000..5d42f6a0fbc9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst @@ -0,0 +1,50 @@ +.. include:: ../../Includes.txt + +========================================================= +Deprecation: #85878 - EidUtility and various TSFE methods +========================================================= + +See :issue:`85878` + +Description +=========== + +The Utility class :php:`TYPO3\CMS\Frontend\Utility\EidUtility` has been marked as deprecated. + +The following methods have been marked as deprecated: +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->initFEuser()` +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->storeSessionData()` +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->previewInfo()` +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->hook_eofe()` +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->addTempContentHttpHeaders()` +* :php:`TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->sendCacheHeaders()` + +The following hook has been deprecated: +`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_previewInfo']` + + +Impact +====== + +Calling any of the methods or registering a hook listener will trigger a deprecation log message. + + +Affected Installations +====================== + +Any TYPO3 installation with custom functionality in the frontend using any of the frontend, or the hook. + + +Migration +========= + +As all functionality has been set up via PSR-15 middlewares, use a PSR-15 middleware instead. + +The methods :php:`addTempContentHttpHeaders()` and :php:`sendCacheHeaders()` are now incorporated +within :php:`TSFE->processOutput()`, this function should be used, or rather add custom headers +to a PSR-15 Response object if available. + +On top, the hook is superseded by the Frontend Hook `hook_eofe` which is executed in the Frontend rendering +flow directly afterwards. + +.. index:: Frontend, PHP-API, FullyScanned, ext:frontend diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index 9a242c967dee..23ab10d8b318 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -922,9 +922,11 @@ protected function initCaches() /** * Initializes the front-end login user. + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use the PSR-15 middleware instead to set up the Frontend User object. */ public function initFEuser() { + trigger_error('TSFE->initFEuser() will be removed in TYPO3 v10.0. Use the FrontendUserAuthenticator middleware instead to initialize a Frontend User object', E_USER_DEPRECATED); $this->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class); // List of pid's acceptable $pid = GeneralUtility::_GP('pid'); @@ -3839,13 +3841,20 @@ public function processOutput() } // Set cache related headers to client (used to enable proxy / client caching!) if (!empty($this->config['config']['sendCacheHeaders'])) { - $this->sendCacheHeaders(); + $headers = $this->getCacheHeaders(); + foreach ($headers as $header => $value) { + header($header . ': ' . $value); + } } // Set headers, if any $this->sendAdditionalHeaders(); // Send appropriate status code in case of temporary content if ($this->tempContent) { - $this->addTempContentHttpHeaders(); + header('HTTP/1.0 503 Service unavailable'); + $headers = $this->getHttpHeadersForTemporaryContent(); + foreach ($headers as $header => $value) { + header($header . ': ' . $value); + } } // Make substitution of eg. username/uid in content only if cache-headers for client/proxy caching is NOT sent! if (!$this->isClientCachable) { @@ -3861,9 +3870,11 @@ public function processOutput() /** * Send cache headers good for client/reverse proxy caching. * @see getCacheHeaders() for more details + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use $TSFE->processOutput to send headers instead. */ public function sendCacheHeaders() { + trigger_error('$TSFE->sendCacheHeaders() will be removed in TYPO3 v10.0, as all headers are compiled within "processOutput" depending on various scenarios. Use $TSFE->processOutput() instead.', E_USER_DEPRECATED); $headers = $this->getCacheHeaders(); foreach ($headers as $header => $value) { header($header . ': ' . $value); @@ -3977,17 +3988,28 @@ public function contentStrReplace() /** * Stores session data for the front end user + * + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0, as this is a simple wrapper method. */ public function storeSessionData() { + trigger_error('Calling $TSFE->storeSessionData will be removed in TYPO3 v10.0. Use the call on the FrontendUserAuthentication object directly instead.', E_USER_DEPRECATED); $this->fe_user->storeSessionData(); } /** * Outputs preview info. + * + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use "hook_eofe" instead. + * @param bool $isCoreCall if set to true, there will be no deprecation message. */ - public function previewInfo() + public function previewInfo($isCoreCall = false) { + if (!$isCoreCall) { + trigger_error('The method $TSFE->previewInfo() will be removed in TYPO3 v10.0, as this is now called by the Frontend RequestHandler', E_USER_DEPRECATED); + } elseif (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_previewInfo'])) { + trigger_error('The hook "hook_previewInfo" will be removed in TYPO3 v10.0, but is still in use. Use hook_eofe instead.', E_USER_DEPRECATED); + } if ($this->fePreview !== 0) { $previewInfo = ''; $_params = ['pObj' => &$this]; @@ -4000,9 +4022,12 @@ public function previewInfo() /** * End-Of-Frontend hook + * + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Functionality still exists. */ public function hook_eofe() { + trigger_error('TSFE->hook_eofe() will be removed in TYPO3 v10.0. The hook is now executed within Frontend RequestHandler', E_USER_DEPRECATED); $_params = ['pObj' => &$this]; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe'] ?? [] as $_funcRef) { GeneralUtility::callUserFunction($_funcRef, $_params, $this); @@ -4010,10 +4035,13 @@ public function hook_eofe() } /** - * Sends HTTP headers for temporary content. These headers prevent search engines from caching temporary content and asks them to revisit this page again. + * Sends HTTP headers for temporary content. + * These headers prevent search engines from caching temporary content and asks them to revisit this page again. + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use $TSFE->processOutput to send headers instead. */ public function addTempContentHttpHeaders() { + trigger_error('$TSFE->addTempContentHttpHeaders() will be removed in TYPO3 v10.0, as all headers are compiled within "processOutput" depending on various scenarios. Use $TSFE->processOutput() instead.', E_USER_DEPRECATED); header('HTTP/1.0 503 Service unavailable'); $headers = $this->getHttpHeadersForTemporaryContent(); foreach ($headers as $header => $value) { diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index 0e460a3a128b..0d249dd9efec 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -119,7 +119,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface $this->timeTracker->pull(); } // Store session data for fe_users - $controller->storeSessionData(); + $controller->fe_user->storeSessionData(); // @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0. $redirectResponse = $controller->redirectToExternalUrl(true); @@ -134,9 +134,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface } // Preview info - $controller->previewInfo(); - // Hook for end-of-frontend - $controller->hook_eofe(); + // @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. + $controller->previewInfo(true); + + // Hook for "end-of-frontend" + $_params = ['pObj' => &$controller]; + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe'] ?? [] as $_funcRef) { + GeneralUtility::callUserFunction($_funcRef, $_params, $controller); + } + // Finish timetracking $this->timeTracker->pull(); diff --git a/typo3/sysext/frontend/Classes/Utility/EidUtility.php b/typo3/sysext/frontend/Classes/Utility/EidUtility.php index d13d450044ab..a17914fd831f 100644 --- a/typo3/sysext/frontend/Classes/Utility/EidUtility.php +++ b/typo3/sysext/frontend/Classes/Utility/EidUtility.php @@ -29,6 +29,8 @@ * this class seeks to provide functions that can * initialize parts of the FE environment as needed, * eg. Frontend User session, Database connection etc. + * + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Ensure to migrate your eID script to a PSR-15 middleware at the right position, where the frontend is boot up at the level you need. */ class EidUtility { @@ -37,12 +39,41 @@ class EidUtility * it creates a calls many objects. Call this method only if necessary! * * @return FrontendUserAuthentication Frontend User object (usually known as TSFE->fe_user) + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Use the FrontendUserAuthenticator PSR-15 middleware to set up the Frontend User. */ public static function initFeUser() { + trigger_error('EidUtility::initFeUser() will be removed in TYPO3 v10. Ensure to intantiate the LanguageService by yourself.', E_USER_DEPRECATED); // Get TSFE instance. It knows how to initialize the user. $tsfe = self::getTSFE(); - $tsfe->initFEuser(); + $tsfe->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class); + // List of pid's acceptable + $pid = GeneralUtility::_GP('pid'); + $tsfe->fe_user->checkPid_value = $pid ? implode(',', GeneralUtility::intExplode(',', $pid)) : 0; + // Check if a session is transferred: + if (GeneralUtility::_GP('FE_SESSION_KEY')) { + $fe_sParts = explode('-', GeneralUtility::_GP('FE_SESSION_KEY')); + // If the session key hash check is OK: + if (md5($fe_sParts[0] . '/' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']) === (string)$fe_sParts[1]) { + $cookieName = FrontendUserAuthentication::getCookieName(); + $_COOKIE[$cookieName] = $fe_sParts[0]; + if (isset($_SERVER['HTTP_COOKIE'])) { + // See http://forge.typo3.org/issues/27740 + $_SERVER['HTTP_COOKIE'] .= ';' . $cookieName . '=' . $fe_sParts[0]; + } + $tsfe->fe_user->forceSetCookie = true; + $tsfe->fe_user->dontSetCookie = false; + unset($cookieName); + } + } + $tsfe->fe_user->start(); + $tsfe->fe_user->unpack_uc(); + + // Call hook for possible manipulation of frontend user object + $_params = ['pObj' => &$tsfe]; + foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] ?? [] as $_funcRef) { + GeneralUtility::callUserFunction($_funcRef, $_params, $tsfe); + } // Return FE user object: return $tsfe->fe_user; } @@ -51,9 +82,11 @@ public static function initFeUser() * Initializes $GLOBALS['LANG'] for use in eID scripts. * * @param string $language TYPO3 language code + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Instantiate the LanguageService by yourself instead. */ public static function initLanguage($language = 'default') { + trigger_error('EidUtility::initLanguage() will be removed in TYPO3 v10. Ensure to intantiate the LanguageService by yourself.', E_USER_DEPRECATED); if (!is_object($GLOBALS['LANG'])) { $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); $GLOBALS['LANG']->init($language); @@ -62,11 +95,11 @@ public static function initLanguage($language = 'default') /** * Makes TCA available inside eID - * @deprecated + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. Is not needed anymore within eID scripts as TCA is now available at any time */ public static function initTCA() { - trigger_error('This method will be removed in TYPO3 v10. Is not needed anymore within eID scripts as TCA is now available at any time.', E_USER_DEPRECATED); + trigger_error('EidUtility::initTCA() will be removed in TYPO3 v10. Is not needed anymore within eID scripts as TCA is now available at any time.', E_USER_DEPRECATED); // Some badly made extensions attempt to manipulate TCA in a wrong way // (inside ext_localconf.php). Therefore $GLOBALS['TCA'] may become an array // but in fact it is not loaded. The check below ensure that @@ -81,9 +114,11 @@ public static function initTCA() * you need not to include the whole $GLOBALS['TCA']. * * @param string $extensionKey Extension key + * @deprecated since TYPO3 v9.4, will be removed in TYPO3 v10.0. */ public static function initExtensionTCA($extensionKey) { + trigger_error('This method will be removed in TYPO3 v10 as it is discouraged to only load ext_tables.php of one extension. Use ExtensionManagementUtility instead.', E_USER_DEPRECATED); $extTablesPath = ExtensionManagementUtility::extPath($extensionKey, 'ext_tables.php'); if (file_exists($extTablesPath)) { $GLOBALS['_EXTKEY'] = $extensionKey; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php index 33e3f7ad861f..2407b4591ad5 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php @@ -170,4 +170,9 @@ 'Deprecation-85804-SaltedPasswordHashClassDeprecations.rst' ], ], + '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'tslib/class.tslib_fe.php\'][\'hook_previewInfo\']' => [ + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], ]; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php index 23230fb597e2..020906b9a0e7 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php @@ -2880,4 +2880,40 @@ 'Deprecation-85821-DeprecatedBoostrapMethods.rst', ], ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->initFEuser' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->sendCacheHeaders' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->storeSessionData' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->hook_eofe' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->previewInfo' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->addTempContentHttpHeaders' => [ + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], ]; diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php index a12476895d20..8a60d2bad464 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php @@ -407,7 +407,7 @@ 'Deprecation-80993-GeneralUtilitygetUserObj.rst', ], ], - 'TYPO3\CMS\Frontend\Utility::initTCA' => [ + 'TYPO3\CMS\Frontend\Utility\EidUtility::initTCA' => [ 'numberOfMandatoryArguments' => 0, 'maximumNumberOfArguments' => 0, 'restFiles' => [ @@ -736,4 +736,25 @@ 'Deprecation-85858-GeneralUtilityclientInfo.rst', ], ], + 'TYPO3\CMS\Frontend\Utility\EidUtility::initLanguage' => [ + 'numberOfMandatoryArguments' => 0, + 'maximumNumberOfArguments' => 1, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Utility\EidUtility::initFeUser' => [ + 'numberOfMandatoryArguments' => 0, + 'maximumNumberOfArguments' => 0, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], + 'TYPO3\CMS\Frontend\Utility\EidUtility::initExtensionTCA' => [ + 'numberOfMandatoryArguments' => 1, + 'maximumNumberOfArguments' => 1, + 'restFiles' => [ + 'Deprecation-85878-EidUtilityAndVariousTSFEMethods.rst', + ], + ], ];