Skip to content

Commit

Permalink
[TASK] Deprecate EidUtility and methods within TSFE
Browse files Browse the repository at this point in the history
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 <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
  • Loading branch information
bmack authored and wouter90 committed Aug 16, 2018
1 parent 551f4fc commit de39313
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 12 deletions.
@@ -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
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -4000,20 +4022,26 @@ 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);
}
}

/**
* 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) {
Expand Down
14 changes: 10 additions & 4 deletions typo3/sysext/frontend/Classes/Http/RequestHandler.php
Expand Up @@ -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);
Expand All @@ -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();

Expand Down
41 changes: 38 additions & 3 deletions typo3/sysext/frontend/Classes/Utility/EidUtility.php
Expand Up @@ -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
{
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand Down
Expand Up @@ -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',
],
],
];
Expand Up @@ -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',
],
],
];
Expand Up @@ -407,7 +407,7 @@
'Deprecation-80993-GeneralUtilitygetUserObj.rst',
],
],
'TYPO3\CMS\Frontend\Utility::initTCA' => [
'TYPO3\CMS\Frontend\Utility\EidUtility::initTCA' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
Expand Down Expand Up @@ -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',
],
],
];

0 comments on commit de39313

Please sign in to comment.