Replace request globals with ServerRequest in Display\Results class
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
1f4bbe5636
commit
190de2a439
@ -3851,13 +3851,18 @@
|
||||
<code><![CDATA[$expr]]></code>
|
||||
<code><![CDATA[$expr]]></code>
|
||||
<code><![CDATA[$field]]></code>
|
||||
<code><![CDATA[$geoOption]]></code>
|
||||
<code><![CDATA[$hiddenFields['session_max_rows']]]></code>
|
||||
<code><![CDATA[$i]]></code>
|
||||
<code><![CDATA[$i]]></code>
|
||||
<code><![CDATA[$identifier]]></code>
|
||||
<code><![CDATA[$meta->name]]></code>
|
||||
<code><![CDATA[$pftext]]></code>
|
||||
<code><![CDATA[$pos]]></code>
|
||||
<code><![CDATA[$query]]></code>
|
||||
<code><![CDATA[$relationalDisplay]]></code>
|
||||
<code><![CDATA[$relationalDisplay]]></code>
|
||||
<code><![CDATA[$sessionMaxRows]]></code>
|
||||
<code><![CDATA[$value]]></code>
|
||||
</MixedAssignment>
|
||||
<MixedOperand>
|
||||
@ -6114,7 +6119,6 @@
|
||||
</PossiblyNullReference>
|
||||
<PossiblyUnusedReturnValue>
|
||||
<code><![CDATA[bool]]></code>
|
||||
<code><![CDATA[bool]]></code>
|
||||
</PossiblyUnusedReturnValue>
|
||||
<RiskyTruthyFalsyComparison>
|
||||
<code><![CDATA[empty($column->collation)]]></code>
|
||||
@ -10175,7 +10179,6 @@
|
||||
<code><![CDATA[testSetConfigParamsForDisplayTable]]></code>
|
||||
<code><![CDATA[testSetConfigParamsForDisplayTable]]></code>
|
||||
<code><![CDATA[testSetConfigParamsForDisplayTable]]></code>
|
||||
<code><![CDATA[testSetConfigParamsForDisplayTable]]></code>
|
||||
</PossiblyInvalidArgument>
|
||||
<PropertyTypeCoercion>
|
||||
<code><![CDATA[$config->settings]]></code>
|
||||
|
||||
@ -14,6 +14,7 @@ use PhpMyAdmin\Dbal\DatabaseInterface;
|
||||
use PhpMyAdmin\Dbal\ResultInterface;
|
||||
use PhpMyAdmin\FieldMetadata;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Indexes\Index;
|
||||
use PhpMyAdmin\Indexes\IndexColumn;
|
||||
use PhpMyAdmin\Message;
|
||||
@ -2789,7 +2790,7 @@ class Results
|
||||
* @todo currently this is called twice unnecessary
|
||||
* @todo ignore LIMIT and ORDER in query!?
|
||||
*/
|
||||
public function setConfigParamsForDisplayTable(StatementInfo $statementInfo): void
|
||||
public function setConfigParamsForDisplayTable(ServerRequest $request, StatementInfo $statementInfo): void
|
||||
{
|
||||
$sqlMd5 = md5($this->server . $this->db . $this->sqlQuery);
|
||||
$query = $_SESSION['tmpval']['query'][$sqlMd5] ?? [];
|
||||
@ -2801,21 +2802,19 @@ class Results
|
||||
}
|
||||
|
||||
// The value can also be from _GET as described on issue #16146 when sorting results
|
||||
$sessionMaxRows = $_GET['session_max_rows'] ?? $_POST['session_max_rows'] ?? '';
|
||||
$sessionMaxRows = $request->getParam('session_max_rows');
|
||||
|
||||
if (is_numeric($sessionMaxRows)) {
|
||||
$query['max_rows'] = (int) $sessionMaxRows;
|
||||
unset($_GET['session_max_rows'], $_POST['session_max_rows']);
|
||||
} elseif ($sessionMaxRows === self::ALL_ROWS) {
|
||||
$query['max_rows'] = self::ALL_ROWS;
|
||||
unset($_GET['session_max_rows'], $_POST['session_max_rows']);
|
||||
} elseif (empty($query['max_rows'])) {
|
||||
$query['max_rows'] = $this->config->config->maxRows;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['pos']) && is_numeric($_REQUEST['pos'])) {
|
||||
$query['pos'] = (int) $_REQUEST['pos'];
|
||||
unset($_REQUEST['pos']);
|
||||
$pos = $request->getParam('pos');
|
||||
if (is_numeric($pos)) {
|
||||
$query['pos'] = (int) $pos;
|
||||
} elseif (empty($query['pos'])) {
|
||||
$query['pos'] = 0;
|
||||
}
|
||||
@ -2823,30 +2822,18 @@ class Results
|
||||
// Full text is needed in case of explain statements, if not specified.
|
||||
$fullText = $statementInfo->flags->queryType === StatementType::Explain;
|
||||
|
||||
if (
|
||||
isset($_REQUEST['pftext']) && in_array(
|
||||
$_REQUEST['pftext'],
|
||||
[self::DISPLAY_PARTIAL_TEXT, self::DISPLAY_FULL_TEXT],
|
||||
true,
|
||||
)
|
||||
) {
|
||||
$query['pftext'] = $_REQUEST['pftext'];
|
||||
unset($_REQUEST['pftext']);
|
||||
$pftext = $request->getParam('pftext');
|
||||
if (in_array($pftext, [self::DISPLAY_PARTIAL_TEXT, self::DISPLAY_FULL_TEXT], true)) {
|
||||
$query['pftext'] = $pftext;
|
||||
} elseif ($fullText) {
|
||||
$query['pftext'] = self::DISPLAY_FULL_TEXT;
|
||||
} elseif (empty($query['pftext'])) {
|
||||
$query['pftext'] = self::DISPLAY_PARTIAL_TEXT;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($_REQUEST['relational_display']) && in_array(
|
||||
$_REQUEST['relational_display'],
|
||||
[self::RELATIONAL_KEY, self::RELATIONAL_DISPLAY_COLUMN],
|
||||
true,
|
||||
)
|
||||
) {
|
||||
$query['relational_display'] = $_REQUEST['relational_display'];
|
||||
unset($_REQUEST['relational_display']);
|
||||
$relationalDisplay = $request->getParam('relational_display');
|
||||
if (in_array($relationalDisplay, [self::RELATIONAL_KEY, self::RELATIONAL_DISPLAY_COLUMN], true)) {
|
||||
$query['relational_display'] = $relationalDisplay;
|
||||
} elseif (empty($query['relational_display'])) {
|
||||
// The current session value has priority over a
|
||||
// change via Settings; this change will be apparent
|
||||
@ -2854,44 +2841,35 @@ class Results
|
||||
$query['relational_display'] = $this->config->settings['RelationalDisplay'];
|
||||
}
|
||||
|
||||
if (
|
||||
isset($_REQUEST['geoOption']) && in_array(
|
||||
$_REQUEST['geoOption'],
|
||||
[self::GEOMETRY_DISP_WKT, self::GEOMETRY_DISP_WKB, self::GEOMETRY_DISP_GEOM],
|
||||
true,
|
||||
)
|
||||
) {
|
||||
$query['geoOption'] = $_REQUEST['geoOption'];
|
||||
unset($_REQUEST['geoOption']);
|
||||
$geoOption = $request->getParam('geoOption');
|
||||
if (in_array($geoOption, [self::GEOMETRY_DISP_WKT, self::GEOMETRY_DISP_WKB, self::GEOMETRY_DISP_GEOM], true)) {
|
||||
$query['geoOption'] = $geoOption;
|
||||
} elseif (empty($query['geoOption'])) {
|
||||
$query['geoOption'] = self::GEOMETRY_DISP_GEOM;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['display_binary'])) {
|
||||
if ($request->has('display_binary')) {
|
||||
$query['display_binary'] = true;
|
||||
unset($_REQUEST['display_binary']);
|
||||
} elseif (isset($_REQUEST['display_options_form'])) {
|
||||
} elseif ($request->has('display_options_form')) {
|
||||
// we know that the checkbox was unchecked
|
||||
unset($query['display_binary']);
|
||||
} elseif (! isset($_REQUEST['full_text_button'])) {
|
||||
} elseif (! $request->has('full_text_button')) {
|
||||
// selected by default because some operations like OPTIMIZE TABLE
|
||||
// and all queries involving functions return "binary" contents,
|
||||
// according to low-level field flags
|
||||
$query['display_binary'] = true;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['display_blob'])) {
|
||||
if ($request->has('display_blob')) {
|
||||
$query['display_blob'] = true;
|
||||
unset($_REQUEST['display_blob']);
|
||||
} elseif (isset($_REQUEST['display_options_form'])) {
|
||||
} elseif ($request->has('display_options_form')) {
|
||||
// we know that the checkbox was unchecked
|
||||
unset($query['display_blob']);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['hide_transformation'])) {
|
||||
if ($request->has('hide_transformation')) {
|
||||
$query['hide_transformation'] = true;
|
||||
unset($_REQUEST['hide_transformation']);
|
||||
} elseif (isset($_REQUEST['display_options_form'])) {
|
||||
} elseif ($request->has('display_options_form')) {
|
||||
// we know that the checkbox was unchecked
|
||||
unset($query['hide_transformation']);
|
||||
}
|
||||
|
||||
@ -1542,7 +1542,7 @@ class Sql
|
||||
$goto,
|
||||
$sqlQuery,
|
||||
);
|
||||
$displayResultsObject->setConfigParamsForDisplayTable($statementInfo);
|
||||
$displayResultsObject->setConfigParamsForDisplayTable($request, $statementInfo);
|
||||
|
||||
// assign default full_sql_query
|
||||
$fullSqlQuery = $sqlQuery;
|
||||
|
||||
@ -15,6 +15,7 @@ use PhpMyAdmin\Display\Results as DisplayResults;
|
||||
use PhpMyAdmin\Display\SortExpression;
|
||||
use PhpMyAdmin\FieldMetadata;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\MessageType;
|
||||
use PhpMyAdmin\ParseAnalyze;
|
||||
@ -876,8 +877,10 @@ class ResultsTest extends AbstractTestCase
|
||||
$query = 'ANALYZE FORMAT=JSON SELECT * FROM test_table';
|
||||
[$statementInfo] = ParseAnalyze::sqlQuery($query, $db);
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com');
|
||||
|
||||
$object = new DisplayResults($this->dbi, $config, $db, $table, 2, '', $query);
|
||||
$object->setConfigParamsForDisplayTable($statementInfo);
|
||||
$object->setConfigParamsForDisplayTable($request, $statementInfo);
|
||||
|
||||
self::assertSame('F', $_SESSION['tmpval']['pftext']);
|
||||
|
||||
@ -885,38 +888,37 @@ class ResultsTest extends AbstractTestCase
|
||||
[$statementInfo] = ParseAnalyze::sqlQuery($query, $db);
|
||||
|
||||
$object = new DisplayResults($this->dbi, $config, $db, $table, 2, '', $query);
|
||||
$object->setConfigParamsForDisplayTable($statementInfo);
|
||||
$object->setConfigParamsForDisplayTable($request, $statementInfo);
|
||||
|
||||
self::assertSame('P', $_SESSION['tmpval']['pftext']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array<string, array<string, array<string, bool|int|string>>>|string> $session
|
||||
* @param array<string, string> $get
|
||||
* @param array<string, string> $post
|
||||
* @param array<string, string> $request
|
||||
* @param array<string, string> $queryParams
|
||||
* @param array<string, string> $parsedBody
|
||||
* @param array<string, bool|array<string, array<string, bool|int|string>>|string|int> $expected
|
||||
*/
|
||||
#[DataProvider('providerSetConfigParamsForDisplayTable')]
|
||||
public function testSetConfigParamsForDisplayTable(
|
||||
array $session,
|
||||
array $get,
|
||||
array $post,
|
||||
array $request,
|
||||
array $queryParams,
|
||||
array $parsedBody,
|
||||
array $expected,
|
||||
): void {
|
||||
$_SESSION = $session;
|
||||
$_GET = $get;
|
||||
$_POST = $post;
|
||||
$_REQUEST = $request;
|
||||
|
||||
$db = 'test_db';
|
||||
$table = 'test_table';
|
||||
$query = 'SELECT * FROM `test_db`.`test_table`;';
|
||||
[$statementInfo] = ParseAnalyze::sqlQuery($query, $db);
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com')
|
||||
->withQueryParams($queryParams)
|
||||
->withParsedBody($parsedBody);
|
||||
|
||||
$object = new DisplayResults($this->dbi, Config::getInstance(), $db, $table, 2, '', $query);
|
||||
$object->setConfigParamsForDisplayTable($statementInfo);
|
||||
$object->setConfigParamsForDisplayTable($request, $statementInfo);
|
||||
|
||||
self::assertArrayHasKey('tmpval', $_SESSION);
|
||||
self::assertIsArray($_SESSION['tmpval']);
|
||||
@ -933,7 +935,6 @@ class ResultsTest extends AbstractTestCase
|
||||
[' PMA_token ' => 'token'],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'query' => [
|
||||
'2b7b3faf4b48255e47876f6d5bd2da35' => [
|
||||
@ -988,7 +989,6 @@ class ResultsTest extends AbstractTestCase
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'query' => [
|
||||
'b' => [],
|
||||
@ -1024,9 +1024,9 @@ class ResultsTest extends AbstractTestCase
|
||||
],
|
||||
'default and request values' => [
|
||||
[' PMA_token ' => 'token'],
|
||||
['session_max_rows' => '27'],
|
||||
['session_max_rows' => '28'],
|
||||
[
|
||||
'session_max_rows' => '27',
|
||||
'pos' => '2',
|
||||
'pftext' => DisplayResults::DISPLAY_FULL_TEXT,
|
||||
'relational_display' => DisplayResults::RELATIONAL_DISPLAY_COLUMN,
|
||||
@ -1088,7 +1088,6 @@ class ResultsTest extends AbstractTestCase
|
||||
],
|
||||
' PMA_token ' => 'token',
|
||||
],
|
||||
[],
|
||||
['session_max_rows' => DisplayResults::ALL_ROWS],
|
||||
[
|
||||
'pos' => 'NaN',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user