Skip to content

Commit 57aa981

Browse files
Merge pull request #18979 from kamil-tekiela/GLOBALS-tables
Globals tables
2 parents 21e7c86 + 3b997cf commit 57aa981

7 files changed

Lines changed: 48 additions & 128 deletions

File tree

phpstan-baseline.neon

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,16 +1785,6 @@ parameters:
17851785
count: 1
17861786
path: src/Controllers/Database/EventsController.php
17871787

1788-
-
1789-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
1790-
count: 1
1791-
path: src/Controllers/Database/ExportController.php
1792-
1793-
-
1794-
message: "#^Cannot access offset 'Name' on mixed\\.$#"
1795-
count: 5
1796-
path: src/Controllers/Database/ExportController.php
1797-
17981788
-
17991789
message: "#^Cannot access offset 'goto' on mixed\\.$#"
18001790
count: 1
@@ -1805,11 +1795,6 @@ parameters:
18051795
count: 2
18061796
path: src/Controllers/Database/ExportController.php
18071797

1808-
-
1809-
message: "#^Parameter \\#1 \\$key of method PhpMyAdmin\\\\Export\\\\Export\\:\\:getCheckedClause\\(\\) expects string, mixed given\\.$#"
1810-
count: 4
1811-
path: src/Controllers/Database/ExportController.php
1812-
18131798
-
18141799
message: "#^Parameter \\#2 \\$array of method PhpMyAdmin\\\\Export\\\\Export\\:\\:getCheckedClause\\(\\) expects array, mixed given\\.$#"
18151800
count: 1
@@ -2395,11 +2380,6 @@ parameters:
23952380
count: 1
23962381
path: src/Controllers/Export/ExportController.php
23972382

2398-
-
2399-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
2400-
count: 1
2401-
path: src/Controllers/Export/ExportController.php
2402-
24032383
-
24042384
message: "#^Parameter \\#1 \\$whatStrucOrData of static method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportRaw\\(\\) expects string, mixed given\\.$#"
24052385
count: 1
@@ -2450,16 +2430,6 @@ parameters:
24502430
count: 1
24512431
path: src/Controllers/Export/ExportController.php
24522432

2453-
-
2454-
message: "#^Parameter \\#2 \\$tables of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportDatabase\\(\\) expects array\\<string\\>, mixed given\\.$#"
2455-
count: 2
2456-
path: src/Controllers/Export/ExportController.php
2457-
2458-
-
2459-
message: "#^Parameter \\#2 \\$tables of method PhpMyAdmin\\\\Export\\\\Export\\:\\:lockTables\\(\\) expects array, mixed given\\.$#"
2460-
count: 1
2461-
path: src/Controllers/Export/ExportController.php
2462-
24632433
-
24642434
message: "#^Parameter \\#2 \\$whatStrucOrData of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportServer\\(\\) expects string, mixed given\\.$#"
24652435
count: 1
@@ -2511,7 +2481,7 @@ parameters:
25112481
path: src/Controllers/Export/ExportController.php
25122482

25132483
-
2514-
message: "#^Parameter \\#4 \\$tableStructure of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportDatabase\\(\\) expects array\\<string\\>, mixed given\\.$#"
2484+
message: "#^Parameter \\#4 \\$tableStructure of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportDatabase\\(\\) expects array\\<string\\>, array given\\.$#"
25152485
count: 2
25162486
path: src/Controllers/Export/ExportController.php
25172487

@@ -2531,7 +2501,7 @@ parameters:
25312501
path: src/Controllers/Export/ExportController.php
25322502

25332503
-
2534-
message: "#^Parameter \\#5 \\$tableData of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportDatabase\\(\\) expects array\\<string\\>, mixed given\\.$#"
2504+
message: "#^Parameter \\#5 \\$tableData of method PhpMyAdmin\\\\Export\\\\Export\\:\\:exportDatabase\\(\\) expects array\\<string\\>, array given\\.$#"
25352505
count: 2
25362506
path: src/Controllers/Export/ExportController.php
25372507

@@ -11285,31 +11255,16 @@ parameters:
1128511255
count: 1
1128611256
path: src/Plugins/Export/ExportXml.php
1128711257

11288-
-
11289-
message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#"
11290-
count: 1
11291-
path: src/Plugins/Export/ExportXml.php
11292-
1129311258
-
1129411259
message: "#^Parameter \\#1 \\$string of function htmlspecialchars expects string, mixed given\\.$#"
11295-
count: 6
11296-
path: src/Plugins/Export/ExportXml.php
11297-
11298-
-
11299-
message: "#^Parameter \\#2 \\$tableName of method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTable\\(\\) expects string, mixed given\\.$#"
11300-
count: 1
11260+
count: 5
1130111261
path: src/Plugins/Export/ExportXml.php
1130211262

1130311263
-
1130411264
message: "#^Parameter \\#3 \\$names of method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportXml\\:\\:exportDefinitions\\(\\) expects array\\<string\\>, array given\\.$#"
1130511265
count: 1
1130611266
path: src/Plugins/Export/ExportXml.php
1130711267

11308-
-
11309-
message: "#^Parameter \\#3 \\$table of static method PhpMyAdmin\\\\Triggers\\\\Triggers\\:\\:getDetails\\(\\) expects string, mixed given\\.$#"
11310-
count: 1
11311-
path: src/Plugins/Export/ExportXml.php
11312-
1131311268
-
1131411269
message: "#^Cannot access offset 'columns' on mixed\\.$#"
1131511270
count: 1

psalm-baseline.xml

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,32 +1105,18 @@
11051105
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
11061106
<code><![CDATA[$GLOBALS['single_table']]]></code>
11071107
<code><![CDATA[$GLOBALS['table_select']]]></code>
1108-
<code><![CDATA[$GLOBALS['tables']]]></code>
11091108
<code><![CDATA[$GLOBALS['unlim_num_rows']]]></code>
11101109
</InvalidArrayOffset>
11111110
<MixedArgument>
11121111
<code><![CDATA[$GLOBALS['table_select']]]></code>
11131112
<code><![CDATA[$GLOBALS['unlim_num_rows']]]></code>
1114-
<code><![CDATA[$eachTable['Name']]]></code>
1115-
<code><![CDATA[$eachTable['Name']]]></code>
1116-
<code><![CDATA[$eachTable['Name']]]></code>
1117-
<code><![CDATA[$eachTable['Name']]]></code>
11181113
</MixedArgument>
1119-
<MixedArrayAccess>
1120-
<code><![CDATA[$eachTable['Name']]]></code>
1121-
<code><![CDATA[$eachTable['Name']]]></code>
1122-
<code><![CDATA[$eachTable['Name']]]></code>
1123-
<code><![CDATA[$eachTable['Name']]]></code>
1124-
<code><![CDATA[$eachTable['Name']]]></code>
1125-
</MixedArrayAccess>
11261114
<MixedAssignment>
11271115
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
11281116
<code><![CDATA[$GLOBALS['single_table']]]></code>
11291117
<code><![CDATA[$GLOBALS['table_select']]]></code>
11301118
<code><![CDATA[$GLOBALS['table_select']]]></code>
1131-
<code><![CDATA[$GLOBALS['tables']]]></code>
11321119
<code><![CDATA[$GLOBALS['unlim_num_rows']]]></code>
1133-
<code>$eachTable</code>
11341120
<code>$selectedTable</code>
11351121
<code>$tableData</code>
11361122
<code>$tableSelect</code>
@@ -1688,7 +1674,6 @@
16881674
<code><![CDATA[$GLOBALS['single_table']]]></code>
16891675
<code><![CDATA[$GLOBALS['table_data']]]></code>
16901676
<code><![CDATA[$GLOBALS['table_select']]]></code>
1691-
<code><![CDATA[$GLOBALS['tables']]]></code>
16921677
<code><![CDATA[$GLOBALS['time_start']]]></code>
16931678
<code><![CDATA[$GLOBALS['what']]]></code>
16941679
</InvalidArrayOffset>
@@ -1700,12 +1685,6 @@
17001685
<code><![CDATA[$GLOBALS['export_type']]]></code>
17011686
<code><![CDATA[$GLOBALS['export_type']]]></code>
17021687
<code><![CDATA[$GLOBALS['export_type']]]></code>
1703-
<code><![CDATA[$GLOBALS['table_data']]]></code>
1704-
<code><![CDATA[$GLOBALS['table_data']]]></code>
1705-
<code><![CDATA[$GLOBALS['tables']]]></code>
1706-
<code><![CDATA[$GLOBALS['tables']]]></code>
1707-
<code><![CDATA[$GLOBALS['tables']]]></code>
1708-
<code><![CDATA[$GLOBALS['tables']]]></code>
17091688
<code>$allrows</code>
17101689
<code>$allrows</code>
17111690
<code>$dbSelect</code>
@@ -1715,15 +1694,19 @@
17151694
<code>$limitTo</code>
17161695
<code>$rememberTemplate</code>
17171696
<code><![CDATA[$request->getParsedBodyParam('filename_template')]]></code>
1718-
<code>$tableStructure</code>
1719-
<code>$tableStructure</code>
17201697
<code>$whatStrucOrData</code>
17211698
<code>$whatStrucOrData</code>
17221699
<code>$whatStrucOrData</code>
17231700
<code>$whatStrucOrData</code>
17241701
<code>$whatStrucOrData</code>
17251702
<code>$whatStrucOrData</code>
17261703
</MixedArgument>
1704+
<MixedArgumentTypeCoercion>
1705+
<code><![CDATA[$GLOBALS['table_data']]]></code>
1706+
<code><![CDATA[$GLOBALS['table_data']]]></code>
1707+
<code>$tableStructure</code>
1708+
<code>$tableStructure</code>
1709+
</MixedArgumentTypeCoercion>
17271710
<MixedArrayAssignment>
17281711
<code><![CDATA[$_SESSION['tmpval']['aliases']]]></code>
17291712
</MixedArrayAssignment>
@@ -1819,11 +1802,8 @@
18191802
<code><![CDATA[$GLOBALS['sql_views_as_tables']]]></code>
18201803
<code><![CDATA[$GLOBALS['table_data']]]></code>
18211804
<code><![CDATA[$GLOBALS['table_data']]]></code>
1822-
<code><![CDATA[$GLOBALS['table_data']]]></code>
18231805
<code><![CDATA[$GLOBALS['table_select']]]></code>
18241806
<code><![CDATA[$GLOBALS['table_select']]]></code>
1825-
<code><![CDATA[$GLOBALS['tables']]]></code>
1826-
<code><![CDATA[$GLOBALS['tables']]]></code>
18271807
<code><![CDATA[$GLOBALS['texytext_columns']]]></code>
18281808
<code><![CDATA[$GLOBALS['texytext_null']]]></code>
18291809
<code><![CDATA[$GLOBALS['texytext_structure_or_data']]]></code>
@@ -1844,7 +1824,7 @@
18441824
<code>$limitFrom</code>
18451825
<code>$limitTo</code>
18461826
<code>$rememberTemplate</code>
1847-
<code>$tableStructure</code>
1827+
<code>$tableNames</code>
18481828
<code>$tableStructure</code>
18491829
<code>$whatStrucOrData</code>
18501830
</MixedAssignment>
@@ -8578,7 +8558,6 @@
85788558
<code>DatabaseInterface::getInstance()</code>
85798559
</DeprecatedMethod>
85808560
<InvalidArrayOffset>
8581-
<code><![CDATA[$GLOBALS['tables']]]></code>
85828561
<code><![CDATA[$GLOBALS['xml_export_contents']]]></code>
85838562
<code><![CDATA[$GLOBALS['xml_export_contents']]]></code>
85848563
<code><![CDATA[$GLOBALS['xml_export_contents']]]></code>
@@ -8595,7 +8574,6 @@
85958574
<code>$colAs</code>
85968575
<code>$dbCharset</code>
85978576
<code>$dbCollation</code>
8598-
<code>$table</code>
85998577
</MixedArgument>
86008578
<MixedArgumentTypeCoercion>
86018579
<code>$events</code>
@@ -8606,20 +8584,10 @@
86068584
<code><![CDATA[$result[0]['DEFAULT_COLLATION_NAME']]]></code>
86078585
</MixedArrayAccess>
86088586
<MixedAssignment>
8609-
<code><![CDATA[$GLOBALS['tables']]]></code>
86108587
<code>$colAs</code>
86118588
<code>$dbCharset</code>
86128589
<code>$dbCollation</code>
8613-
<code>$table</code>
86148590
</MixedAssignment>
8615-
<PossiblyInvalidArgument>
8616-
<code>$table</code>
8617-
<code>$table</code>
8618-
<code>$table</code>
8619-
</PossiblyInvalidArgument>
8620-
<PossiblyInvalidArrayOffset>
8621-
<code>$result[$table]</code>
8622-
</PossiblyInvalidArrayOffset>
86238591
<PossiblyNullArgument>
86248592
<code>$record[$i]</code>
86258593
<code>$tableAlias</code>

src/Controllers/Database/ExportController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function __construct(
4141
public function __invoke(ServerRequest $request): void
4242
{
4343
$GLOBALS['urlParams'] ??= null;
44-
$GLOBALS['tables'] ??= null;
4544
$GLOBALS['table_select'] ??= null;
4645
$GLOBALS['unlim_num_rows'] ??= null;
4746
$GLOBALS['errorUrl'] ??= null;
@@ -78,8 +77,8 @@ public function __invoke(ServerRequest $request): void
7877

7978
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/export');
8079

81-
[$GLOBALS['tables']] = Util::getDbInfo($request, Current::$database, false);
82-
$GLOBALS['num_tables'] = count($GLOBALS['tables']);
80+
$tableNames = $this->export->getTableNames(Current::$database);
81+
$GLOBALS['num_tables'] = count($tableNames);
8382

8483
// exit if no tables in db found
8584
if ($GLOBALS['num_tables'] < 1) {
@@ -97,32 +96,32 @@ public function __invoke(ServerRequest $request): void
9796

9897
$tablesForMultiValues = [];
9998

100-
foreach ($GLOBALS['tables'] as $eachTable) {
99+
foreach ($tableNames as $tableName) {
101100
$tableSelect = $request->getParsedBodyParam('table_select');
102101
if (is_array($tableSelect)) {
103-
$isChecked = $this->export->getCheckedClause($eachTable['Name'], $tableSelect);
102+
$isChecked = $this->export->getCheckedClause($tableName, $tableSelect);
104103
} elseif (isset($GLOBALS['table_select'])) {
105-
$isChecked = $this->export->getCheckedClause($eachTable['Name'], $GLOBALS['table_select']);
104+
$isChecked = $this->export->getCheckedClause($tableName, $GLOBALS['table_select']);
106105
} else {
107106
$isChecked = true;
108107
}
109108

110109
$tableStructure = $request->getParsedBodyParam('table_structure');
111110
if (is_array($tableStructure)) {
112-
$structureChecked = $this->export->getCheckedClause($eachTable['Name'], $tableStructure);
111+
$structureChecked = $this->export->getCheckedClause($tableName, $tableStructure);
113112
} else {
114113
$structureChecked = $isChecked;
115114
}
116115

117116
$tableData = $request->getParsedBodyParam('table_data');
118117
if (is_array($tableData)) {
119-
$dataChecked = $this->export->getCheckedClause($eachTable['Name'], $tableData);
118+
$dataChecked = $this->export->getCheckedClause($tableName, $tableData);
120119
} else {
121120
$dataChecked = $isChecked;
122121
}
123122

124123
$tablesForMultiValues[] = [
125-
'name' => $eachTable['Name'],
124+
'name' => $tableName,
126125
'is_checked_select' => $isChecked,
127126
'is_checked_structure' => $structureChecked,
128127
'is_checked_data' => $dataChecked,

src/Controllers/Export/ExportController.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
use PhpMyAdmin\Message;
1919
use PhpMyAdmin\Plugins;
2020
use PhpMyAdmin\Plugins\Export\ExportSql;
21+
use PhpMyAdmin\Plugins\Export\ExportXml;
2122
use PhpMyAdmin\ResponseRenderer;
2223
use PhpMyAdmin\Sanitize;
2324
use PhpMyAdmin\SqlParser\Parser;
2425
use PhpMyAdmin\SqlParser\Statements\SelectStatement;
2526
use PhpMyAdmin\Template;
2627
use PhpMyAdmin\Url;
2728
use PhpMyAdmin\Util;
29+
use Webmozart\Assert\Assert;
2830

2931
use function __;
3032
use function count;
@@ -57,7 +59,6 @@ public function __invoke(ServerRequest $request): void
5759
$GLOBALS['what'] ??= null;
5860
$GLOBALS['single_table'] ??= null;
5961
$GLOBALS['save_filename'] ??= null;
60-
$GLOBALS['tables'] ??= null;
6162
$GLOBALS['table_select'] ??= null;
6263
$GLOBALS['time_start'] ??= null;
6364
$GLOBALS['charset'] ??= null;
@@ -172,14 +173,16 @@ public function __invoke(ServerRequest $request): void
172173
$this->response->disable();
173174
}
174175

175-
$GLOBALS['tables'] = [];
176+
$tableNames = [];
176177
// Generate error url and check for needed variables
177178
if ($GLOBALS['export_type'] === 'server') {
178179
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/export');
179180
} elseif ($GLOBALS['export_type'] === 'database' && Current::$database !== '') {
180181
$GLOBALS['errorUrl'] = Url::getFromRoute('/database/export', ['db' => Current::$database]);
181182
// Check if we have something to export
182-
$GLOBALS['tables'] = $GLOBALS['table_select'] ?? [];
183+
$tableNames = $GLOBALS['table_select'] ?? [];
184+
Assert::isArray($tableNames);
185+
Assert::allString($tableNames);
183186
} elseif ($GLOBALS['export_type'] === 'table' && Current::$database !== '' && Current::$table !== '') {
184187
$GLOBALS['errorUrl'] = Url::getFromRoute('/table/export', [
185188
'db' => Current::$database,
@@ -294,7 +297,7 @@ public function __invoke(ServerRequest $request): void
294297
} else {
295298
// HTML
296299
if ($GLOBALS['export_type'] === 'database') {
297-
$GLOBALS['num_tables'] = count($GLOBALS['tables']);
300+
$GLOBALS['num_tables'] = count($tableNames);
298301
if ($GLOBALS['num_tables'] === 0) {
299302
$GLOBALS['message'] = Message::error(
300303
__('No tables found in database.'),
@@ -319,6 +322,11 @@ public function __invoke(ServerRequest $request): void
319322
$this->export->dumpBuffer = '';
320323
$this->export->dumpBufferLength = 0;
321324

325+
// TODO: This is a temporary hack to avoid GLOBALS. Replace this with something better.
326+
if ($exportPlugin instanceof ExportXml) {
327+
$exportPlugin->setTables($tableNames);
328+
}
329+
322330
// Add possibly some comments to export
323331
if (! $exportPlugin->exportHeader()) {
324332
throw new ExportException('Failure during header export.');
@@ -370,16 +378,16 @@ public function __invoke(ServerRequest $request): void
370378
}
371379

372380
if ($structureOrDataForced) {
373-
$tableStructure = $GLOBALS['tables'];
374-
$GLOBALS['table_data'] = $GLOBALS['tables'];
381+
$tableStructure = $tableNames;
382+
$GLOBALS['table_data'] = $tableNames;
375383
}
376384

377385
if ($lockTables) {
378-
$this->export->lockTables(DatabaseName::from(Current::$database), $GLOBALS['tables'], 'READ');
386+
$this->export->lockTables(DatabaseName::from(Current::$database), $tableNames, 'READ');
379387
try {
380388
$this->export->exportDatabase(
381389
DatabaseName::from(Current::$database),
382-
$GLOBALS['tables'],
390+
$tableNames,
383391
$whatStrucOrData,
384392
$tableStructure,
385393
$GLOBALS['table_data'],
@@ -399,7 +407,7 @@ public function __invoke(ServerRequest $request): void
399407
} else {
400408
$this->export->exportDatabase(
401409
DatabaseName::from(Current::$database),
402-
$GLOBALS['tables'],
410+
$tableNames,
403411
$whatStrucOrData,
404412
$tableStructure,
405413
$GLOBALS['table_data'],

0 commit comments

Comments
 (0)