Skip to content

Commit d5b068b

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents 07af957 + a174a41 commit d5b068b

File tree

8 files changed

+236
-13
lines changed

8 files changed

+236
-13
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog
1414
- issue #17364 Fix error when trying to import a status monitor chart arrangement
1515
- issue #18106 Fix renaming database with a view
1616
- issue #18120 Fix bug with numerical tables during renaming database
17+
- issue #16851 Fix ($cfg['Order']) default column order doesn't have have any effect since phpMyAdmin 4.2.0
1718

1819
5.2.1 (2023-02-07)
1920
- issue #17522 Fix case where the routes cache file is invalid

libraries/classes/Display/Results.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,11 +1430,16 @@ private function getSingleAndMultiSortUrls(
14301430
? 0
14311431
: count($sortExpressionNoDirection);
14321432
$sortExpressionNoDirection[$specialIndex] = Util::backquote($currentName);
1433-
$isTimeOrDate = $fieldsMeta->isType(FieldMetadata::TYPE_TIME)
1434-
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATE)
1435-
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATETIME)
1436-
|| $fieldsMeta->isType(FieldMetadata::TYPE_TIMESTAMP);
1437-
$sortDirection[$specialIndex] = $isTimeOrDate ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR;
1433+
// Set the direction to the config value
1434+
$sortDirection[$specialIndex] = $GLOBALS['cfg']['Order'];
1435+
// Or perform SMART mode
1436+
if ($GLOBALS['cfg']['Order'] === self::SMART_SORT_ORDER) {
1437+
$isTimeOrDate = $fieldsMeta->isType(FieldMetadata::TYPE_TIME)
1438+
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATE)
1439+
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATETIME)
1440+
|| $fieldsMeta->isType(FieldMetadata::TYPE_TIMESTAMP);
1441+
$sortDirection[$specialIndex] = $isTimeOrDate ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR;
1442+
}
14381443
}
14391444

14401445
$sortExpressionNoDirection = array_filter($sortExpressionNoDirection);

libraries/classes/Header.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ public function __construct()
9191
$this->bodyId = '';
9292
$this->title = '';
9393
$this->console = new Console(new Relation($GLOBALS['dbi']), $this->template);
94-
$this->menu = new Menu($GLOBALS['dbi'], $GLOBALS['db'] ?? '', $GLOBALS['table'] ?? '');
95-
$this->menuEnabled = true;
94+
$this->menuEnabled = false;
95+
if ($GLOBALS['dbi'] !== null) {
96+
$this->menuEnabled = true;
97+
$this->menu = new Menu($GLOBALS['dbi'], $GLOBALS['db'] ?? '', $GLOBALS['table'] ?? '');
98+
}
99+
96100
$this->warningsEnabled = true;
97101
$this->scripts = new Scripts();
98102
$this->addDefaultScripts();
@@ -150,8 +154,8 @@ public function getJsParams(): array
150154
'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'],
151155
'session_gc_maxlifetime' => (int) ini_get('session.gc_maxlifetime'),
152156
'logged_in' => isset($GLOBALS['dbi']) ? $GLOBALS['dbi']->isConnected() : false,
153-
'is_https' => $GLOBALS['config']->isHttps(),
154-
'rootPath' => $GLOBALS['config']->getRootPath(),
157+
'is_https' => $GLOBALS['config'] !== null && $GLOBALS['config']->isHttps(),
158+
'rootPath' => $GLOBALS['config'] !== null && $GLOBALS['config']->getRootPath(),
155159
'arg_separator' => Url::getArgSeparator(),
156160
'version' => Version::VERSION,
157161
];

libraries/classes/ResponseRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ private function getDisplay(): string
266266
// and, in this case, the header will be
267267
// in the content part of the request
268268
return (new Template())->render('base', [
269-
'header' => $this->header->getDisplay(),
269+
'header' => $this->header?->getDisplay() ?? '',
270270
'content' => $this->HTML,
271-
'footer' => $this->footer->getDisplay(),
271+
'footer' => $this->footer?->getDisplay() ?? '',
272272
]);
273273
}
274274

libraries/classes/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public static function buildHttpQuery($params, $encrypt = true)
251251

252252
$separator = self::getArgSeparator();
253253

254-
if (! $encrypt || ! $GLOBALS['config']->get('URLQueryEncryption')) {
254+
if (! $encrypt || $GLOBALS['config'] === null || ! $GLOBALS['config']->get('URLQueryEncryption')) {
255255
return http_build_query($params, '', $separator);
256256
}
257257

phpstan-baseline.neon

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7625,6 +7625,11 @@ parameters:
76257625
count: 1
76267626
path: libraries/classes/ReplicationInfo.php
76277627

7628+
-
7629+
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
7630+
count: 2
7631+
path: libraries/classes/ResponseRenderer.php
7632+
76287633
-
76297634
message: "#^Foreach overwrites \\$value with its value variable\\.$#"
76307635
count: 1
@@ -7640,6 +7645,16 @@ parameters:
76407645
count: 1
76417646
path: libraries/classes/ResponseRenderer.php
76427647

7648+
-
7649+
message: "#^Using nullsafe method call on non\\-nullable type PhpMyAdmin\\\\Footer\\. Use \\-\\> instead\\.$#"
7650+
count: 1
7651+
path: libraries/classes/ResponseRenderer.php
7652+
7653+
-
7654+
message: "#^Using nullsafe method call on non\\-nullable type PhpMyAdmin\\\\Header\\. Use \\-\\> instead\\.$#"
7655+
count: 1
7656+
path: libraries/classes/ResponseRenderer.php
7657+
76437658
-
76447659
message: "#^Casting to array\\<string, mixed\\> something that's already array\\<string, mixed\\>\\.$#"
76457660
count: 4
@@ -10300,6 +10315,11 @@ parameters:
1030010315
count: 1
1030110316
path: test/classes/Display/ResultsTest.php
1030210317

10318+
-
10319+
message: "#^Method PhpMyAdmin\\\\Tests\\\\Display\\\\ResultsTest\\:\\:dataProviderSortOrder\\(\\) return type has no value type specified in iterable type array\\.$#"
10320+
count: 1
10321+
path: test/classes/Display/ResultsTest.php
10322+
1030310323
-
1030410324
message: "#^Method PhpMyAdmin\\\\Tests\\\\Display\\\\ResultsTest\\:\\:providerSetConfigParamsForDisplayTable\\(\\) return type has no value type specified in iterable type array\\.$#"
1030510325
count: 1

psalm-baseline.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6969,6 +6969,7 @@
69696969
<code>$sortExpressionNoDirection</code>
69706970
</InvalidArgument>
69716971
<InvalidArrayOffset>
6972+
<code><![CDATA[$GLOBALS['cfg']['Order']]]></code>
69726973
<code><![CDATA[$GLOBALS['cfg']['RowActionType']]]></code>
69736974
<code><![CDATA[$GLOBALS['is_header_sent']]]></code>
69746975
<code><![CDATA[$GLOBALS['row']]]></code>
@@ -7018,6 +7019,10 @@
70187019
<code>$row[$i]</code>
70197020
<code>$row[$i]</code>
70207021
<code>$sessionMaxRows</code>
7022+
<code>$sortDirection[$index]</code>
7023+
<code>$sortDirection[$index]</code>
7024+
<code>$sortDirection[$index]</code>
7025+
<code>$sortDirection[$index]</code>
70217026
<code>$sortExpressionNoDirection[$indexInExpression]</code>
70227027
<code>$sortExpressionNoDirection[$indexInExpression]</code>
70237028
<code>$sortExpressionNoDirection[$indexInExpression]</code>
@@ -7220,6 +7225,7 @@
72207225
<code>$relationalDisplay</code>
72217226
<code><![CDATA[$rowInfo[mb_strtolower($fieldsMeta[$m]->orgname)]]]></code>
72227227
<code>$sessionMaxRows</code>
7228+
<code>$sortDirection[$specialIndex]</code>
72237229
<code>$sqlQuery</code>
72247230
<code>$sqlQueryAdd</code>
72257231
<code>$tableCreateTime</code>
@@ -8723,6 +8729,17 @@
87238729
<PossiblyInvalidArgument>
87248730
<code>$message</code>
87258731
</PossiblyInvalidArgument>
8732+
<PossiblyNullArgument>
8733+
<code><![CDATA[$GLOBALS['dbi']]]></code>
8734+
</PossiblyNullArgument>
8735+
<PropertyNotSetInConstructor>
8736+
<code>$menu</code>
8737+
</PropertyNotSetInConstructor>
8738+
<RedundantCondition>
8739+
<code><![CDATA[$GLOBALS['config'] !== null]]></code>
8740+
<code><![CDATA[$GLOBALS['config'] !== null]]></code>
8741+
<code><![CDATA[$GLOBALS['dbi'] !== null]]></code>
8742+
</RedundantCondition>
87268743
<RedundantFunctionCall>
87278744
<code>strtolower</code>
87288745
</RedundantFunctionCall>
@@ -13719,11 +13736,17 @@
1371913736
<code><![CDATA[(string) $GLOBALS['table']]]></code>
1372013737
</RedundantCast>
1372113738
<RedundantCondition>
13739+
<code><![CDATA[$this->footer?->getDisplay()]]></code>
13740+
<code><![CDATA[$this->header?->getDisplay()]]></code>
1372213741
<code><![CDATA[is_scalar($GLOBALS['db'])]]></code>
1372313742
<code><![CDATA[is_scalar($GLOBALS['table'])]]></code>
1372413743
<code><![CDATA[isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])]]></code>
1372513744
<code><![CDATA[isset($GLOBALS['table']) && is_scalar($GLOBALS['table'])]]></code>
1372613745
</RedundantCondition>
13746+
<TypeDoesNotContainNull>
13747+
<code><![CDATA[$this->footer]]></code>
13748+
<code><![CDATA[$this->header]]></code>
13749+
</TypeDoesNotContainNull>
1372713750
<TypeDoesNotContainType>
1372813751
<code><![CDATA['']]></code>
1372913752
<code><![CDATA['']]></code>
@@ -15551,7 +15574,6 @@
1555115574
}]]></code>
1555215575
</MixedReturnStatement>
1555315576
<PossiblyNullReference>
15554-
<code>get</code>
1555515577
<code>get</code>
1555615578
<code>getCookie</code>
1555715579
</PossiblyNullReference>
@@ -16916,6 +16938,8 @@
1691616938
<code><![CDATA[$_SESSION['tmpval']['relational_display']]]></code>
1691716939
</MixedArrayAssignment>
1691816940
<MixedAssignment>
16941+
<code>$data</code>
16942+
<code>$data</code>
1691916943
<code>$output</code>
1692016944
<code>$output</code>
1692116945
<code>$output</code>
@@ -16928,6 +16952,11 @@
1692816952
<code>array</code>
1692916953
<code>array</code>
1693016954
</MixedInferredReturnType>
16955+
<PossiblyInvalidArgument>
16956+
<code>testGetSingleAndMultiSortUrls</code>
16957+
<code>testGetSingleAndMultiSortUrls</code>
16958+
<code>testGetSingleAndMultiSortUrls</code>
16959+
</PossiblyInvalidArgument>
1693116960
</file>
1693216961
<file src="test/classes/Engines/PbxtTest.php">
1693316962
<MixedInferredReturnType>

test/classes/Display/ResultsTest.php

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use const MYSQLI_TYPE_DECIMAL;
3939
use const MYSQLI_TYPE_LONG;
4040
use const MYSQLI_TYPE_STRING;
41+
use const MYSQLI_TYPE_TIME;
4142
use const MYSQLI_TYPE_TIMESTAMP;
4243

4344
/**
@@ -1804,4 +1805,167 @@ public function testGetTable2(): void
18041805

18051806
$this->assertEquals($tableTemplate, $actual);
18061807
}
1808+
1809+
/**
1810+
* @return array[]
1811+
*/
1812+
public function dataProviderSortOrder(): array
1813+
{
1814+
return [
1815+
'Default date' => [
1816+
'SMART',
1817+
'DESC',// date types are DESC in SMART mode
1818+
MYSQLI_TYPE_DATE,
1819+
],
1820+
'ASC date' => [
1821+
'ASC',
1822+
'ASC',// do as config says
1823+
MYSQLI_TYPE_DATE,
1824+
],
1825+
'DESC date' => [
1826+
'DESC',
1827+
'DESC',// do as config says
1828+
MYSQLI_TYPE_DATE,
1829+
],
1830+
'Default date-time' => [
1831+
'SMART',
1832+
'DESC',// date time types are DESC in SMART mode
1833+
MYSQLI_TYPE_DATETIME,
1834+
],
1835+
'ASC date-time' => [
1836+
'ASC',
1837+
'ASC',// do as config says
1838+
MYSQLI_TYPE_DATETIME,
1839+
],
1840+
'DESC date-time' => [
1841+
'DESC',
1842+
'DESC',// do as config says
1843+
MYSQLI_TYPE_DATETIME,
1844+
],
1845+
'Default time' => [
1846+
'SMART',
1847+
'DESC',// time types are DESC in SMART mode
1848+
MYSQLI_TYPE_TIME,
1849+
],
1850+
'ASC time' => [
1851+
'ASC',
1852+
'ASC',// do as config says
1853+
MYSQLI_TYPE_TIME,
1854+
],
1855+
'DESC time' => [
1856+
'DESC',
1857+
'DESC',// do as config says
1858+
MYSQLI_TYPE_TIME,
1859+
],
1860+
'Default timestamp' => [
1861+
'SMART',
1862+
'DESC',// timestamp types are DESC in SMART mode
1863+
MYSQLI_TYPE_TIMESTAMP,
1864+
],
1865+
'ASC timestamp' => [
1866+
'ASC',
1867+
'ASC',// do as config says
1868+
MYSQLI_TYPE_TIMESTAMP,
1869+
],
1870+
'DESC timestamp' => [
1871+
'DESC',
1872+
'DESC',// do as config says
1873+
MYSQLI_TYPE_TIMESTAMP,
1874+
],
1875+
'Default string' => [
1876+
'SMART',
1877+
'ASC',// string types are ASC in SMART mode
1878+
MYSQLI_TYPE_STRING,
1879+
],
1880+
'ASC string' => [
1881+
'ASC',
1882+
'ASC',// do as config says
1883+
MYSQLI_TYPE_STRING,
1884+
],
1885+
'DESC string' => [
1886+
'DESC',
1887+
'DESC',// do as config says
1888+
MYSQLI_TYPE_STRING,
1889+
],
1890+
];
1891+
}
1892+
1893+
/**
1894+
* @dataProvider dataProviderSortOrder
1895+
*/
1896+
public function testGetSingleAndMultiSortUrls(
1897+
string $orderSetting,
1898+
string $querySortDirection,
1899+
int $metaType
1900+
): void {
1901+
$GLOBALS['cfg']['Order'] = $orderSetting;
1902+
1903+
$data = $this->callFunction(
1904+
$this->object,
1905+
DisplayResults::class,
1906+
'getSingleAndMultiSortUrls',
1907+
[
1908+
['`Country`.`Code` ASC'], // sortExpression,
1909+
['`Country`.`Code`'], // sortExpressionNoDirection,
1910+
'`Country`.',
1911+
'FoundedIn',
1912+
['ASC'], // sortDirection,
1913+
new FieldMetadata($metaType, 0, (object) []),
1914+
]
1915+
);
1916+
1917+
$this->assertSame([
1918+
"\n" . 'ORDER BY `Country`.`FoundedIn` ' . $querySortDirection, // singleSortOrder
1919+
"\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`FoundedIn` ' . $querySortDirection, // sortOrderColumns
1920+
'', // orderImg
1921+
], $data);
1922+
1923+
$data = $this->callFunction(
1924+
$this->object,
1925+
DisplayResults::class,
1926+
'getSingleAndMultiSortUrls',
1927+
[
1928+
['`Country`.`Code` ASC'], // sortExpression,
1929+
['`Country`.`Code`'], // sortExpressionNoDirection,
1930+
'`Country`.',
1931+
'Code2',
1932+
['ASC'], // sortDirection,
1933+
new FieldMetadata($metaType, 0, (object) []),
1934+
]
1935+
);
1936+
1937+
$this->assertSame([
1938+
"\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder
1939+
"\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns
1940+
'', // orderImg
1941+
], $data);
1942+
1943+
$data = $this->callFunction(
1944+
$this->object,
1945+
DisplayResults::class,
1946+
'getSingleAndMultiSortUrls',
1947+
[
1948+
[
1949+
'`Country`.`Continent` DESC","`Country`.`Region` ASC',
1950+
'`Country`.`Population` ASC',
1951+
], // sortExpression,
1952+
[
1953+
'`Country`.`Continent`',
1954+
'`Country`.`Region`',
1955+
'`Country`.`Population`',
1956+
], // sortExpressionNoDirection,
1957+
'`Country`.',
1958+
'Code2',
1959+
['DESC', 'ASC', 'ASC'], // sortDirection,
1960+
new FieldMetadata($metaType, 0, (object) []),
1961+
]
1962+
);
1963+
1964+
$this->assertSame([
1965+
"\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder
1966+
"\n" . 'ORDER BY `Country`.`Continent` DESC, `Country`.`Region` ASC'
1967+
. ', `Country`.`Population` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns
1968+
'', // orderImg
1969+
], $data);
1970+
}
18071971
}

0 commit comments

Comments
 (0)