diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-11 06:57:24 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-11 06:57:24 +0300 |
commit | b62062b3aa7379e54374b1bd9ff3a829a928c09c (patch) | |
tree | ca737c2f503e1e95f1ca4ca380adb5ed74cec556 /libraries | |
parent | aeb237f629527c74a9a3f50a88fa03cfd398e6c7 (diff) |
Refactor Export::processExportSchema() to use DatabaseName object
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Controllers/SchemaExportController.php | 14 | ||||
-rw-r--r-- | libraries/classes/Export.php | 15 |
2 files changed, 15 insertions, 14 deletions
diff --git a/libraries/classes/Controllers/SchemaExportController.php b/libraries/classes/Controllers/SchemaExportController.php index 7a9d26b726..3a935fe7f2 100644 --- a/libraries/classes/Controllers/SchemaExportController.php +++ b/libraries/classes/Controllers/SchemaExportController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers; +use PhpMyAdmin\Dbal\DatabaseName; use PhpMyAdmin\Export; use PhpMyAdmin\Html\MySQLDocumentation; use PhpMyAdmin\Http\ServerRequest; @@ -12,6 +13,7 @@ use PhpMyAdmin\ResponseRenderer; use RuntimeException; use function __; +use function is_string; /** * Schema export handler @@ -32,8 +34,11 @@ class SchemaExportController public function __invoke(ServerRequest $request): void { - if (! $request->hasBodyParam('export_type')) { - $errorMessage = __('Missing parameter:') . ' export_type' + $db = DatabaseName::tryFromValue($request->getParsedBodyParam('db')); + /** @var mixed $exportType */ + $exportType = $request->getParsedBodyParam('export_type'); + if ($db === null || ! is_string($exportType) || $exportType === '') { + $errorMessage = __('Missing parameter:') . ($db === null ? ' db' : ' export_type') . MySQLDocumentation::showDocumentation('faq', 'faqmissingparameters', true) . '[br]'; $this->response->setRequestStatus(false); @@ -43,11 +48,10 @@ class SchemaExportController } /** - * Include the appropriate Schema Class depending on $export_type - * default is PDF + * Include the appropriate Schema Class depending on $exportType, default is PDF. */ try { - $this->export->processExportSchema($request->getParsedBodyParam('export_type')); + $this->export->processExportSchema($db, $exportType); } catch (RuntimeException $exception) { $this->response->setRequestStatus(false); $this->response->addHTML(Message::error($exception->getMessage())->getDisplay()); diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 166ced3026..ed1418fd3f 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -1240,22 +1240,19 @@ class Export * get all the export options and verify * call and include the appropriate Schema Class depending on $export_type * - * @param string|null $exportType format of the export + * @param non-empty-string $exportType format of the export */ - public function processExportSchema(?string $exportType): void + public function processExportSchema(DatabaseName $db, string $exportType): void { /** * default is PDF, otherwise validate it's only letters a-z */ - if (! isset($exportType) || ! preg_match('/^[a-zA-Z]+$/', $exportType)) { + if (! preg_match('/^[a-zA-Z]+$/', $exportType)) { $exportType = 'pdf'; } - // sanitize this parameter which will be used below in a file inclusion - $exportType = Core::securePath($exportType); - // get the specific plugin - /** @var SchemaPlugin $exportPlugin */ + /** @var SchemaPlugin|null $exportPlugin */ $exportPlugin = Plugins::getPlugin('schema', $exportType); // Check schema export type @@ -1263,8 +1260,8 @@ class Export throw new RuntimeException(__('Bad type!')); } - $this->dbi->selectDb($_POST['db']); - $exportPlugin->exportSchema($_POST['db']); + $this->dbi->selectDb($db); + $exportPlugin->exportSchema($db->getName()); } private function getHTMLForRefreshButton(string $exportType): string |