Skip to content

Commit 4d691ea

Browse files
Merge pull request #19054 from kamil-tekiela/Refactor-import-10
Remove register globals from import and privileges
2 parents 015d66c + ae23908 commit 4d691ea

16 files changed

Lines changed: 189 additions & 258 deletions

‎phpstan-baseline.neon‎

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5857,7 +5857,7 @@ parameters:
58575857

58585858
-
58595859
message: "#^Only booleans are allowed in a negated boolean, int\\|false given\\.$#"
5860-
count: 2
5860+
count: 1
58615861
path: src/Core.php
58625862

58635863
-
@@ -5875,11 +5875,6 @@ parameters:
58755875
count: 1
58765876
path: src/Core.php
58775877

5878-
-
5879-
message: "#^Parameter \\#1 \\$pattern of function preg_match expects string, mixed given\\.$#"
5880-
count: 1
5881-
path: src/Core.php
5882-
58835878
-
58845879
message: "#^Parameter \\#1 \\$sqlQuery of static method PhpMyAdmin\\\\Html\\\\Generator\\:\\:formatSql\\(\\) expects string, mixed given\\.$#"
58855880
count: 1
@@ -5895,11 +5890,6 @@ parameters:
58955890
count: 1
58965891
path: src/Core.php
58975892

5898-
-
5899-
message: "#^Parameter \\#2 \\$subject of function preg_match expects string, \\(int\\|string\\) given\\.$#"
5900-
count: 1
5901-
path: src/Core.php
5902-
59035893
-
59045894
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
59055895
count: 3
@@ -11295,19 +11285,14 @@ parameters:
1129511285
count: 1
1129611286
path: src/Plugins/ExportPlugin.php
1129711287

11298-
-
11299-
message: "#^Cannot access offset 0 on mixed\\.$#"
11300-
count: 10
11301-
path: src/Plugins/Import/ImportCsv.php
11302-
1130311288
-
1130411289
message: "#^Cannot call method getMessage\\(\\) on mixed\\.$#"
1130511290
count: 1
1130611291
path: src/Plugins/Import/ImportCsv.php
1130711292

1130811293
-
1130911294
message: "#^Cannot cast mixed to string\\.$#"
11310-
count: 3
11295+
count: 8
1131111296
path: src/Plugins/Import/ImportCsv.php
1131211297

1131311298
-
@@ -11335,46 +11320,11 @@ parameters:
1133511320
count: 1
1133611321
path: src/Plugins/Import/ImportCsv.php
1133711322

11338-
-
11339-
message: "#^Parameter \\#1 \\$csvTerminated of method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportCsv\\:\\:buildErrorsForParams\\(\\) expects string, mixed given\\.$#"
11340-
count: 1
11341-
path: src/Plugins/Import/ImportCsv.php
11342-
1134311323
-
1134411324
message: "#^Parameter \\#1 \\$serverMessage of static method PhpMyAdmin\\\\Html\\\\Generator\\:\\:mysqlDie\\(\\) expects string, mixed given\\.$#"
1134511325
count: 1
1134611326
path: src/Plugins/Import/ImportCsv.php
1134711327

11348-
-
11349-
message: "#^Parameter \\#1 \\$str of function strtr expects string, mixed given\\.$#"
11350-
count: 4
11351-
path: src/Plugins/Import/ImportCsv.php
11352-
11353-
-
11354-
message: "#^Parameter \\#1 \\$string of function mb_strlen expects string, mixed given\\.$#"
11355-
count: 1
11356-
path: src/Plugins/Import/ImportCsv.php
11357-
11358-
-
11359-
message: "#^Parameter \\#2 \\$csvEnclosed of method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportCsv\\:\\:buildErrorsForParams\\(\\) expects string, mixed given\\.$#"
11360-
count: 1
11361-
path: src/Plugins/Import/ImportCsv.php
11362-
11363-
-
11364-
message: "#^Parameter \\#2 \\$needle of function str_contains expects string, mixed given\\.$#"
11365-
count: 1
11366-
path: src/Plugins/Import/ImportCsv.php
11367-
11368-
-
11369-
message: "#^Parameter \\#3 \\$csvColumns of method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportCsv\\:\\:getSqlTemplateAndRequiredFields\\(\\) expects string\\|null, mixed given\\.$#"
11370-
count: 1
11371-
path: src/Plugins/Import/ImportCsv.php
11372-
11373-
-
11374-
message: "#^Parameter \\#3 \\$csvEscaped of method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportCsv\\:\\:buildErrorsForParams\\(\\) expects string, mixed given\\.$#"
11375-
count: 1
11376-
path: src/Plugins/Import/ImportCsv.php
11377-
1137811328
-
1137911329
message: "#^Parameter \\#3 \\$rows of class PhpMyAdmin\\\\Import\\\\ImportTable constructor expects array\\<int, array\\<int, mixed\\>\\>, array\\<int\\<0, max\\>, array\\> given\\.$#"
1138011330
count: 1
@@ -11395,16 +11345,6 @@ parameters:
1139511345
count: 1
1139611346
path: src/Plugins/Import/ImportLdi.php
1139711347

11398-
-
11399-
message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#"
11400-
count: 2
11401-
path: src/Plugins/Import/ImportLdi.php
11402-
11403-
-
11404-
message: "#^Parameter \\#2 \\$subject of function preg_split expects string, mixed given\\.$#"
11405-
count: 1
11406-
path: src/Plugins/Import/ImportLdi.php
11407-
1140811348
-
1140911349
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Import\\\\ImportMediawiki\\:\\:doImport\\(\\) should return array\\<string\\> but returns mixed\\.$#"
1141011350
count: 1
@@ -12972,7 +12912,7 @@ parameters:
1297212912

1297312913
-
1297412914
message: "#^Cannot cast mixed to int\\.$#"
12975-
count: 8
12915+
count: 4
1297612916
path: src/Server/Privileges.php
1297712917

1297812918
-

‎psalm-baseline.xml‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,6 @@
41694169
<code><![CDATA[$matches[1]]]></code>
41704170
</InvalidOperand>
41714171
<MixedArgument>
4172-
<code><![CDATA[$onePostPattern]]></code>
41734172
<code><![CDATA[$path[$depth + 1]]]></code>
41744173
<code><![CDATA[$query]]></code>
41754174
</MixedArgument>
@@ -4188,7 +4187,6 @@
41884187
<code><![CDATA[$_POST[$urlQueryParamKey]]]></code>
41894188
<code><![CDATA[$_REQUEST[$urlQueryParamKey]]]></code>
41904189
<code><![CDATA[$a[$lastKey]]]></code>
4191-
<code><![CDATA[$onePostPattern]]></code>
41924190
<code><![CDATA[$parsedBody[$urlQueryParamKey]]]></code>
41934191
<code><![CDATA[$path[$depth]]]></code>
41944192
<code><![CDATA[$query]]></code>
@@ -4201,9 +4199,6 @@
42014199
<code><![CDATA[$secret]]></code>
42024200
<code><![CDATA[$secret]]></code>
42034201
</MixedOperand>
4204-
<PossiblyInvalidArgument>
4205-
<code><![CDATA[$postKey]]></code>
4206-
</PossiblyInvalidArgument>
42074202
<PossiblyInvalidArrayOffset>
42084203
<code><![CDATA[$path[$depth - 1]]]></code>
42094204
</PossiblyInvalidArrayOffset>
@@ -8587,11 +8582,9 @@
85878582
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
85888583
</DeprecatedMethod>
85898584
<InvalidArgument>
8590-
<code><![CDATA[$GLOBALS['csv_columns']]]></code>
85918585
<code><![CDATA[$colNames]]></code>
85928586
</InvalidArgument>
85938587
<InvalidArrayOffset>
8594-
<code><![CDATA[$GLOBALS['csv_new_line']]]></code>
85958588
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
85968589
<code><![CDATA[$values[count($values) - 1]]]></code>
85978590
<code><![CDATA[$values[count($values) - 1]]]></code>
@@ -8602,11 +8595,7 @@
86028595
<InvalidReturnType>
86038596
<code><![CDATA[string]]></code>
86048597
</InvalidReturnType>
8605-
<MixedArgument>
8606-
<code><![CDATA[$GLOBALS['csv_new_line']]]></code>
8607-
</MixedArgument>
86088598
<MixedAssignment>
8609-
<code><![CDATA[$GLOBALS['csv_new_line']]]></code>
86108599
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
86118600
</MixedAssignment>
86128601
<PossiblyInvalidCast>
@@ -8617,12 +8606,6 @@
86178606
<code><![CDATA[$maxLines]]></code>
86188607
<code><![CDATA[1]]></code>
86198608
</PossiblyInvalidOperand>
8620-
<PossiblyNullArgument>
8621-
<code><![CDATA[$GLOBALS['csv_enclosed']]]></code>
8622-
<code><![CDATA[$GLOBALS['csv_escaped']]]></code>
8623-
<code><![CDATA[$GLOBALS['csv_new_line']]]></code>
8624-
<code><![CDATA[$GLOBALS['csv_terminated']]]></code>
8625-
</PossiblyNullArgument>
86268609
<PossiblyNullOperand>
86278610
<code><![CDATA[$ch]]></code>
86288611
</PossiblyNullOperand>
@@ -8645,41 +8628,9 @@
86458628
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
86468629
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
86478630
</DeprecatedMethod>
8648-
<InvalidArrayOffset>
8649-
<code><![CDATA[$GLOBALS['ldi_columns']]]></code>
8650-
<code><![CDATA[$GLOBALS['ldi_enclosed']]]></code>
8651-
<code><![CDATA[$GLOBALS['ldi_escaped']]]></code>
8652-
<code><![CDATA[$GLOBALS['ldi_ignore']]]></code>
8653-
<code><![CDATA[$GLOBALS['ldi_local_option']]]></code>
8654-
<code><![CDATA[$GLOBALS['ldi_new_line']]]></code>
8655-
<code><![CDATA[$GLOBALS['ldi_replace']]]></code>
8656-
<code><![CDATA[$GLOBALS['ldi_terminated']]]></code>
8657-
</InvalidArrayOffset>
86588631
<MixedArgument>
8659-
<code><![CDATA[$GLOBALS['ldi_columns']]]></code>
8660-
<code><![CDATA[$GLOBALS['ldi_enclosed']]]></code>
8661-
<code><![CDATA[$GLOBALS['ldi_escaped']]]></code>
86628632
<code><![CDATA[ImportSettings::$importFile]]></code>
86638633
</MixedArgument>
8664-
<MixedAssignment>
8665-
<code><![CDATA[$GLOBALS['ldi_columns']]]></code>
8666-
<code><![CDATA[$GLOBALS['ldi_enclosed']]]></code>
8667-
<code><![CDATA[$GLOBALS['ldi_escaped']]]></code>
8668-
<code><![CDATA[$GLOBALS['ldi_ignore']]]></code>
8669-
<code><![CDATA[$GLOBALS['ldi_local_option']]]></code>
8670-
<code><![CDATA[$GLOBALS['ldi_new_line']]]></code>
8671-
<code><![CDATA[$GLOBALS['ldi_replace']]]></code>
8672-
<code><![CDATA[$GLOBALS['ldi_terminated']]]></code>
8673-
</MixedAssignment>
8674-
<MixedOperand>
8675-
<code><![CDATA[$GLOBALS['ldi_new_line']]]></code>
8676-
<code><![CDATA[$GLOBALS['ldi_terminated']]]></code>
8677-
</MixedOperand>
8678-
<PossiblyNullArgument>
8679-
<code><![CDATA[$GLOBALS['ldi_columns']]]></code>
8680-
<code><![CDATA[$GLOBALS['ldi_enclosed']]]></code>
8681-
<code><![CDATA[$GLOBALS['ldi_escaped']]]></code>
8682-
</PossiblyNullArgument>
86838634
<PossiblyUnusedReturnValue>
86848635
<code><![CDATA[string[]]]></code>
86858636
</PossiblyUnusedReturnValue>
@@ -10119,13 +10070,7 @@
1011910070
<code><![CDATA[$initials]]></code>
1012010071
</InvalidArgument>
1012110072
<InvalidArrayOffset>
10122-
<code><![CDATA[$GLOBALS['Grant_priv']]]></code>
10123-
<code><![CDATA[$GLOBALS['Grant_priv']]]></code>
1012410073
<code><![CDATA[$GLOBALS['dbname']]]></code>
10125-
<code><![CDATA[$GLOBALS['max_connections']]]></code>
10126-
<code><![CDATA[$GLOBALS['max_questions']]]></code>
10127-
<code><![CDATA[$GLOBALS['max_updates']]]></code>
10128-
<code><![CDATA[$GLOBALS['max_user_connections']]]></code>
1012910074
<code><![CDATA[$GLOBALS['new_username']]]></code>
1013010075
<code><![CDATA[$GLOBALS['pred_hostname']]]></code>
1013110076
<code><![CDATA[$GLOBALS['pred_username']]]></code>

‎src/Controllers/Import/ImportController.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ public function __invoke(ServerRequest $request): void
195195
return;
196196
}
197197

198-
$postPatterns = ['/^' . $format . '_/'];
199-
Core::setPostAsGlobal($postPatterns);
200-
201198
if (Current::$table !== '' && Current::$database !== '') {
202199
$GLOBALS['urlParams'] = ['db' => Current::$database, 'table' => Current::$table];
203200
} elseif (Current::$database !== '') {
@@ -485,6 +482,8 @@ public function __invoke(ServerRequest $request): void
485482
if (! $GLOBALS['error']) {
486483
$importPlugin = new ($importFormat->getClassName());
487484

485+
$importPlugin->setImportOptions($request);
486+
488487
// Do the real import
489488
$defaultFkCheck = ForeignKey::handleDisableCheckInit();
490489
try {

‎src/Controllers/Server/PrivilegesController.php‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpMyAdmin\ConfigStorage\Relation;
88
use PhpMyAdmin\ConfigStorage\RelationCleanup;
99
use PhpMyAdmin\Controllers\AbstractController;
10-
use PhpMyAdmin\Core;
1110
use PhpMyAdmin\DatabaseInterface;
1211
use PhpMyAdmin\Html\Generator;
1312
use PhpMyAdmin\Http\ServerRequest;
@@ -75,11 +74,6 @@ public function __invoke(ServerRequest $request): void
7574
]);
7675
}
7776

78-
/**
79-
* Sets globals from $_POST patterns, for privileges and max_* vars
80-
*/
81-
Core::setPostAsGlobal(['/_priv$/i', '/^max_/i']);
82-
8377
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
8478

8579
if ($this->dbi->isSuperUser()) {

‎src/Core.php‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpMyAdmin\Http\ServerRequest;
1010

1111
use function __;
12-
use function array_keys;
1312
use function array_pop;
1413
use function array_walk_recursive;
1514
use function chr;
@@ -534,24 +533,6 @@ static function ($item) use (&$empty): void {
534533
return empty($value);
535534
}
536535

537-
/**
538-
* Creates some globals from $_POST variables matching a pattern
539-
*
540-
* @param mixed[] $postPatterns The patterns to search for
541-
*/
542-
public static function setPostAsGlobal(array $postPatterns): void
543-
{
544-
foreach (array_keys($_POST) as $postKey) {
545-
foreach ($postPatterns as $onePostPattern) {
546-
if (! preg_match($onePostPattern, $postKey)) {
547-
continue;
548-
}
549-
550-
$GLOBALS[$postKey] = $_POST[$postKey];
551-
}
552-
}
553-
}
554-
555536
/**
556537
* Gets the "true" IP address of the current user
557538
*

0 commit comments

Comments
 (0)