Skip to content

Commit 0eab757

Browse files
committed
Merge #20266 - Fix #20041 - Fix export for raw queries without table reference
Pull-request: #20266 Fixes: #20041 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents cea7654 + fb391a9 commit 0eab757

5 files changed

Lines changed: 42 additions & 16 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15054,7 +15054,7 @@ parameters:
1505415054
Use dependency injection instead\.$#
1505515055
'''
1505615056
identifier: staticMethod.deprecated
15057-
count: 1
15057+
count: 2
1505815058
path: tests/unit/Controllers/Table/ExportControllerTest.php
1505915059

1506015060
-

psalm-baseline.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,24 +2128,12 @@
21282128
</RiskyTruthyFalsyComparison>
21292129
</file>
21302130
<file src="src/Controllers/Table/ExportController.php">
2131-
<MixedArgument>
2132-
<code><![CDATA[Current::$database]]></code>
2133-
<code><![CDATA[Current::$table]]></code>
2134-
</MixedArgument>
21352131
<MixedArgumentTypeCoercion>
21362132
<code><![CDATA[Current::$whereClause]]></code>
21372133
</MixedArgumentTypeCoercion>
2138-
<MixedPropertyTypeCoercion>
2139-
<code><![CDATA[UrlParams::$params]]></code>
2140-
<code><![CDATA[UrlParams::$params]]></code>
2141-
<code><![CDATA[['db' => Current::$database, 'table' => Current::$table]]]></code>
2142-
</MixedPropertyTypeCoercion>
21432134
<PossiblyNullArgument>
21442135
<code><![CDATA[$parser->list]]></code>
21452136
</PossiblyNullArgument>
2146-
<PossiblyUnusedReturnValue>
2147-
<code><![CDATA[Response]]></code>
2148-
</PossiblyUnusedReturnValue>
21492137
</file>
21502138
<file src="src/Controllers/Table/ExportRowsController.php">
21512139
<InvalidPropertyAssignmentValue>
@@ -9431,6 +9419,7 @@
94319419
<file src="tests/unit/Controllers/Table/ExportControllerTest.php">
94329420
<DeprecatedMethod>
94339421
<code><![CDATA[Config::getInstance()]]></code>
9422+
<code><![CDATA[Config::getInstance()]]></code>
94349423
</DeprecatedMethod>
94359424
</file>
94369425
<file src="tests/unit/Controllers/Table/ImportControllerTest.php">

src/Controllers/Table/ExportController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ public function __invoke(ServerRequest $request): Response
4545

4646
$this->response->addScriptFiles(['export.js']);
4747

48-
if (Current::$database === '') {
48+
$isRawQuery = $request->has('raw_query');
49+
50+
if (Current::$database === '' && ! $isRawQuery) {
4951
return $this->response->missingParameterError('db');
5052
}
5153

52-
if (Current::$table === '') {
54+
if (Current::$table === '' && ! $isRawQuery) {
5355
return $this->response->missingParameterError('table');
5456
}
5557

src/Display/Results.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3457,7 +3457,7 @@ private function getResultsOperations(
34573457
* first table of this database, so that /table/export and
34583458
* the script it calls do not fail
34593459
*/
3460-
if ($urlParams['table'] === '' && $urlParams['db'] !== '') {
3460+
if (! isset($urlParams['raw_query']) && $urlParams['table'] === '' && $urlParams['db'] !== '') {
34613461
$urlParams['table'] = (string) $this->dbi->fetchValue('SHOW TABLES');
34623462
}
34633463

tests/unit/Controllers/Table/ExportControllerTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,39 @@ public function testExportController(): void
124124
(new ExportController($response, $options, $pageSettings))(self::createStub(ServerRequest::class));
125125
self::assertSame($expected, $response->getHTMLResult());
126126
}
127+
128+
public function testExportControllerWithRawQuery(): void
129+
{
130+
Current::$database = '';
131+
Current::$table = '';
132+
Current::$sqlQuery = 'SELECT 1 as foo';
133+
$config = Config::getInstance();
134+
$config->selectedServer = $config->getSettings()->Servers[1]->asArray();
135+
136+
$dbi = $this->createDatabaseInterface();
137+
DatabaseInterface::$instance = $dbi;
138+
139+
$response = new ResponseRenderer();
140+
$relation = new Relation($dbi, $config);
141+
$template = new Template($config);
142+
$userPreferences = new UserPreferences($dbi, $relation, $template, $config, new Clock());
143+
$pageSettings = new PageSettings($userPreferences, $response);
144+
145+
$userPreferencesHandler = new UserPreferencesHandler(
146+
$config,
147+
$dbi,
148+
$userPreferences,
149+
new LanguageManager($config),
150+
new ThemeManager(),
151+
);
152+
$options = new Options($relation, new TemplateModel($dbi), $userPreferencesHandler);
153+
154+
$request = self::createStub(ServerRequest::class);
155+
$request->method('has')->willReturnMap([['raw_query', true], ['single_table', false]]);
156+
157+
$result = (new ExportController($response, $options, $pageSettings))($request);
158+
159+
// Should return 200 instead of 400 for missing db/table params
160+
self::assertSame(200, $result->getStatusCode());
161+
}
127162
}

0 commit comments

Comments
 (0)