Commit f2f1679f authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Richard Haeser
Browse files

[TASK] Deprecate GeneralUtility::compileSelectedGetVarsFromArray

To reduce usages of GeneralUtility::_GP(),
GeneralUtility::compileSelectedGetVarsFromArray()
is deprecated. Its only usage in the core is
adjusted by accessing the PSR-7 Request
instead.

Side note: Actually also the method name is
misleading. Since _GP() is used internally,
also POST data are checked.

Resolves: #94252
Releases: master
Change-Id: Ia3d569dbc9bdb21770e6d5981752f40b2fe59d0c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69362


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Richard Haeser's avatarRichard Haeser <richard@richardhaeser.com>
parent 7873a185
......@@ -465,7 +465,7 @@ class EditDocumentController
$this->R_URL_getvars['edit'] = $this->editconf;
// Prepare 'open documents' url, this is later modified again various times
$this->compileStoreData();
$this->compileStoreData($request);
// Backend user session data of this module
$this->docDat = $this->getBackendUser()->getModuleData('FormEngine', 'ses');
$this->docHandler = $this->docDat[0] ?? [];
......@@ -621,7 +621,7 @@ class EditDocumentController
// Unset default values since we don't need them anymore.
unset($this->R_URL_getvars['defVals']);
// Recompile the store* values since editconf changed
$this->compileStoreData();
$this->compileStoreData($request);
}
// See if any records was auto-created as new versions?
if (!empty($tce->autoVersionIdMap)) {
......@@ -670,7 +670,7 @@ class EditDocumentController
// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
$this->R_URL_getvars['edit'] = $this->editconf;
// Recompile the store* values since editconf changed...
$this->compileStoreData();
$this->compileStoreData($request);
}
// If a document should be duplicated.
if (isset($parsedBody['_duplicatedoc']) && is_array($this->editconf)) {
......@@ -725,7 +725,7 @@ class EditDocumentController
// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
$this->R_URL_getvars['edit'] = $this->editconf;
// Recompile the store* values since editconf changed...
$this->compileStoreData();
$this->compileStoreData($request);
// Inform the user of the duplication
$flashMessage = GeneralUtility::makeInstance(
......@@ -2398,13 +2398,19 @@ class EditDocumentController
* Populates the variables $this->storeArray, $this->storeUrl, $this->storeUrlMd5
* to prepare 'open documents' urls
*/
protected function compileStoreData(): void
protected function compileStoreData(ServerRequestInterface $request): void
{
// @todo: Refactor in TYPO3 v10: This GeneralUtility method fiddles with _GP()
$this->storeArray = GeneralUtility::compileSelectedGetVarsFromArray(
'edit,defVals,overrideVals,columnsOnly,noView',
$this->R_URL_getvars
);
$queryParams = $request->getQueryParams();
$parsedBody = $request->getParsedBody();
foreach (['edit', 'defVals', 'overrideVals' , 'columnsOnly' , 'noView'] as $key) {
if (isset($this->R_URL_getvars[$key])) {
$this->storeArray[$key] = $this->R_URL_getvars[$key];
} else {
$this->storeArray[$key] = $parsedBody[$key] ?? $queryParams[$key] ?? null;
}
}
$this->storeUrl = HttpUtility::buildQueryString($this->storeArray, '&');
$this->storeUrlMd5 = md5($this->storeUrl);
}
......
......@@ -1078,9 +1078,15 @@ class GeneralUtility
* @param array $getArray Array from where to get values based on the keys in $varList
* @param bool $GPvarAlt If set, then \TYPO3\CMS\Core\Utility\GeneralUtility::_GP() is used to fetch the value if not found (isset) in the $getArray
* @return array Output array with selected variables.
* @deprecated since v11, will be removed in v12.
*/
public static function compileSelectedGetVarsFromArray($varList, array $getArray, $GPvarAlt = true)
{
trigger_error(
'GeneralUtility::compileSelectedGetVarsFromArray() is deprecated and will be removed in v12.',
E_USER_DEPRECATED
);
$keys = self::trimExplode(',', $varList, true);
$outArr = [];
foreach ($keys as $v) {
......
.. include:: ../../Includes.txt
================================================================================
Deprecation: #94252 - Deprecated GeneralUtility::compileSelectedGetVarsFromArray
================================================================================
See :issue:`94252`
Description
===========
In our effort to reduce usages of :php:`GeneralUtility::_GP()`, the
:php:`GeneralUtility` method :php:`compileSelectedGetVarsFromArray` is
deprecated, since it internally calls :php:`GeneralUtility::_GP()` instead
of accessing the PSR-7 Request. The method was furthermore only used once
in the core since it's internal logic can easily be implemented on a case
by case basis.
Impact
======
Calling the method will log a deprecation warning and the method will
be dropped with TYPO3 v12.
Affected Installations
======================
All TYPO3 installations calling this method in custom code. The extension
scanner will find all usages as strong match.
Migration
=========
All usages of the method in custom extension code have to be replaced
with a custom implementation, preferably using the PSR-7 Request.
See: :php:`EditDocumentController->compileStoreData()` for an example
on how such migration could look like.
.. index:: PHP-API, FullyScanned, ext:core
......@@ -961,34 +961,6 @@ class GeneralUtilityTest extends UnitTestCase
];
}
//////////////////////////////////
// Tests concerning compileSelectedGetVarsFromArray
//////////////////////////////////
/**
* @test
*/
public function compileSelectedGetVarsFromArrayFiltersIncomingData()
{
$filter = 'foo,bar';
$getArray = ['foo' => 1, 'cake' => 'lie'];
$expected = ['foo' => 1];
$result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, false);
self::assertSame($expected, $result);
}
/**
* @test
*/
public function compileSelectedGetVarsFromArrayUsesGetPostDataFallback()
{
$_GET['bar'] = '2';
$filter = 'foo,bar';
$getArray = ['foo' => 1, 'cake' => 'lie'];
$expected = ['foo' => 1, 'bar' => '2'];
$result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, true);
self::assertSame($expected, $result);
}
//////////////////////////////////
// Tests concerning revExplode
//////////////////////////////////
......
<?php
declare(strict_types=1);
/*
* 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!
*/
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class GeneralUtilityTest extends UnitTestCase
{
/**
* @test
*/
public function compileSelectedGetVarsFromArrayFiltersIncomingData(): void
{
$filter = 'foo,bar';
$getArray = ['foo' => 1, 'cake' => 'lie'];
$expected = ['foo' => 1];
$result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, false);
self::assertSame($expected, $result);
}
/**
* @test
*/
public function compileSelectedGetVarsFromArrayUsesGetPostDataFallback(): void
{
$_GET['bar'] = '2';
$filter = 'foo,bar';
$getArray = ['foo' => 1, 'cake' => 'lie'];
$expected = ['foo' => 1, 'bar' => '2'];
$result = GeneralUtility::compileSelectedGetVarsFromArray($filter, $getArray, true);
self::assertSame($expected, $result);
}
}
......@@ -1072,4 +1072,11 @@ return [
'Breaking-93080-RelationHandlerInternalsProtected.rst',
],
],
'TYPO3\CMS\Core\Utility\GeneralUtility::compileSelectedGetVarsFromArray' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 3,
'restFiles' => [
'Deprecation-94252-DeprecatedGeneralUtilitycompileSelectedGetVarsFromArray.rst'
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment