diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 69172b86bf..c4a04c1246 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2832,24 +2832,6 @@ parameters: count: 1 path: src/Controllers/Export/ExportController.php - - - message: '#^Parameter \#1 \$exportType of method PhpMyAdmin\\Export\\Export\:\:getHtmlForDisplayedExportFooter\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Export/ExportController.php - - - - message: '#^Parameter \#1 \$exportType of method PhpMyAdmin\\Export\\Export\:\:getHtmlForDisplayedExportHeader\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Export/ExportController.php - - - - message: '#^Parameter \#1 \$exportType of method PhpMyAdmin\\Export\\Export\:\:getPageLocationAndSaveMessage\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 3 - path: src/Controllers/Export/ExportController.php - - message: '#^Parameter \#1 \$fileHandle of method PhpMyAdmin\\Export\\Export\:\:closeFile\(\) expects resource, mixed given\.$#' identifier: argument.type @@ -2880,12 +2862,6 @@ parameters: count: 1 path: src/Controllers/Export/ExportController.php - - - message: '#^Parameter \#2 \$exportType of method PhpMyAdmin\\Export\\Export\:\:rememberFilename\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Export/ExportController.php - - message: '#^Parameter \#3 \$saveFilename of method PhpMyAdmin\\Export\\Export\:\:closeFile\(\) expects string, mixed given\.$#' identifier: argument.type @@ -2898,24 +2874,12 @@ parameters: count: 2 path: src/Controllers/Export/ExportController.php - - - message: '#^Parameter \#5 \$exportType of method PhpMyAdmin\\Export\\Export\:\:exportTable\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Controllers/Export/ExportController.php - - message: '#^Parameter \#5 \$tableData of method PhpMyAdmin\\Export\\Export\:\:exportDatabase\(\) expects array\, array\ given\.$#' identifier: argument.type count: 2 path: src/Controllers/Export/ExportController.php - - - message: '#^Parameter \#7 \$exportType of method PhpMyAdmin\\Export\\Export\:\:exportDatabase\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Controllers/Export/ExportController.php - - message: '#^Property PhpMyAdmin\\Export\\Export\:\:\$dumpBuffer \(string\) does not accept array\|bool\|string\.$#' identifier: assign.propertyType @@ -8346,6 +8310,12 @@ parameters: count: 2 path: src/Export/Export.php + - + message: '#^Parameter \#2 \$dbAlias of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:exportDBCreate\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Export/Export.php + - message: '#^Parameter \#2 \$dbAlias of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:exportDBHeader\(\) expects string, mixed given\.$#' identifier: argument.type @@ -8364,12 +8334,6 @@ parameters: count: 1 path: src/Export/Export.php - - - message: '#^Parameter \#3 \$dbAlias of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:exportDBCreate\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Export/Export.php - - message: '#^Parameter \#3 \$kana of static method PhpMyAdmin\\Encoding\:\:kanjiStrConv\(\) expects string, mixed given\.$#' identifier: argument.type @@ -8443,13 +8407,13 @@ parameters: path: src/Export/Template.php - - message: '#^Parameter \#2 \$username of class PhpMyAdmin\\Export\\Template constructor expects string, mixed given\.$#' + message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Plugins\\ExportType\:\:from\(\) expects int\|string, mixed given\.$#' identifier: argument.type count: 1 path: src/Export/Template.php - - message: '#^Parameter \#3 \$exportType of class PhpMyAdmin\\Export\\Template constructor expects string, mixed given\.$#' + message: '#^Parameter \#2 \$username of class PhpMyAdmin\\Export\\Template constructor expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Export/Template.php @@ -12372,18 +12336,6 @@ parameters: count: 2 path: src/Plugins/Export/ExportLatex.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportLatex.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportLatex.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12426,12 +12378,6 @@ parameters: count: 1 path: src/Plugins/Export/ExportLatex.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportLatex.php - - message: '#^Parameter \#1 \$string of static method PhpMyAdmin\\Plugins\\Export\\ExportLatex\:\:texEscape\(\) expects string, mixed given\.$#' identifier: argument.type @@ -12651,18 +12597,6 @@ parameters: count: 4 path: src/Plugins/Export/ExportOdt.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportOdt.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12693,12 +12627,6 @@ parameters: count: 1 path: src/Plugins/Export/ExportOdt.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportOdt.php - - message: '#^Only booleans are allowed in an if condition, array\|false given\.$#' identifier: if.condNotBoolean @@ -12873,18 +12801,6 @@ parameters: count: 8 path: src/Plugins/Export/ExportSql.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: src/Plugins/Export/ExportSql.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: src/Plugins/Export/ExportSql.php - - message: '#^Cannot access offset ''tables'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -12993,12 +12909,6 @@ parameters: count: 6 path: src/Plugins/Export/ExportSql.php - - - message: '#^Only booleans are allowed in a negated boolean, mixed given\.$#' - identifier: booleanNot.exprNotBoolean - count: 1 - path: src/Plugins/Export/ExportSql.php - - message: '#^Only booleans are allowed in an if condition, bool\|null given\.$#' identifier: if.condNotBoolean @@ -18033,12 +17943,6 @@ parameters: count: 1 path: src/Tracking/Tracker.php - - - message: '#^Cannot cast mixed to string\.$#' - identifier: cast.string - count: 1 - path: src/Tracking/Tracker.php - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed @@ -22176,18 +22080,6 @@ parameters: count: 3 path: tests/unit/Plugins/Export/ExportLatexTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportLatexTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportLatexTest.php - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: 80, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' identifier: assign.propertyType @@ -22203,18 +22095,6 @@ parameters: count: 1 path: tests/unit/Plugins/Export/ExportOdtTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportOdtTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportOdtTest.php - - message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#' identifier: argument.type @@ -22230,18 +22110,6 @@ parameters: count: 9 path: tests/unit/Plugins/Export/ExportSqlTest.php - - - message: '#^Cannot access offset ''export_type'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: tests/unit/Plugins/Export/ExportSqlTest.php - - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 3 - path: tests/unit/Plugins/Export/ExportSqlTest.php - - message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#' identifier: argument.type @@ -22263,12 +22131,6 @@ parameters: count: 1 path: tests/unit/Plugins/Export/ExportTexytextTest.php - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: tests/unit/Plugins/Export/ExportTexytextTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: @@ -22278,12 +22140,6 @@ parameters: count: 2 path: tests/unit/Plugins/Export/ExportXmlTest.php - - - message: '#^Cannot access offset ''single_table'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: tests/unit/Plugins/Export/ExportXmlTest.php - - message: '#^Property PhpMyAdmin\\Config\:\:\$selectedServer \(array\{host\: string, port\: string, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\) does not accept array\{host\: string, port\: 80, socket\: string, ssl\: bool, ssl_key\: string\|null, ssl_cert\: string\|null, ssl_ca\: string\|null, ssl_ca_path\: string\|null, \.\.\.\}\.$#' identifier: assign.propertyType diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f7a7ee03f8..8cdb2db30f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1440,7 +1440,6 @@ - @@ -1452,11 +1451,6 @@ - - - - - @@ -1488,8 +1482,6 @@ - - @@ -1586,11 +1578,6 @@ - - - - - export->dumpBuffer]]> @@ -1600,11 +1587,6 @@ - - - - - export->dumpBuffer]]> export->dumpBuffer]]> @@ -7330,10 +7312,6 @@ - - - - @@ -7454,10 +7432,6 @@ - - - - @@ -7606,11 +7580,6 @@ - - - - - @@ -10534,9 +10503,6 @@ - - - @@ -10549,9 +10515,6 @@ - - - diff --git a/src/Controllers/Database/ExportController.php b/src/Controllers/Database/ExportController.php index 48bd8d1671..9a107466d3 100644 --- a/src/Controllers/Database/ExportController.php +++ b/src/Controllers/Database/ExportController.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Identifiers\DatabaseName; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Url; use PhpMyAdmin\UrlParams; @@ -123,9 +124,9 @@ final class ExportController implements InvocableController $isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw'; if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) { - $exportType = 'raw'; + $exportType = ExportType::Raw; } else { - $exportType = 'database'; + $exportType = ExportType::Database; } $GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null; diff --git a/src/Controllers/Export/ExportController.php b/src/Controllers/Export/ExportController.php index e5cfa09d9d..6b521cc762 100644 --- a/src/Controllers/Export/ExportController.php +++ b/src/Controllers/Export/ExportController.php @@ -22,6 +22,7 @@ use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\Export\ExportSql; use PhpMyAdmin\Plugins\Export\ExportXml; use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Sanitize; use PhpMyAdmin\SqlParser\Parser; @@ -35,7 +36,6 @@ use function function_exists; use function in_array; use function ini_set; use function is_array; -use function is_string; use function register_shutdown_function; use function time; @@ -50,7 +50,6 @@ final class ExportController implements InvocableController public function __invoke(ServerRequest $request): Response { - $GLOBALS['export_type'] ??= null; $GLOBALS['message'] ??= null; $GLOBALS['compression'] ??= null; $GLOBALS['asfile'] ??= null; @@ -96,15 +95,10 @@ final class ExportController implements InvocableController return $this->response->missingParameterError('what'); } - if (! is_string($GLOBALS['export_type']) || $GLOBALS['export_type'] === '') { - return $this->response->missingParameterError('export_type'); - } + $exportType = ExportType::from($request->getParsedBodyParamAsString('export_type')); // export class instance, not array of properties, as before - $exportPlugin = Plugins::getPlugin('export', $GLOBALS['what'], [ - 'export_type' => $GLOBALS['export_type'], - 'single_table' => isset($GLOBALS['single_table']), - ]); + $exportPlugin = Plugins::getPlugin('export', $GLOBALS['what'], $exportType, isset($GLOBALS['single_table'])); // Check export type if (! $exportPlugin instanceof ExportPlugin) { @@ -166,7 +160,7 @@ final class ExportController implements InvocableController $tableNames = []; // Generate error url and check for needed variables - if ($GLOBALS['export_type'] === 'database') { + if ($exportType === ExportType::Database) { if (Current::$database === '') { return $this->response->missingParameterError('db'); } @@ -175,7 +169,7 @@ final class ExportController implements InvocableController $tableNames = $GLOBALS['table_select'] ?? []; Assert::isArray($tableNames); Assert::allString($tableNames); - } elseif ($GLOBALS['export_type'] === 'table') { + } elseif ($exportType === ExportType::Table) { if (Current::$database === '') { return $this->response->missingParameterError('db'); } @@ -183,11 +177,6 @@ final class ExportController implements InvocableController if (Current::$table === '') { return $this->response->missingParameterError('table'); } - } elseif ($GLOBALS['export_type'] !== 'raw' && $GLOBALS['export_type'] !== 'server') { - $this->response->setRequestStatus(false); - $this->response->addHTML(Message::error(__('Bad parameters!'))->getDisplay()); - - return $this->response->response(); } // Merge SQL Query aliases with Export aliases from @@ -243,7 +232,7 @@ final class ExportController implements InvocableController $filenameTemplate = $request->getParsedBodyParamAsString('filename_template'); if ((bool) $rememberTemplate) { - $this->export->rememberFilename($config, $GLOBALS['export_type'], $filenameTemplate); + $this->export->rememberFilename($config, $exportType, $filenameTemplate); } $filename = $this->export->getFinalFilename( @@ -256,7 +245,7 @@ final class ExportController implements InvocableController } // For raw query export, filename will be export.extension - if ($GLOBALS['export_type'] === 'raw') { + if ($exportType === ExportType::Raw) { $filename = $this->export->getFinalFilename($exportPlugin, $GLOBALS['compression'], 'export'); } @@ -269,7 +258,7 @@ final class ExportController implements InvocableController // problem opening export file on server? if ($message !== null) { - $location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $message); + $location = $this->export->getPageLocationAndSaveMessage($exportType, $message); $this->response->redirect($location); return $this->response->response(); @@ -287,7 +276,7 @@ final class ExportController implements InvocableController Core::downloadHeader($filename, $mimeType); } else { // HTML - if ($GLOBALS['export_type'] === 'database') { + if ($exportType === ExportType::Database) { $GLOBALS['num_tables'] = count($tableNames); if ($GLOBALS['num_tables'] === 0) { $GLOBALS['message'] = Message::error( @@ -300,11 +289,7 @@ final class ExportController implements InvocableController } } - echo $this->export->getHtmlForDisplayedExportHeader( - $GLOBALS['export_type'], - Current::$database, - Current::$table, - ); + echo $this->export->getHtmlForDisplayedExportHeader($exportType, Current::$database, Current::$table); } try { @@ -345,14 +330,14 @@ final class ExportController implements InvocableController $GLOBALS[$GLOBALS['what'] . '_structure_or_data'] = $whatStrucOrData; } - if ($GLOBALS['export_type'] === 'raw') { + if ($exportType === ExportType::Raw) { $whatStrucOrData = 'raw'; } /** * Builds the dump */ - if ($GLOBALS['export_type'] === 'server') { + if ($exportType === ExportType::Server) { if ($dbSelect === null) { $dbSelect = ''; } @@ -361,7 +346,6 @@ final class ExportController implements InvocableController $dbSelect, $whatStrucOrData, $exportPlugin, - $GLOBALS['export_type'], $doRelation, $doComments, $doMime, @@ -369,7 +353,7 @@ final class ExportController implements InvocableController $aliases, $separateFiles, ); - } elseif ($GLOBALS['export_type'] === 'database') { + } elseif ($exportType === ExportType::Database) { if (! is_array($tableStructure)) { $tableStructure = []; } @@ -393,7 +377,6 @@ final class ExportController implements InvocableController $tableStructure, $GLOBALS['table_data'], $exportPlugin, - $GLOBALS['export_type'], $doRelation, $doComments, $doMime, @@ -412,7 +395,6 @@ final class ExportController implements InvocableController $tableStructure, $GLOBALS['table_data'], $exportPlugin, - $GLOBALS['export_type'], $doRelation, $doComments, $doMime, @@ -421,7 +403,7 @@ final class ExportController implements InvocableController $separateFiles, ); } - } elseif ($GLOBALS['export_type'] === 'raw') { + } elseif ($exportType === ExportType::Raw) { Export::exportRaw($whatStrucOrData, $exportPlugin, Current::$database, Current::$sqlQuery); } else { // We export just one table @@ -438,7 +420,6 @@ final class ExportController implements InvocableController Current::$table, $whatStrucOrData, $exportPlugin, - $GLOBALS['export_type'], $doRelation, $doComments, $doMime, @@ -458,7 +439,6 @@ final class ExportController implements InvocableController Current::$table, $whatStrucOrData, $exportPlugin, - $GLOBALS['export_type'], $doRelation, $doComments, $doMime, @@ -480,7 +460,7 @@ final class ExportController implements InvocableController } if ($GLOBALS['save_on_server'] && $GLOBALS['message'] instanceof Message) { - $location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $GLOBALS['message']); + $location = $this->export->getPageLocationAndSaveMessage($exportType, $GLOBALS['message']); $this->response->redirect($location); return $this->response->response(); @@ -490,11 +470,7 @@ final class ExportController implements InvocableController * Send the dump as a file... */ if (empty($GLOBALS['asfile'])) { - echo $this->export->getHtmlForDisplayedExportFooter( - $GLOBALS['export_type'], - Current::$database, - Current::$table, - ); + echo $this->export->getHtmlForDisplayedExportFooter($exportType, Current::$database, Current::$table); return $this->response->response(); } @@ -532,7 +508,7 @@ final class ExportController implements InvocableController $this->export->dumpBuffer, $GLOBALS['save_filename'], ); - $location = $this->export->getPageLocationAndSaveMessage($GLOBALS['export_type'], $message); + $location = $this->export->getPageLocationAndSaveMessage($exportType, $message); $this->response->redirect($location); return $this->response->response(); @@ -553,10 +529,6 @@ final class ExportController implements InvocableController $GLOBALS['single_table'] = $postParams['single_table']; } - if (isset($postParams['export_type'])) { - $GLOBALS['export_type'] = $postParams['export_type']; - } - if (isset($postParams['table_select'])) { $GLOBALS['table_select'] = $postParams['table_select']; } diff --git a/src/Controllers/Operations/DatabaseController.php b/src/Controllers/Operations/DatabaseController.php index f245a30857..5c39a877f3 100644 --- a/src/Controllers/Operations/DatabaseController.php +++ b/src/Controllers/Operations/DatabaseController.php @@ -21,6 +21,7 @@ use PhpMyAdmin\Message; use PhpMyAdmin\MessageType; use PhpMyAdmin\Operations; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Query\Utilities; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Url; @@ -100,10 +101,12 @@ final class DatabaseController implements InvocableController $tableNames = $this->dbi->getTables(Current::$database); // remove all foreign key constraints, otherwise we can get errors - $exportSqlPlugin = Plugins::getPlugin('export', 'sql', [ - 'export_type' => 'database', - 'single_table' => isset($GLOBALS['single_table']), - ]); + $exportSqlPlugin = Plugins::getPlugin( + 'export', + 'sql', + ExportType::Database, + isset($GLOBALS['single_table']), + ); // create stand-in tables for views $views = $this->operations->getViewsAndCreateSqlViewStandIn( diff --git a/src/Controllers/Server/ExportController.php b/src/Controllers/Server/ExportController.php index e3f9b320a9..3ec911beda 100644 --- a/src/Controllers/Server/ExportController.php +++ b/src/Controllers/Server/ExportController.php @@ -13,6 +13,7 @@ use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\ResponseRenderer; use function __; @@ -57,7 +58,7 @@ final class ExportController implements InvocableController $GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null; - $exportList = Plugins::getExport('server', isset($GLOBALS['single_table'])); + $exportList = Plugins::getExport(ExportType::Server, isset($GLOBALS['single_table'])); if ($exportList === []) { $this->response->addHTML(Message::error( @@ -68,7 +69,7 @@ final class ExportController implements InvocableController } $options = $this->export->getOptions( - 'server', + ExportType::Server, Current::$database, Current::$table, Current::$sqlQuery, diff --git a/src/Controllers/Table/ExportController.php b/src/Controllers/Table/ExportController.php index d352261478..b12e203e36 100644 --- a/src/Controllers/Table/ExportController.php +++ b/src/Controllers/Table/ExportController.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statements\SelectStatement; @@ -88,7 +89,7 @@ class ExportController implements InvocableController $GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null; - $exportList = Plugins::getExport('table', isset($GLOBALS['single_table'])); + $exportList = Plugins::getExport(ExportType::Table, isset($GLOBALS['single_table'])); if ($exportList === []) { $this->response->addHTML(Message::error( @@ -98,10 +99,10 @@ class ExportController implements InvocableController return $this->response->response(); } - $exportType = 'table'; + $exportType = ExportType::Table; $isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw'; if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) { - $exportType = 'raw'; + $exportType = ExportType::Raw; } $options = $this->export->getOptions( @@ -115,7 +116,7 @@ class ExportController implements InvocableController ); $this->response->render('table/export/index', array_merge($options, [ - 'export_type' => $exportType, + 'export_type' => $exportType->value, 'page_settings_error_html' => $pageSettingsErrorHtml, 'page_settings_html' => $pageSettingsHtml, ])); diff --git a/src/Export/Export.php b/src/Export/Export.php index 6990ae4de7..bdc1cabb05 100644 --- a/src/Export/Export.php +++ b/src/Export/Export.php @@ -18,6 +18,7 @@ use PhpMyAdmin\Message; use PhpMyAdmin\MessageType; use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Plugins\SchemaPlugin; use PhpMyAdmin\Table\Table; use PhpMyAdmin\Url; @@ -223,14 +224,14 @@ class Export /** * Returns HTML containing the footer for a displayed export * - * @param string $exportType the export type - * @param string $db the database name - * @param string $table the table name + * @param ExportType $exportType the export type + * @param string $db the database name + * @param string $table the table name * * @return string the HTML output */ public function getHtmlForDisplayedExportFooter( - string $exportType, + ExportType $exportType, string $db, string $table, ): string { @@ -314,14 +315,14 @@ class Export public function rememberFilename( Config $config, - string $exportType, + ExportType $exportType, string $filenameTemplate, ): void { - if ($exportType === 'server') { + if ($exportType === ExportType::Server) { $config->setUserValue('pma_server_filename_template', 'Export/file_template_server', $filenameTemplate); - } elseif ($exportType === 'database') { + } elseif ($exportType === ExportType::Database) { $config->setUserValue('pma_db_filename_template', 'Export/file_template_database', $filenameTemplate); - } elseif ($exportType === 'raw') { + } elseif ($exportType === ExportType::Raw) { $config->setUserValue('pma_raw_filename_template', 'Export/file_template_raw', $filenameTemplate); } else { $config->setUserValue('pma_table_filename_template', 'Export/file_template_table', $filenameTemplate); @@ -463,14 +464,14 @@ class Export /** * Returns HTML containing the header for a displayed export * - * @param string $exportType the export type - * @param string $db the database name - * @param string $table the table name + * @param ExportType $exportType the export type + * @param string $db the database name + * @param string $table the table name * * @return string the generated HTML and back button */ public function getHtmlForDisplayedExportHeader( - string $exportType, + ExportType $exportType, string $db, string $table, ): string { @@ -495,7 +496,6 @@ class Export * @param string|mixed[] $dbSelect the selected databases to export * @param string $whatStrucOrData structure or data or both * @param ExportPlugin $exportPlugin the selected export plugin - * @param string $exportType the export type * @param bool $doRelation whether to export relation info * @param bool $doComments whether to add comments * @param bool $doMime whether to add MIME info @@ -507,7 +507,6 @@ class Export string|array $dbSelect, string $whatStrucOrData, ExportPlugin $exportPlugin, - string $exportType, bool $doRelation, bool $doComments, bool $doMime, @@ -534,7 +533,6 @@ class Export $tables, $tables, $exportPlugin, - $exportType, $doRelation, $doComments, $doMime, @@ -559,7 +557,6 @@ class Export * @param string[] $tableStructure whether to export structure for each table * @param string[] $tableData whether to export data for each table * @param ExportPlugin $exportPlugin the selected export plugin - * @param string $exportType the export type * @param bool $doRelation whether to export relation info * @param bool $doComments whether to add comments * @param bool $doMime whether to add MIME info @@ -574,7 +571,6 @@ class Export array $tableStructure, array $tableData, ExportPlugin $exportPlugin, - string $exportType, bool $doRelation, bool $doComments, bool $doMime, @@ -589,7 +585,7 @@ class Export return; } - if (! $exportPlugin->exportDBCreate($db->getName(), $exportType, $dbAlias)) { + if (! $exportPlugin->exportDBCreate($db->getName(), $dbAlias)) { return; } @@ -642,7 +638,6 @@ class Export $db->getName(), $table, 'stand_in', - $exportType, $doRelation, $doComments, $doMime, @@ -676,7 +671,6 @@ class Export $db->getName(), $table, 'create_table', - $exportType, $doRelation, $doComments, $doMime, @@ -727,7 +721,6 @@ class Export $db->getName(), $table, 'triggers', - $exportType, $doRelation, $doComments, $doMime, @@ -757,7 +750,6 @@ class Export $db->getName(), $view, 'create_view', - $exportType, $doRelation, $doComments, $doMime, @@ -850,7 +842,6 @@ class Export * @param string $table the table to export * @param string $whatStrucOrData structure or data or both * @param ExportPlugin $exportPlugin the selected export plugin - * @param string $exportType the export type * @param bool $doRelation whether to export relation info * @param bool $doComments whether to add comments * @param bool $doMime whether to add MIME info @@ -866,7 +857,6 @@ class Export string $table, string $whatStrucOrData, ExportPlugin $exportPlugin, - string $exportType, bool $doRelation, bool $doComments, bool $doMime, @@ -901,7 +891,6 @@ class Export $db, $table, 'create_view', - $exportType, $doRelation, $doComments, $doMime, @@ -918,7 +907,6 @@ class Export $db, $table, 'create_table', - $exportType, $doRelation, $doComments, $doMime, @@ -970,7 +958,6 @@ class Export $db, $table, 'triggers', - $exportType, $doRelation, $doComments, $doMime, @@ -1001,15 +988,15 @@ class Export * * @psalm-return non-empty-string */ - public function getPageLocationAndSaveMessage(string $exportType, Message $message): string + public function getPageLocationAndSaveMessage(ExportType $exportType, Message $message): string { (new FlashMessenger())->addMessage($message->isError() ? 'danger' : 'success', $message->getMessage()); - if ($exportType === 'server') { + if ($exportType === ExportType::Server) { return 'index.php?route=/server/export' . Url::getCommonRaw([], '&'); } - if ($exportType === 'database') { + if ($exportType === ExportType::Database) { $params = ['db' => Current::$database]; return 'index.php?route=/database/export' . Url::getCommonRaw($params, '&'); @@ -1148,24 +1135,22 @@ class Export * get all the export options and verify * call and include the appropriate Schema Class depending on $export_type * - * @param non-empty-string $exportType - * * @return array{fileName: non-empty-string, mediaType: non-empty-string, fileData: string} * * @throws ExportException */ - public function getExportSchemaInfo(DatabaseName $db, string $exportType): array + public function getExportSchemaInfo(DatabaseName $db, string $format): array { /** * default is PDF, otherwise validate it's only letters a-z */ - if (preg_match('/^[a-zA-Z]+$/', $exportType) !== 1) { - $exportType = 'pdf'; + if (preg_match('/^[a-zA-Z]+$/', $format) !== 1) { + $format = 'pdf'; } // get the specific plugin /** @var SchemaPlugin|null $exportPlugin */ - $exportPlugin = Plugins::getPlugin('schema', $exportType); + $exportPlugin = Plugins::getPlugin('schema', $format); // Check schema export type if ($exportPlugin === null) { @@ -1183,7 +1168,7 @@ class Export return $this->dbi->getTables($database); } - private function getHTMLForRefreshButton(string $exportType): string + private function getHTMLForRefreshButton(ExportType $exportType): string { $postParams = $this->getPostParams($exportType); @@ -1211,12 +1196,12 @@ class Export . __('Copy to clipboard') . ' ]

'; } - private function getHTMLForBackButton(string $exportType, string $db, string $table): string + private function getHTMLForBackButton(ExportType $exportType, string $db, string $table): string { $backButton = '

[ exportComment(); // delete the stand-in table previously created (if any) - if ($exportType !== 'table') { + if (ExportPlugin::$exportType !== ExportType::Table) { $dump .= 'DROP TABLE IF EXISTS ' . Util::backquote($tableAlias) . ';' . "\n"; } diff --git a/src/Plugins/Export/ExportTexytext.php b/src/Plugins/Export/ExportTexytext.php index 741d53f20c..4231e7c4dd 100644 --- a/src/Plugins/Export/ExportTexytext.php +++ b/src/Plugins/Export/ExportTexytext.php @@ -136,11 +136,10 @@ class ExportTexytext extends ExportPlugin /** * Outputs CREATE DATABASE statement * - * @param string $db Database name - * @param string $exportType 'server', 'database', 'table' - * @param string $dbAlias Aliases of db + * @param string $db Database name + * @param string $dbAlias Aliases of db */ - public function exportDBCreate(string $db, string $exportType, string $dbAlias = ''): bool + public function exportDBCreate(string $db, string $dbAlias = ''): bool { return true; } @@ -453,7 +452,6 @@ class ExportTexytext extends ExportPlugin * @param string $db database name * @param string $table table name * @param string $exportMode 'create_table', 'triggers', 'create_view', 'stand_in' - * @param string $exportType 'server', 'database', 'table' * @param bool $doRelation whether to include relation comments * @param bool $doComments whether to include the pmadb-style column * comments as comments in the structure; @@ -469,7 +467,6 @@ class ExportTexytext extends ExportPlugin string $db, string $table, string $exportMode, - string $exportType, bool $doRelation = false, bool $doComments = false, bool $doMime = false, diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php index 032023bf51..6107f99786 100644 --- a/src/Plugins/Export/ExportXml.php +++ b/src/Plugins/Export/ExportXml.php @@ -383,11 +383,10 @@ class ExportXml extends ExportPlugin /** * Outputs CREATE DATABASE statement * - * @param string $db Database name - * @param string $exportType 'server', 'database', 'table' - * @param string $dbAlias Aliases of db + * @param string $db Database name + * @param string $dbAlias Aliases of db */ - public function exportDBCreate(string $db, string $exportType, string $dbAlias = ''): bool + public function exportDBCreate(string $db, string $dbAlias = ''): bool { return true; } diff --git a/src/Plugins/Export/ExportYaml.php b/src/Plugins/Export/ExportYaml.php index 95c7dc395b..aea88e585d 100644 --- a/src/Plugins/Export/ExportYaml.php +++ b/src/Plugins/Export/ExportYaml.php @@ -104,11 +104,10 @@ class ExportYaml extends ExportPlugin /** * Outputs CREATE DATABASE statement * - * @param string $db Database name - * @param string $exportType 'server', 'database', 'table' - * @param string $dbAlias Aliases of db + * @param string $db Database name + * @param string $dbAlias Aliases of db */ - public function exportDBCreate(string $db, string $exportType, string $dbAlias = ''): bool + public function exportDBCreate(string $db, string $dbAlias = ''): bool { return true; } diff --git a/src/Plugins/Export/README.md b/src/Plugins/Export/README.md index 050491ef45..c583d075a9 100644 --- a/src/Plugins/Export/README.md +++ b/src/Plugins/Export/README.md @@ -162,12 +162,11 @@ class Export[Name] extends PhpMyAdmin\Plugins\ExportPlugin * Outputs CREATE DATABASE statement * * @param string $db Database name - * @param string $exportType 'server', 'database', 'table' * @param string $dbAlias Aliases of db * * @return bool Whether it succeeded */ - public function exportDBCreate($db, $exportType, $dbAlias = '') + public function exportDBCreate($db, $dbAlias = '') { // implementation return true; diff --git a/src/Plugins/ExportPlugin.php b/src/Plugins/ExportPlugin.php index 630f9e926b..66d2ee86a2 100644 --- a/src/Plugins/ExportPlugin.php +++ b/src/Plugins/ExportPlugin.php @@ -28,6 +28,9 @@ abstract class ExportPlugin implements Plugin */ protected ExportPluginProperties $properties; + public static ExportType $exportType = ExportType::Raw; + public static bool $singleTable = false; + final public function __construct( public Relation $relation, protected Export $export, @@ -65,11 +68,10 @@ abstract class ExportPlugin implements Plugin /** * Outputs CREATE DATABASE statement * - * @param string $db Database name - * @param string $exportType 'server', 'database', 'table' - * @param string $dbAlias Aliases of db + * @param string $db Database name + * @param string $dbAlias Aliases of db */ - abstract public function exportDBCreate(string $db, string $exportType, string $dbAlias = ''): bool; + abstract public function exportDBCreate(string $db, string $dbAlias = ''): bool; /** * Outputs the content of a table @@ -129,7 +131,6 @@ abstract class ExportPlugin implements Plugin * @param string $db database name * @param string $table table name * @param string $exportMode 'create_table', 'triggers', 'create_view', 'stand_in' - * @param string $exportType 'server', 'database', 'table' * @param bool $doRelation whether to include relation comments * @param bool $doComments whether to include the pmadb-style column comments * as comments in the structure; this is deprecated @@ -144,7 +145,6 @@ abstract class ExportPlugin implements Plugin string $db, string $table, string $exportMode, - string $exportType, bool $doRelation = false, bool $doComments = false, bool $doMime = false, diff --git a/src/Plugins/ExportType.php b/src/Plugins/ExportType.php new file mode 100644 index 0000000000..9a735e5a61 --- /dev/null +++ b/src/Plugins/ExportType.php @@ -0,0 +1,13 @@ + 'table', - 'single_table' => false, - ]); + $exportSqlPlugin = Plugins::getPlugin('export', 'sql', ExportType::Table); // It is better that all identifiers are quoted $exportSqlPlugin->useSqlBackquotes(true); diff --git a/src/Tracking/Tracker.php b/src/Tracking/Tracker.php index a152bc2296..8483d99c0d 100644 --- a/src/Tracking/Tracker.php +++ b/src/Tracking/Tracker.php @@ -158,7 +158,6 @@ class Tracker string $trackingSet = '', bool $isView = false, ): bool { - $GLOBALS['export_type'] ??= null; $dbi = DatabaseInterface::getInstance(); $relation = new Relation($dbi); @@ -167,10 +166,7 @@ class Tracker $trackingSet = $config->selectedServer['tracking_default_statements']; } - $exportSqlPlugin = Plugins::getPlugin('export', 'sql', [ - 'export_type' => (string) $GLOBALS['export_type'], - 'single_table' => false, - ]); + $exportSqlPlugin = Plugins::getPlugin('export', 'sql'); if (! $exportSqlPlugin instanceof ExportSql) { return false; } diff --git a/tests/unit/Controllers/Export/Template/CreateControllerTest.php b/tests/unit/Controllers/Export/Template/CreateControllerTest.php index ba777eba57..5c9f087cc8 100644 --- a/tests/unit/Controllers/Export/Template/CreateControllerTest.php +++ b/tests/unit/Controllers/Export/Template/CreateControllerTest.php @@ -50,7 +50,7 @@ class CreateControllerTest extends AbstractTestCase $template = new Template(); $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody([ - 'exportType' => 'type', + 'exportType' => 'raw', 'templateName' => 'name', 'templateData' => 'data', 'template_id' => null, @@ -67,14 +67,14 @@ class CreateControllerTest extends AbstractTestCase ExportTemplate::fromArray([ 'id' => 1, 'username' => 'user1', - 'exportType' => 'type1', + 'exportType' => 'raw', 'name' => 'name1', 'data' => 'data1', ]), ExportTemplate::fromArray([ 'id' => 2, 'username' => 'user2', - 'exportType' => 'type2', + 'exportType' => 'raw', 'name' => 'name2', 'data' => 'data2', ]), diff --git a/tests/unit/Controllers/Table/ExportControllerTest.php b/tests/unit/Controllers/Table/ExportControllerTest.php index e69ce41ea4..68e8ee4509 100644 --- a/tests/unit/Controllers/Table/ExportControllerTest.php +++ b/tests/unit/Controllers/Table/ExportControllerTest.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Export\Options; use PhpMyAdmin\Export\TemplateModel; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Tests\Stubs\ResponseRenderer; @@ -58,7 +59,7 @@ class ExportControllerTest extends AbstractTestCase ); $pageSettings->init('Export'); $template = new Template(); - $exportList = Plugins::getExport('table', true); + $exportList = Plugins::getExport(ExportType::Table, true); $expected = $template->render('table/export/index', [ 'export_type' => 'table', diff --git a/tests/unit/Export/ExportTest.php b/tests/unit/Export/ExportTest.php index 54c7156fc0..afde4557d2 100644 --- a/tests/unit/Export/ExportTest.php +++ b/tests/unit/Export/ExportTest.php @@ -14,6 +14,8 @@ use PhpMyAdmin\Identifiers\DatabaseName; use PhpMyAdmin\Message; use PhpMyAdmin\Plugins\Export\ExportPhparray; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Transformations; use PHPUnit\Framework\Attributes\CoversClass; @@ -96,7 +98,6 @@ class ExportTest extends AbstractTestCase public function testExportDatabase(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'database', 'single_table' => false]; $GLOBALS['sql_create_view'] = 'something'; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; @@ -133,6 +134,7 @@ class ExportTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; $export = new Export($dbi); + ExportPlugin::$exportType = ExportType::Database; $export->exportDatabase( DatabaseName::from('test_db'), ['test_table'], @@ -140,7 +142,6 @@ class ExportTest extends AbstractTestCase ['test_table'], ['test_table'], new ExportSql(new Relation($dbi), $export, new Transformations()), - 'database', false, true, false, @@ -163,7 +164,6 @@ SQL; public function testExportServer(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'server', 'single_table' => false]; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; @@ -173,6 +173,7 @@ SQL; $GLOBALS['sql_structure_or_data'] = 'structure_and_data'; $GLOBALS['sql_insert_syntax'] = 'both'; $GLOBALS['sql_max_query_size'] = '50000'; + ExportPlugin::$exportType = ExportType::Server; // phpcs:disable Generic.Files.LineLength.TooLong $dbiDummy = $this->createDbiDummy(); @@ -220,7 +221,6 @@ SQL; ['test_db'], 'structure_and_data', new ExportSql(new Relation($dbi), $export, new Transformations()), - 'server', false, true, false, @@ -250,7 +250,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('server', Message::error('Error message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Server, Message::error('Error message!')); self::assertSame('index.php?route=/server/export&server=2&lang=en', $location); self::assertSame( [['context' => 'danger', 'message' => 'Error message!', 'statement' => '']], @@ -265,7 +265,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('server', Message::success('Success message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Server, Message::success('Success message!')); self::assertSame('index.php?route=/server/export&server=2&lang=en', $location); self::assertSame( [['context' => 'success', 'message' => 'Success message!', 'statement' => '']], @@ -281,7 +281,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('database', Message::error('Error message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Database, Message::error('Error message!')); self::assertSame('index.php?route=/database/export&db=test_db&server=2&lang=en', $location); self::assertSame( [['context' => 'danger', 'message' => 'Error message!', 'statement' => '']], @@ -297,7 +297,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('database', Message::success('Success message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Database, Message::success('Success message!')); self::assertSame('index.php?route=/database/export&db=test_db&server=2&lang=en', $location); self::assertSame( [['context' => 'success', 'message' => 'Success message!', 'statement' => '']], @@ -314,7 +314,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('table', Message::error('Error message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Table, Message::error('Error message!')); self::assertSame( 'index.php?route=/table/export&db=test_db&table=test_table&single_table=true&server=2&lang=en', $location, @@ -334,7 +334,7 @@ SQL; $_SESSION = []; $dbi = $this->createDatabaseInterface(); $export = new Export($dbi); - $location = $export->getPageLocationAndSaveMessage('table', Message::success('Success message!')); + $location = $export->getPageLocationAndSaveMessage(ExportType::Table, Message::success('Success message!')); self::assertSame( 'index.php?route=/table/export&db=test_db&table=test_table&single_table=true&server=2&lang=en', $location, diff --git a/tests/unit/Export/OptionsTest.php b/tests/unit/Export/OptionsTest.php index 47ca58f71c..de2ed27dc7 100644 --- a/tests/unit/Export/OptionsTest.php +++ b/tests/unit/Export/OptionsTest.php @@ -12,6 +12,7 @@ use PhpMyAdmin\Encoding; use PhpMyAdmin\Export\Options; use PhpMyAdmin\Export\TemplateModel; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Tests\AbstractTestCase; use PhpMyAdmin\Util; use PHPUnit\Framework\Attributes\CoversClass; @@ -56,7 +57,7 @@ class OptionsTest extends AbstractTestCase $config->settings['ZipDump'] = false; $config->settings['GZipDump'] = false; - $exportType = 'server'; + $exportType = ExportType::Server; $db = 'PMA'; $table = 'PMA_test'; $numTablesStr = '10'; @@ -87,7 +88,7 @@ class OptionsTest extends AbstractTestCase $actual = $this->export->getOptions($exportType, $db, $table, '', $numTablesStr, $unlimNumRowsStr, $exportList); $expected = [ - 'export_type' => $exportType, + 'export_type' => $exportType->value, 'db' => $db, 'table' => $table, 'templates' => ['is_enabled' => '', 'templates' => [], 'selected' => null], @@ -95,7 +96,7 @@ class OptionsTest extends AbstractTestCase 'hidden_inputs' => [ 'db' => $db, 'table' => $table, - 'export_type' => $exportType, + 'export_type' => $exportType->value, 'export_method' => $config->settings['Export']['method'], 'template_id' => '', ], diff --git a/tests/unit/Plugins/Export/ExportCsvTest.php b/tests/unit/Plugins/Export/ExportCsvTest.php index b0de9ff66b..fe751834e2 100644 --- a/tests/unit/Plugins/Export/ExportCsvTest.php +++ b/tests/unit/Plugins/Export/ExportCsvTest.php @@ -362,7 +362,7 @@ class ExportCsvTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportHtmlwordTest.php b/tests/unit/Plugins/Export/ExportHtmlwordTest.php index d887222d94..4416044853 100644 --- a/tests/unit/Plugins/Export/ExportHtmlwordTest.php +++ b/tests/unit/Plugins/Export/ExportHtmlwordTest.php @@ -284,7 +284,7 @@ class ExportHtmlwordTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } @@ -583,7 +583,6 @@ class ExportHtmlwordTest extends AbstractTestCase 'test_db', 'test_table', 'create_table', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -609,7 +608,6 @@ class ExportHtmlwordTest extends AbstractTestCase 'test_db', 'test_table', 'triggers', - 'test', ), ); $result = ob_get_clean(); @@ -631,7 +629,6 @@ class ExportHtmlwordTest extends AbstractTestCase 'test_db', 'test_table', 'create_view', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -657,7 +654,6 @@ class ExportHtmlwordTest extends AbstractTestCase 'test_db', 'test_table', 'stand_in', - 'test', ), ); $result = ob_get_clean(); diff --git a/tests/unit/Plugins/Export/ExportJsonTest.php b/tests/unit/Plugins/Export/ExportJsonTest.php index 6f1de0ab23..10658278a5 100644 --- a/tests/unit/Plugins/Export/ExportJsonTest.php +++ b/tests/unit/Plugins/Export/ExportJsonTest.php @@ -160,7 +160,7 @@ class ExportJsonTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportLatexTest.php b/tests/unit/Plugins/Export/ExportLatexTest.php index 877a1e050b..aeca51edb3 100644 --- a/tests/unit/Plugins/Export/ExportLatexTest.php +++ b/tests/unit/Plugins/Export/ExportLatexTest.php @@ -12,6 +12,8 @@ use PhpMyAdmin\Current; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportLatex; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -50,9 +52,8 @@ class ExportLatexTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; Current::$database = 'db'; Current::$table = 'table'; $this->object = new ExportLatex( @@ -75,8 +76,8 @@ class ExportLatexTest extends AbstractTestCase public function testSetProperties(): void { - $GLOBALS['plugin_param']['export_type'] = ''; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Raw; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', @@ -419,8 +420,8 @@ class ExportLatexTest extends AbstractTestCase ); // case 2 - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; $method->invoke($this->object, null); @@ -472,7 +473,7 @@ class ExportLatexTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } @@ -609,7 +610,6 @@ class ExportLatexTest extends AbstractTestCase 'database', '', 'test', - 'test', true, true, true, @@ -697,7 +697,6 @@ class ExportLatexTest extends AbstractTestCase 'database', '', 'test', - 'test', true, true, true, @@ -755,7 +754,6 @@ class ExportLatexTest extends AbstractTestCase 'database', '', 'test', - 'test', ), ); $result = ob_get_clean(); @@ -772,7 +770,6 @@ class ExportLatexTest extends AbstractTestCase 'database', '', 'triggers', - 'test', ), ); } diff --git a/tests/unit/Plugins/Export/ExportMediawikiTest.php b/tests/unit/Plugins/Export/ExportMediawikiTest.php index 8492ac8d0f..3b3d078365 100644 --- a/tests/unit/Plugins/Export/ExportMediawikiTest.php +++ b/tests/unit/Plugins/Export/ExportMediawikiTest.php @@ -214,7 +214,7 @@ class ExportMediawikiTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } @@ -247,7 +247,6 @@ class ExportMediawikiTest extends AbstractTestCase 'db', 'table', 'create_table', - 'test', ), ); $result = ob_get_clean(); diff --git a/tests/unit/Plugins/Export/ExportOdsTest.php b/tests/unit/Plugins/Export/ExportOdsTest.php index 8205ccf1e9..3fb010fee1 100644 --- a/tests/unit/Plugins/Export/ExportOdsTest.php +++ b/tests/unit/Plugins/Export/ExportOdsTest.php @@ -207,7 +207,7 @@ class ExportOdsTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportOdtTest.php b/tests/unit/Plugins/Export/ExportOdtTest.php index 1868a63943..a3d9a9e88e 100644 --- a/tests/unit/Plugins/Export/ExportOdtTest.php +++ b/tests/unit/Plugins/Export/ExportOdtTest.php @@ -14,6 +14,8 @@ use PhpMyAdmin\Export\Export; use PhpMyAdmin\Identifiers\TableName; use PhpMyAdmin\Identifiers\TriggerName; use PhpMyAdmin\Plugins\Export\ExportOdt; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -69,9 +71,8 @@ class ExportOdtTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = true; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new ExportOdt( new Relation($this->dbi), @@ -93,8 +94,8 @@ class ExportOdtTest extends AbstractTestCase public function testSetProperties(): void { - $GLOBALS['plugin_param']['export_type'] = ''; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Raw; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', @@ -294,8 +295,8 @@ class ExportOdtTest extends AbstractTestCase ); // case 2 - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; $method->invoke($this->object, null); @@ -350,7 +351,7 @@ class ExportOdtTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } @@ -758,7 +759,6 @@ class ExportOdtTest extends AbstractTestCase 'test_db', 'test_table', 'create_table', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -798,7 +798,6 @@ class ExportOdtTest extends AbstractTestCase 'test_db', 'test_table', 'triggers', - 'test', ), ); @@ -828,7 +827,6 @@ class ExportOdtTest extends AbstractTestCase 'test_db', 'test_table', 'create_view', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -868,7 +866,6 @@ class ExportOdtTest extends AbstractTestCase 'test_db', 'test_table', 'stand_in', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); diff --git a/tests/unit/Plugins/Export/ExportPdfTest.php b/tests/unit/Plugins/Export/ExportPdfTest.php index 0f327af1b6..b4e202b78d 100644 --- a/tests/unit/Plugins/Export/ExportPdfTest.php +++ b/tests/unit/Plugins/Export/ExportPdfTest.php @@ -212,7 +212,7 @@ class ExportPdfTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportPhparrayTest.php b/tests/unit/Plugins/Export/ExportPhparrayTest.php index f12327d258..8a417df434 100644 --- a/tests/unit/Plugins/Export/ExportPhparrayTest.php +++ b/tests/unit/Plugins/Export/ExportPhparrayTest.php @@ -162,7 +162,7 @@ class ExportPhparrayTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index d9a74d7736..ddd9ffed5f 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -13,6 +13,8 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportSql; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertySubgroup; @@ -67,9 +69,8 @@ class ExportSqlTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; $this->object = new ExportSql( new Relation($dbi), @@ -93,8 +94,8 @@ class ExportSqlTest extends AbstractTestCase public function testSetPropertiesWithHideSql(): void { // test with hide structure and hide sql as true - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; $method = new ReflectionMethod(ExportSql::class, 'setProperties'); $properties = $method->invoke($this->object, null); @@ -116,8 +117,8 @@ class ExportSqlTest extends AbstractTestCase ->willReturn(['v1', 'v2']); DatabaseInterface::$instance = $dbi; - $GLOBALS['plugin_param']['export_type'] = 'server'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Server; + ExportPlugin::$singleTable = false; $relationParameters = RelationParameters::fromArray([ 'db' => 'db', @@ -485,7 +486,7 @@ class ExportSqlTest extends AbstractTestCase ob_start(); self::assertTrue( - $this->object->exportDBCreate('db', 'database'), + $this->object->exportDBCreate('db'), ); $result = ob_get_clean(); @@ -519,7 +520,7 @@ class ExportSqlTest extends AbstractTestCase ob_start(); self::assertTrue( - $this->object->exportDBCreate('db', 'database'), + $this->object->exportDBCreate('db'), ); $result = ob_get_clean(); @@ -907,7 +908,6 @@ SQL; 'test_db', 'test_table', 'create_table', - 'test', ), ); $result = ob_get_clean(); @@ -930,7 +930,6 @@ SQL; 'test_db', 'test_table', 'triggers', - 'test', ), ); $result = ob_get_clean(); @@ -949,6 +948,7 @@ SQL; $GLOBALS['sql_views_as_tables'] = false; $this->object->useSqlBackquotes(false); + ExportPlugin::$exportType = ExportType::Raw; ob_start(); self::assertTrue( @@ -956,7 +956,6 @@ SQL; 'test_db', 'test_table', 'create_view', - 'test', ), ); $result = ob_get_clean(); @@ -979,7 +978,6 @@ SQL; 'test_db', 'test_table', 'create_view', - 'test', ), ); $result = ob_get_clean(); @@ -996,7 +994,6 @@ SQL; 'test_db', 'test_table', 'stand_in', - 'test', ), ); $result = ob_get_clean(); diff --git a/tests/unit/Plugins/Export/ExportTexytextTest.php b/tests/unit/Plugins/Export/ExportTexytextTest.php index eb45bbd83f..280b413f73 100644 --- a/tests/unit/Plugins/Export/ExportTexytextTest.php +++ b/tests/unit/Plugins/Export/ExportTexytextTest.php @@ -16,6 +16,8 @@ use PhpMyAdmin\Export\Export; use PhpMyAdmin\Identifiers\TableName; use PhpMyAdmin\Identifiers\TriggerName; use PhpMyAdmin\Plugins\Export\ExportTexytext; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -60,9 +62,8 @@ class ExportTexytextTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; Current::$database = ''; Current::$table = ''; $GLOBALS['lang'] = 'en'; @@ -205,7 +206,7 @@ class ExportTexytextTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } @@ -349,7 +350,6 @@ class ExportTexytextTest extends AbstractTestCase 'test_db', 'test_table', 'create_table', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -374,7 +374,6 @@ class ExportTexytextTest extends AbstractTestCase 'test_db', 'test_table', 'triggers', - 'test', ), ); $result = ob_get_clean(); @@ -396,7 +395,6 @@ class ExportTexytextTest extends AbstractTestCase 'test_db', 'test_table', 'create_view', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); @@ -421,7 +419,6 @@ class ExportTexytextTest extends AbstractTestCase 'test_db', 'test_table', 'stand_in', - 'test', ), ); $this->dummyDbi->assertAllSelectsConsumed(); diff --git a/tests/unit/Plugins/Export/ExportXmlTest.php b/tests/unit/Plugins/Export/ExportXmlTest.php index 3ab87ac212..b6fe7b6089 100644 --- a/tests/unit/Plugins/Export/ExportXmlTest.php +++ b/tests/unit/Plugins/Export/ExportXmlTest.php @@ -10,6 +10,8 @@ use PhpMyAdmin\Current; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Plugins\Export\ExportXml; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; @@ -45,9 +47,8 @@ class ExportXmlTest extends AbstractTestCase $GLOBALS['buffer_needed'] = false; $GLOBALS['asfile'] = false; $GLOBALS['save_on_server'] = false; - $GLOBALS['plugin_param'] = []; - $GLOBALS['plugin_param']['export_type'] = 'table'; - $GLOBALS['plugin_param']['single_table'] = false; + ExportPlugin::$exportType = ExportType::Table; + ExportPlugin::$singleTable = false; Current::$database = 'db'; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new ExportXml( @@ -365,7 +366,7 @@ class ExportXmlTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/Plugins/Export/ExportYamlTest.php b/tests/unit/Plugins/Export/ExportYamlTest.php index a9097f1ed5..753adfc84d 100644 --- a/tests/unit/Plugins/Export/ExportYamlTest.php +++ b/tests/unit/Plugins/Export/ExportYamlTest.php @@ -152,7 +152,7 @@ class ExportYamlTest extends AbstractTestCase public function testExportDBCreate(): void { self::assertTrue( - $this->object->exportDBCreate('testDB', 'database'), + $this->object->exportDBCreate('testDB'), ); } diff --git a/tests/unit/PluginsTest.php b/tests/unit/PluginsTest.php index 1c39529877..8d5a84155b 100644 --- a/tests/unit/PluginsTest.php +++ b/tests/unit/PluginsTest.php @@ -10,6 +10,8 @@ use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Export\Export; use PhpMyAdmin\Import\ImportSettings; use PhpMyAdmin\Plugins; +use PhpMyAdmin\Plugins\ExportPlugin; +use PhpMyAdmin\Plugins\ExportType; use PhpMyAdmin\Transformations; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -26,8 +28,9 @@ class PluginsTest extends AbstractTestCase public function testGetExport(): void { - $plugins = Plugins::getExport('database', false); - self::assertSame(['export_type' => 'database', 'single_table' => false], $GLOBALS['plugin_param']); + $plugins = Plugins::getExport(ExportType::Database, false); + self::assertSame(ExportType::Database, ExportPlugin::$exportType); + self::assertFalse(ExportPlugin::$singleTable); self::assertCount(14, $plugins); self::assertContainsOnlyInstancesOf(Plugins\ExportPlugin::class, $plugins); } @@ -98,7 +101,6 @@ class PluginsTest extends AbstractTestCase public function testGetChoice(): void { - $GLOBALS['plugin_param'] = ['export_type' => 'database', 'single_table' => false]; $dbi = DatabaseInterface::getInstance(); $exportList = [ new Plugins\Export\ExportJson( diff --git a/tests/unit/Stubs/DbiDummy.php b/tests/unit/Stubs/DbiDummy.php index 2a9e52e0b3..25c1d1f97d 100644 --- a/tests/unit/Stubs/DbiDummy.php +++ b/tests/unit/Stubs/DbiDummy.php @@ -1424,20 +1424,20 @@ class DbiDummy implements DbiExtension ], [ 'query' => 'INSERT INTO `db`.`table` (`username`, `export_type`, `template_name`, `template_data`)' - . ' VALUES (\'user\', \'type\', \'name\', \'data\');', + . ' VALUES (\'user\', \'raw\', \'name\', \'data\');', 'result' => true, ], [ 'query' => 'SELECT * FROM `db`.`table` WHERE `username` = \'user\'' - . ' AND `export_type` = \'type\' ORDER BY `template_name`;', + . ' AND `export_type` = \'raw\' ORDER BY `template_name`;', 'columns' => ['id', 'username', 'export_type', 'template_name', 'template_data'], - 'result' => [['1', 'user1', 'type1', 'name1', 'data1'], ['2', 'user2', 'type2', 'name2', 'data2']], + 'result' => [['1', 'user1', 'raw', 'name1', 'data1'], ['2', 'user2', 'raw', 'name2', 'data2']], ], ['query' => 'DELETE FROM `db`.`table` WHERE `id` = 1 AND `username` = \'user\';', 'result' => true], [ 'query' => 'SELECT * FROM `db`.`table` WHERE `id` = 1 AND `username` = \'user\';', 'columns' => ['id', 'username', 'export_type', 'template_name', 'template_data'], - 'result' => [['1', 'user1', 'type1', 'name1', 'data1']], + 'result' => [['1', 'user1', 'raw', 'name1', 'data1']], ], [ 'query' => 'UPDATE `db`.`table` SET `template_data` = \'data\'' diff --git a/tests/unit/Tracking/TrackerTest.php b/tests/unit/Tracking/TrackerTest.php index dad470a814..a0c029d97c 100644 --- a/tests/unit/Tracking/TrackerTest.php +++ b/tests/unit/Tracking/TrackerTest.php @@ -42,7 +42,6 @@ class TrackerTest extends AbstractTestCase $config->selectedServer['tracking_default_statements'] = ''; $config->selectedServer['tracking_version_auto_create'] = ''; $config->selectedServer['DisableIS'] = false; - $GLOBALS['export_type'] = null; $relationParameters = RelationParameters::fromArray([ 'db' => 'pmadb',