Fix #20041 - Fix export for raw queries without table reference
Signed-off-by: Nicolai Ehrhardt <245527909+predictor2718@users.noreply.github.com>
This commit is contained in:
parent
bd94fa9f11
commit
bcaf89c19f
@ -15054,7 +15054,7 @@ parameters:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 1
|
||||
count: 2
|
||||
path: tests/unit/Controllers/Table/ExportControllerTest.php
|
||||
|
||||
-
|
||||
|
||||
@ -45,11 +45,13 @@ readonly class ExportController implements InvocableController
|
||||
|
||||
$this->response->addScriptFiles(['export.js']);
|
||||
|
||||
if (Current::$database === '') {
|
||||
$isRawQuery = $request->has('raw_query');
|
||||
|
||||
if (Current::$database === '' && ! $isRawQuery) {
|
||||
return $this->response->missingParameterError('db');
|
||||
}
|
||||
|
||||
if (Current::$table === '') {
|
||||
if (Current::$table === '' && ! $isRawQuery) {
|
||||
return $this->response->missingParameterError('table');
|
||||
}
|
||||
|
||||
|
||||
@ -3457,7 +3457,7 @@ class Results
|
||||
* first table of this database, so that /table/export and
|
||||
* the script it calls do not fail
|
||||
*/
|
||||
if ($urlParams['table'] === '' && $urlParams['db'] !== '') {
|
||||
if (! isset($urlParams['raw_query']) && $urlParams['table'] === '' && $urlParams['db'] !== '') {
|
||||
$urlParams['table'] = (string) $this->dbi->fetchValue('SHOW TABLES');
|
||||
}
|
||||
|
||||
|
||||
@ -124,4 +124,39 @@ class ExportControllerTest extends AbstractTestCase
|
||||
(new ExportController($response, $options, $pageSettings))(self::createStub(ServerRequest::class));
|
||||
self::assertSame($expected, $response->getHTMLResult());
|
||||
}
|
||||
|
||||
public function testExportControllerWithRawQuery(): void
|
||||
{
|
||||
Current::$database = '';
|
||||
Current::$table = '';
|
||||
Current::$sqlQuery = 'SELECT 1 as foo';
|
||||
$config = Config::getInstance();
|
||||
$config->selectedServer = $config->getSettings()->Servers[1]->asArray();
|
||||
|
||||
$dbi = $this->createDatabaseInterface();
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
|
||||
$response = new ResponseRenderer();
|
||||
$relation = new Relation($dbi, $config);
|
||||
$template = new Template($config);
|
||||
$userPreferences = new UserPreferences($dbi, $relation, $template, $config, new Clock());
|
||||
$pageSettings = new PageSettings($userPreferences, $response);
|
||||
|
||||
$userPreferencesHandler = new UserPreferencesHandler(
|
||||
$config,
|
||||
$dbi,
|
||||
$userPreferences,
|
||||
new LanguageManager($config),
|
||||
new ThemeManager(),
|
||||
);
|
||||
$options = new Options($relation, new TemplateModel($dbi), $userPreferencesHandler);
|
||||
|
||||
$request = self::createStub(ServerRequest::class);
|
||||
$request->method('has')->willReturnMap([['raw_query', true], ['single_table', false]]);
|
||||
|
||||
$result = (new ExportController($response, $options, $pageSettings))($request);
|
||||
|
||||
// Should return 200 instead of 400 for missing db/table params
|
||||
self::assertSame(200, $result->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user