Skip to content

Commit 1db76c6

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents b7e0985 + c66cdc2 commit 1db76c6

10 files changed

Lines changed: 174 additions & 154 deletions

File tree

phpstan-baseline.neon

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6787,7 +6787,7 @@ parameters:
67876787

67886788
-
67896789
message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#"
6790-
count: 3
6790+
count: 2
67916791
path: src/Display/Results.php
67926792

67936793
-
@@ -6830,6 +6830,11 @@ parameters:
68306830
count: 1
68316831
path: src/Display/Results.php
68326832

6833+
-
6834+
message: "#^Parameter \\#1 \\$statement of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Query\\:\\:replaceClause\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Statement, PhpMyAdmin\\\\SqlParser\\\\Statement\\|null given\\.$#"
6835+
count: 2
6836+
path: src/Display/Results.php
6837+
68336838
-
68346839
message: "#^Parameter \\#1 \\$table of class PhpMyAdmin\\\\Display\\\\ForeignKeyRelatedTable constructor expects string, mixed given\\.$#"
68356840
count: 2
@@ -6857,7 +6862,7 @@ parameters:
68576862

68586863
-
68596864
message: "#^Parameter \\#2 \\$list of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Query\\:\\:replaceClause\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#"
6860-
count: 1
6865+
count: 3
68616866
path: src/Display/Results.php
68626867

68636868
-
@@ -6901,17 +6906,17 @@ parameters:
69016906
path: src/Display/Results.php
69026907

69036908
-
6904-
message: "#^Parameter \\#5 \\$isFieldTruncated of method PhpMyAdmin\\\\Display\\\\Results\\:\\:addClass\\(\\) expects bool, mixed given\\.$#"
6909+
message: "#^Parameter \\#4 \\$sortExpressionNoDirection of method PhpMyAdmin\\\\Display\\\\Results\\:\\:getTableHeaders\\(\\) expects array\\<int, string\\>, array\\<int, string\\|null\\> given\\.$#"
69056910
count: 1
69066911
path: src/Display/Results.php
69076912

69086913
-
6909-
message: "#^Parameter \\#5 \\$sortDirection of method PhpMyAdmin\\\\Display\\\\Results\\:\\:getSingleAndMultiSortUrls\\(\\) expects array\\<string\\>, array given\\.$#"
6914+
message: "#^Parameter \\#5 \\$isFieldTruncated of method PhpMyAdmin\\\\Display\\\\Results\\:\\:addClass\\(\\) expects bool, mixed given\\.$#"
69106915
count: 1
69116916
path: src/Display/Results.php
69126917

69136918
-
6914-
message: "#^Parameter \\#5 \\$sortExpressionNoDirection of method PhpMyAdmin\\\\Display\\\\Results\\:\\:getTableHeaders\\(\\) expects array\\<int, string\\>, array\\<int, string\\|null\\> given\\.$#"
6919+
message: "#^Parameter \\#5 \\$sortDirection of method PhpMyAdmin\\\\Display\\\\Results\\:\\:getSingleAndMultiSortUrls\\(\\) expects array\\<string\\>, array given\\.$#"
69156920
count: 1
69166921
path: src/Display/Results.php
69176922

@@ -12300,16 +12305,6 @@ parameters:
1230012305
count: 1
1230112306
path: src/ResponseRenderer.php
1230212307

12303-
-
12304-
message: "#^Cannot access offset '/' on mixed\\.$#"
12305-
count: 1
12306-
path: src/Routing/Routing.php
12307-
12308-
-
12309-
message: "#^Cannot access offset 'GET' on mixed\\.$#"
12310-
count: 1
12311-
path: src/Routing/Routing.php
12312-
1231312308
-
1231412309
message: "#^Parameter \\#1 \\$filename of function is_readable expects string, mixed given\\.$#"
1231512310
count: 1
@@ -15936,15 +15931,20 @@ parameters:
1593615931
path: tests/unit/Replication/ReplicationGuiTest.php
1593715932

1593815933
-
15939-
message: "#^Parameter \\#1 \\$directory of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryIsWritable\\(\\) expects string, mixed given\\.$#"
15934+
message: "#^Cannot access offset '/' on mixed\\.$#"
1594015935
count: 1
1594115936
path: tests/unit/Routing/RoutingTest.php
1594215937

1594315938
-
15944-
message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$settings \\(array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\) does not accept array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\.$#"
15939+
message: "#^Cannot access offset 'GET' on mixed\\.$#"
1594515940
count: 1
1594615941
path: tests/unit/Routing/RoutingTest.php
1594715942

15943+
-
15944+
message: "#^Parameter \\#1 \\$directory of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryIsWritable\\(\\) expects string, mixed given\\.$#"
15945+
count: 3
15946+
path: tests/unit/Routing/RoutingTest.php
15947+
1594815948
-
1594915949
message: "#^Class PhpMyAdmin\\\\Tests\\\\Server\\\\PluginsTest has an uninitialized property \\$plugins\\. Give it default value or assign it in the constructor\\.$#"
1595015950
count: 1

psalm-baseline.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5455,6 +5455,8 @@
54555455
<PossiblyNullArgument>
54565456
<code><![CDATA[$statementInfo->parser->list]]></code>
54575457
<code><![CDATA[$statementInfo->parser->list]]></code>
5458+
<code><![CDATA[$statementInfo->parser->list]]></code>
5459+
<code><![CDATA[$statementInfo->statement]]></code>
54585460
</PossiblyNullArgument>
54595461
<PossiblyNullArrayAccess>
54605462
<code><![CDATA[$firstStatement->order[$key]]]></code>
@@ -10179,9 +10181,6 @@
1017910181
<DeprecatedMethod>
1018010182
<code><![CDATA[Config::getInstance()]]></code>
1018110183
</DeprecatedMethod>
10182-
<MixedArrayAccess>
10183-
<code><![CDATA[$dispatchData[0]['GET']['/']]]></code>
10184-
</MixedArrayAccess>
1018510184
</file>
1018610185
<file src="src/Sanitize.php">
1018710186
<DeprecatedMethod>
@@ -14538,10 +14537,10 @@
1453814537
<file src="tests/unit/Routing/RoutingTest.php">
1453914538
<DeprecatedMethod>
1454014539
<code><![CDATA[Config::getInstance()]]></code>
14540+
<code><![CDATA[Config::getInstance()]]></code>
14541+
<code><![CDATA[Config::getInstance()]]></code>
14542+
<code><![CDATA[Config::getInstance()]]></code>
1454114543
</DeprecatedMethod>
14542-
<InvalidPropertyAssignmentValue>
14543-
<code><![CDATA[$config->settings]]></code>
14544-
</InvalidPropertyAssignmentValue>
1454514544
<PossiblyUnusedMethod>
1454614545
<code><![CDATA[providerForTestCleanupPathInfo]]></code>
1454714546
</PossiblyUnusedMethod>

resources/js/src/database/multi_table_query.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ AJAX.registerTeardown('database/multi_table_query.js', function () {
2525
$(this).off('change');
2626
});
2727

28+
$('.columnNameSelect').each(function () {
29+
$(this).off('change');
30+
});
31+
2832
$('#update_query_button').off('click');
2933
$('#add_column_button').off('click');
3034
});
@@ -176,15 +180,27 @@ AJAX.registerOnload('database/multi_table_query.js', function () {
176180
addNewColumnCallbacks();
177181
});
178182

183+
$('.columnNameSelect').each(function () {
184+
$(this).on('change', function () {
185+
const colIsStar = $(this).val() === '*';
186+
187+
colIsStar && $(this).siblings('.col_alias').val('');
188+
$(this).siblings('.col_alias').prop('disabled', colIsStar);
189+
});
190+
});
191+
179192
function addNewColumnCallbacks () {
180193
$('.tableNameSelect').each(function () {
181194
$(this).on('change', function () {
182195
var $sibs = $(this).siblings('.columnNameSelect');
196+
const $alias = $(this).siblings('.col_alias');
197+
183198
if ($sibs.length === 0) {
184199
$sibs = $(this).parent().parent().find('.columnNameSelect');
185200
}
186201

187202
$sibs.first().html($('#' + $(this).find(':selected').data('hash')).html());
203+
$alias.prop('disabled', true);
188204
});
189205
});
190206

resources/js/src/modules/functions/escape.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function escapeJsString (unsafe) {
3838
* @return {string}
3939
*/
4040
export function escapeBacktick (s) {
41-
return s.replace('`', '``');
41+
return s.replaceAll('`', '``');
4242
}
4343

4444
/**

src/Display/Results.php

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ private function getTableNavigation(
680680
* @param mixed[] $sortDirection sort direction
681681
* @param bool $isLimitedDisplay with limited operations
682682
* or not
683-
* @param string $unsortedSqlQuery query without the sort part
684683
*
685684
* @return string html content
686685
*/
@@ -691,7 +690,6 @@ private function getTableHeadersForColumns(
691690
array $sortExpressionNoDirection,
692691
array $sortDirection,
693692
bool $isLimitedDisplay,
694-
string $unsortedSqlQuery,
695693
): string {
696694
// required to generate sort links that will remember whether the
697695
// "Show all" button has been clicked
@@ -728,7 +726,7 @@ private function getTableHeadersForColumns(
728726
$this->fieldsMeta[$i],
729727
$sortExpression,
730728
$sortExpressionNoDirection,
731-
$unsortedSqlQuery,
729+
$statementInfo,
732730
$sessionMaxRows,
733731
$comments,
734732
$sortDirection,
@@ -776,7 +774,6 @@ private function getTableHeadersForColumns(
776774
*
777775
* @see getTable()
778776
*
779-
* @param string $unsortedSqlQuery the unsorted sql query
780777
* @param mixed[] $sortExpression sort expression
781778
* @param array<int, string> $sortExpressionNoDirection sort expression without direction
782779
* @param mixed[] $sortDirection sort direction
@@ -794,7 +791,6 @@ private function getTableHeadersForColumns(
794791
private function getTableHeaders(
795792
DisplayParts $displayParts,
796793
StatementInfo $statementInfo,
797-
string $unsortedSqlQuery,
798794
array $sortExpression = [],
799795
array $sortExpressionNoDirection = [],
800796
array $sortDirection = [],
@@ -838,7 +834,6 @@ private function getTableHeaders(
838834
$sortExpressionNoDirection,
839835
$sortDirection,
840836
$isLimitedDisplay,
841-
$unsortedSqlQuery,
842837
);
843838

844839
// Display column at rightside - checkboxes or empty column
@@ -1134,7 +1129,7 @@ private function getFullOrPartialTextButtonOrLink(): string
11341129
. $themeManager->theme->getImgPath($tmpImageFile)
11351130
. '" alt="' . $tmpTxt . '" title="' . $tmpTxt . '">';
11361131

1137-
return Generator::linkOrButton(Url::getFromRoute('/sql'), $urlParamsFullText, $tmpImage);
1132+
return Generator::linkOrButton(Url::getFromRoute('/sql', $urlParamsFullText, false), null, $tmpImage);
11381133
}
11391134

11401135
/**
@@ -1165,7 +1160,6 @@ private function getCommentForRow(array $commentsMap, FieldMetadata $fieldsMeta)
11651160
* @param FieldMetadata $fieldsMeta set of field properties
11661161
* @param mixed[] $sortExpression sort expression
11671162
* @param array<int, string> $sortExpressionNoDirection sort expression without direction
1168-
* @param string $unsortedSqlQuery the unsorted sql query
11691163
* @param int $sessionMaxRows maximum rows resulted by sql
11701164
* @param string $comments comment for row
11711165
* @param mixed[] $sortDirection sort direction
@@ -1187,7 +1181,7 @@ private function getOrderLinkAndSortedHeaderHtml(
11871181
FieldMetadata $fieldsMeta,
11881182
array $sortExpression,
11891183
array $sortExpressionNoDirection,
1190-
string $unsortedSqlQuery,
1184+
StatementInfo $statementInfo,
11911185
int $sessionMaxRows,
11921186
string $comments,
11931187
array $sortDirection,
@@ -1216,19 +1210,16 @@ private function getOrderLinkAndSortedHeaderHtml(
12161210
$fieldsMeta,
12171211
);
12181212

1219-
if (
1220-
preg_match(
1221-
'@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is',
1222-
$unsortedSqlQuery,
1223-
$regs3,
1224-
)
1225-
) {
1226-
$singleSortedSqlQuery = $regs3[1] . $singleSortOrder . $regs3[2];
1227-
$multiSortedSqlQuery = $regs3[1] . $multiSortOrder . $regs3[2];
1228-
} else {
1229-
$singleSortedSqlQuery = $unsortedSqlQuery . $singleSortOrder;
1230-
$multiSortedSqlQuery = $unsortedSqlQuery . $multiSortOrder;
1231-
}
1213+
$singleSortedSqlQuery = Query::replaceClause(
1214+
$statementInfo->statement,
1215+
$statementInfo->parser->list,
1216+
$singleSortOrder,
1217+
);
1218+
$multiSortedSqlQuery = Query::replaceClause(
1219+
$statementInfo->statement,
1220+
$statementInfo->parser->list,
1221+
$multiSortOrder,
1222+
);
12321223

12331224
$singleUrlParams = [
12341225
'db' => $this->db,
@@ -1507,16 +1498,15 @@ private function getSortOrderLink(
15071498
array $orderUrlParams,
15081499
array $multiOrderUrlParams,
15091500
): string {
1510-
$urlPath = Url::getFromRoute('/sql');
1501+
$urlPath = Url::getFromRoute('/sql', $multiOrderUrlParams, false);
15111502
$innerLinkContent = htmlspecialchars($fieldsMeta->name) . $orderImg
15121503
. '<input type="hidden" value="'
15131504
. $urlPath
1514-
. Url::getCommon($multiOrderUrlParams, str_contains($urlPath, '?') ? '&' : '?', false)
15151505
. '">';
15161506

15171507
return Generator::linkOrButton(
1518-
Url::getFromRoute('/sql'),
1519-
$orderUrlParams,
1508+
Url::getFromRoute('/sql', $orderUrlParams, false),
1509+
null,
15201510
$innerLinkContent,
15211511
['class' => 'sortlink'],
15221512
);
@@ -3161,7 +3151,6 @@ public function getTable(
31613151
$this->table = $this->fieldsMeta[0]->table;
31623152
}
31633153

3164-
$unsortedSqlQuery = '';
31653154
$sortByKeyData = [];
31663155
// can the result be sorted?
31673156
if ($displayParts->hasSortLink && $statementInfo->statement !== null) {
@@ -3211,7 +3200,6 @@ public function getTable(
32113200
$headers = $this->getTableHeaders(
32123201
$displayParts,
32133202
$statementInfo,
3214-
$unsortedSqlQuery,
32153203
$sortExpression,
32163204
$sortExpressionNoDirection,
32173205
$sortDirection,
@@ -3909,8 +3897,8 @@ private function getRowData(
39093897
}
39103898

39113899
$value .= Generator::linkOrButton(
3912-
Url::getFromRoute('/sql'),
3913-
$urlParams,
3900+
Url::getFromRoute('/sql', $urlParams, false),
3901+
null,
39143902
$displayedData,
39153903
$tagParams,
39163904
);

src/Routing/Routing.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Fig\Http\Message\StatusCodeInterface;
1313
use PhpMyAdmin\Config;
1414
use PhpMyAdmin\Container\ContainerBuilder;
15-
use PhpMyAdmin\Controllers\HomeController;
1615
use PhpMyAdmin\Controllers\InvocableController;
1716
use PhpMyAdmin\Controllers\Setup\MainController;
1817
use PhpMyAdmin\Controllers\Setup\ShowConfigController;
@@ -35,7 +34,6 @@
3534
use function file_put_contents;
3635
use function htmlspecialchars;
3736
use function implode;
38-
use function is_array;
3937
use function is_readable;
4038
use function is_writable;
4139
use function mb_strlen;
@@ -92,12 +90,16 @@ public static function getDispatcher(): Dispatcher
9290

9391
// If skip cache is enabled, do not try to read the file
9492
// If no cache skipping then read it and use it
95-
if (! $skipCache && file_exists(self::ROUTES_CACHE_FILE)) {
93+
if (
94+
! $skipCache
95+
&& file_exists(self::ROUTES_CACHE_FILE)
96+
&& isset($_SESSION['isRoutesCacheFileValid'])
97+
&& $_SESSION['isRoutesCacheFileValid']
98+
) {
9699
/** @psalm-suppress MissingFile, UnresolvableInclude, MixedAssignment */
97100
$dispatchData = require self::ROUTES_CACHE_FILE;
98-
if (self::isRoutesCacheFileValid($dispatchData)) {
99-
return new DispatcherGroupCountBased($dispatchData);
100-
}
101+
102+
return new DispatcherGroupCountBased($dispatchData);
101103
}
102104

103105
$routeCollector = new RouteCollector(new RouteParserStd(), new DataGeneratorGroupCountBased());
@@ -109,10 +111,14 @@ public static function getDispatcher(): Dispatcher
109111
// If skip cache is enabled, do not try to write it
110112
// If no skip cache then try to write if write is possible
111113
if (! $skipCache && $canWriteCache) {
112-
$writeWorks = self::writeCache(
113-
'<?php return ' . var_export($dispatchData, true) . ';',
114-
);
115-
if (! $writeWorks) {
114+
/** @psalm-suppress MissingFile, UnresolvableInclude, MixedAssignment */
115+
$cachedDispatchData = file_exists(self::ROUTES_CACHE_FILE) ? require self::ROUTES_CACHE_FILE : [];
116+
$_SESSION['isRoutesCacheFileValid'] = $dispatchData === $cachedDispatchData;
117+
if (
118+
! $_SESSION['isRoutesCacheFileValid']
119+
&& ! self::writeCache(sprintf('<?php return %s;', var_export($dispatchData, true)))
120+
) {
121+
$_SESSION['isRoutesCacheFileValid'] = false;
116122
trigger_error(
117123
sprintf(
118124
__(
@@ -174,16 +180,6 @@ public static function callControllerForRoute(
174180
return $controller($request->withAttribute('routeVars', $routeInfo[2]));
175181
}
176182

177-
/** @psalm-assert-if-true array[] $dispatchData */
178-
private static function isRoutesCacheFileValid(mixed $dispatchData): bool
179-
{
180-
return is_array($dispatchData)
181-
&& isset($dispatchData[1])
182-
&& is_array($dispatchData[1])
183-
&& isset($dispatchData[0]['GET']['/'])
184-
&& $dispatchData[0]['GET']['/'] === HomeController::class;
185-
}
186-
187183
public static function callSetupController(ServerRequest $request, ResponseFactory $responseFactory): Response
188184
{
189185
$route = $request->getRoute();

0 commit comments

Comments
 (0)