Merge pull request #19447 from kamil-tekiela/plugin_param

Remove $GLOBALS['plugin_param'] and $GLOBALS['export_type']
This commit is contained in:
Maurício Meneghini Fauth 2024-12-14 17:09:46 -03:00 committed by GitHub
commit 0765b057b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
51 changed files with 254 additions and 504 deletions

View File

@ -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\<string\>, array\<mixed\> 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

View File

@ -1440,7 +1440,6 @@
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$GLOBALS['single_table']]]></code>
<code><![CDATA[$GLOBALS['table_data']]]></code>
@ -1452,11 +1451,6 @@
<code><![CDATA[$GLOBALS['charset']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['file_handle']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$dbSelect]]></code>
@ -1488,8 +1482,6 @@
<code><![CDATA[$GLOBALS['excel_null']]]></code>
<code><![CDATA[$GLOBALS['excel_removeCRLF']]]></code>
<code><![CDATA[$GLOBALS['excel_structure_or_data']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['htmlword_columns']]]></code>
<code><![CDATA[$GLOBALS['htmlword_null']]]></code>
<code><![CDATA[$GLOBALS['htmlword_structure_or_data']]]></code>
@ -1586,11 +1578,6 @@
<code><![CDATA[$GLOBALS['charset']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['file_handle']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
@ -1600,11 +1587,6 @@
<code><![CDATA[$GLOBALS['charset']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['compression']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['export_type']]]></code>
<code><![CDATA[$GLOBALS['save_filename']]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
@ -7330,10 +7312,6 @@
<PossiblyNullArgument>
<code><![CDATA[$record[$columns[$i]]]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$GLOBALS['plugin_param']['export_type']]]></code>
<code><![CDATA[$GLOBALS['plugin_param']['single_table']]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullOperand>
<code><![CDATA[$tableAlias]]></code>
<code><![CDATA[$tableAlias]]></code>
@ -7454,10 +7432,6 @@
<code><![CDATA[$tableAlias]]></code>
<code><![CDATA[$viewAlias]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$GLOBALS['plugin_param']['export_type']]]></code>
<code><![CDATA[$GLOBALS['plugin_param']['single_table']]]></code>
</PossiblyNullArrayAccess>
<PossiblyUnusedReturnValue>
<code><![CDATA[string]]></code>
</PossiblyUnusedReturnValue>
@ -7606,11 +7580,6 @@
<code><![CDATA[$tableAlias]]></code>
<code><![CDATA[$tableAlias]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$GLOBALS['plugin_param']['export_type']]]></code>
<code><![CDATA[$GLOBALS['plugin_param']['export_type']]]></code>
<code><![CDATA[$GLOBALS['plugin_param']['single_table']]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullArrayOffset>
<code><![CDATA[$aliases[$oldDatabase]['tables']]]></code>
</PossiblyNullArrayOffset>
@ -10534,9 +10503,6 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['export_type']]]></code>
</InvalidArrayOffset>
<MixedArgument>
<code><![CDATA[$result['identifier']]]></code>
<code><![CDATA[$result['tablename']]]></code>
@ -10549,9 +10515,6 @@
<MixedArrayAssignment>
<code><![CDATA[self::$trackingCache[$dbName][$tableName]]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code><![CDATA[$GLOBALS['export_type']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[bool]]></code>
</MixedInferredReturnType>

View File

@ -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;

View File

@ -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'];
}

View File

@ -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(

View File

@ -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,

View File

@ -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,
]));

View File

@ -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') . '</a> ]</p>';
}
private function getHTMLForBackButton(string $exportType, string $db, string $table): string
private function getHTMLForBackButton(ExportType $exportType, string $db, string $table): string
{
$backButton = '<p>[ <a href="';
$backButton .= match ($exportType) {
'server' => Url::getFromRoute('/server/export') . '" data-post="' . Url::getCommon([], '', false),
'database' => Url::getFromRoute('/database/export') . '" data-post="' . Url::getCommon(
ExportType::Server => Url::getFromRoute('/server/export') . '" data-post="' . Url::getCommon([], '', false),
ExportType::Database => Url::getFromRoute('/database/export') . '" data-post="' . Url::getCommon(
['db' => $db],
'',
false,
@ -1237,12 +1222,12 @@ class Export
}
/** @return mixed[] */
private function getPostParams(string $exportType): array
private function getPostParams(ExportType $exportType): array
{
$postParams = $_POST;
// Convert the multiple select elements from an array to a string
if ($exportType === 'database') {
if ($exportType === ExportType::Database) {
$structOrDataForced = empty($postParams['structure_or_data_forced']);
if ($structOrDataForced && ! isset($postParams['table_structure'])) {
$postParams['table_structure'] = [];

View File

@ -11,6 +11,7 @@ use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Plugins\ExportType;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\Table\Table;
use PhpMyAdmin\Util;
@ -87,7 +88,7 @@ final class Options
}
/**
* @param string $exportType export type: server|database|table
* @param ExportType $exportType export type: server|database|table
* @param string $db selected DB
* @param string $table selected table
* @param string $sqlQuery SQL query
@ -98,7 +99,7 @@ final class Options
* @return array<string, mixed>
*/
public function getOptions(
string $exportType,
ExportType $exportType,
string $db,
string $table,
string $sqlQuery,
@ -127,7 +128,7 @@ final class Options
$tableObject = new Table($table, $db, DatabaseInterface::getInstance());
$rows = [];
if ($table !== '' && $numTables === 0 && ! $tableObject->isMerge() && $exportType !== 'raw') {
if ($table !== '' && $numTables === 0 && ! $tableObject->isMerge() && $exportType !== ExportType::Raw) {
$rows = [
'allrows' => $_POST['allrows'] ?? null,
'limit_to' => $_POST['limit_to'] ?? null,
@ -153,7 +154,7 @@ final class Options
$hiddenInputs = [
'db' => $db,
'table' => $table,
'export_type' => $exportType,
'export_type' => $exportType->value,
'export_method' => $_POST['export_method'] ?? $config->settings['Export']['method'] ?? 'quick',
'template_id' => $_POST['template_id'] ?? '',
];
@ -167,7 +168,7 @@ final class Options
}
return [
'export_type' => $exportType,
'export_type' => $exportType->value,
'db' => $db,
'table' => $table,
'templates' => [
@ -208,21 +209,21 @@ final class Options
];
}
private function getFileNameTemplate(string $exportType, string|null $filename = null): string
private function getFileNameTemplate(ExportType $exportType, string|null $filename = null): string
{
if ($filename !== null) {
return $filename;
}
$config = Config::getInstance();
if ($exportType === 'database') {
if ($exportType === ExportType::Database) {
return (string) $config->getUserValue(
'pma_db_filename_template',
$config->settings['Export']['file_template_database'],
);
}
if ($exportType === 'table') {
if ($exportType === ExportType::Table) {
return (string) $config->getUserValue(
'pma_table_filename_template',
$config->settings['Export']['file_template_table'],

View File

@ -4,13 +4,15 @@ declare(strict_types=1);
namespace PhpMyAdmin\Export;
use PhpMyAdmin\Plugins\ExportType;
/** @psalm-immutable */
final class Template
{
private function __construct(
private int $id,
private string $username,
private string $exportType,
private ExportType $exportType,
private string $name,
private string $data,
) {
@ -22,7 +24,7 @@ final class Template
return new self(
$state['id'] ?? 0,
$state['username'],
$state['exportType'] ?? '',
ExportType::from($state['exportType'] ?? ''),
$state['name'] ?? '',
$state['data'],
);
@ -38,7 +40,7 @@ final class Template
return $this->username;
}
public function getExportType(): string
public function getExportType(): ExportType
{
return $this->exportType;
}

View File

@ -8,6 +8,7 @@ use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Plugins\ExportType;
use PhpMyAdmin\Util;
use function sprintf;
@ -26,7 +27,7 @@ final class TemplateModel
Util::backquote($db),
Util::backquote($table),
$this->dbi->quoteString($template->getUsername(), ConnectionType::ControlUser),
$this->dbi->quoteString($template->getExportType(), ConnectionType::ControlUser),
$this->dbi->quoteString($template->getExportType()->value, ConnectionType::ControlUser),
$this->dbi->quoteString($template->getName(), ConnectionType::ControlUser),
$this->dbi->quoteString($template->getData(), ConnectionType::ControlUser),
);
@ -102,14 +103,14 @@ final class TemplateModel
}
/** @return Template[]|string */
public function getAll(DatabaseName $db, TableName $table, string $user, string $exportType): array|string
public function getAll(DatabaseName $db, TableName $table, string $user, ExportType $exportType): array|string
{
$query = sprintf(
'SELECT * FROM %s.%s WHERE `username` = %s AND `export_type` = %s ORDER BY `template_name`;',
Util::backquote($db),
Util::backquote($table),
$this->dbi->quoteString($user, ConnectionType::ControlUser),
$this->dbi->quoteString($exportType, ConnectionType::ControlUser),
$this->dbi->quoteString($exportType->value, ConnectionType::ControlUser),
);
$result = $this->dbi->tryQueryAsControlUser($query);
if ($result === false) {

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\Plugins\ExportType;
use PhpMyAdmin\Plugins\ImportPlugin;
use PhpMyAdmin\Plugins\Plugin;
use PhpMyAdmin\Plugins\SchemaPlugin;
@ -49,16 +50,19 @@ class Plugins
/**
* Instantiates the specified plugin type for a certain format
*
* @param string $type the type of the plugin (import, export, etc)
* @param string $format the format of the plugin (sql, xml, et )
* @param array|string|null $param parameter to plugin by which they can decide whether they can work
* @psalm-param array{export_type: string, single_table: bool}|string|null $param
* @param string $type the type of the plugin (import, export, etc)
* @param string $format the format of the plugin (sql, xml, et )
*
* @return object|null new plugin instance
*/
public static function getPlugin(string $type, string $format, array|string|null $param = null): object|null
{
$GLOBALS['plugin_param'] = $param;
public static function getPlugin(
string $type,
string $format,
ExportType $exportType = ExportType::Raw,
bool $singleTable = false,
): object|null {
ExportPlugin::$exportType = $exportType;
ExportPlugin::$singleTable = $singleTable;
$pluginType = mb_strtoupper($type[0]) . mb_strtolower(mb_substr($type, 1));
$pluginFormat = mb_strtoupper($format[0]) . mb_strtolower(mb_substr($format, 1));
$class = sprintf('PhpMyAdmin\\Plugins\\%s\\%s%s', $pluginType, $pluginType, $pluginFormat);
@ -81,15 +85,13 @@ class Plugins
}
/**
* @param string $type server|database|table|raw
* @psalm-param 'server'|'database'|'table'|'raw' $type
*
* @return ExportPlugin[]
* @psalm-return list<ExportPlugin>
*/
public static function getExport(string $type, bool $singleTable): array
public static function getExport(ExportType $type, bool $singleTable): array
{
$GLOBALS['plugin_param'] = ['export_type' => $type, 'single_table' => $singleTable];
ExportPlugin::$exportType = $type;
ExportPlugin::$singleTable = $singleTable;
return self::getPlugins('Export');
}

View File

@ -116,11 +116,10 @@ class ExportCodegen 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;
}

View File

@ -174,11 +174,10 @@ class ExportCsv 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;
}

View File

@ -152,11 +152,10 @@ class ExportHtmlword 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;
}
@ -482,7 +481,6 @@ class ExportHtmlword 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;
@ -498,7 +496,6 @@ class ExportHtmlword extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,

View File

@ -156,11 +156,10 @@ class ExportJson 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;
}

View File

@ -12,6 +12,7 @@ use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
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;
@ -55,10 +56,8 @@ class ExportLatex extends ExportPlugin
protected function setProperties(): ExportPluginProperties
{
$GLOBALS['plugin_param'] ??= null;
$hideStructure = false;
if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) {
if (ExportPlugin::$exportType === ExportType::Table && ! ExportPlugin::$singleTable) {
$hideStructure = true;
}
@ -258,11 +257,10 @@ class ExportLatex 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;
}
@ -416,7 +414,6 @@ class ExportLatex 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;
@ -432,7 +429,6 @@ class ExportLatex extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,

View File

@ -127,11 +127,10 @@ class ExportMediawiki 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;
}
@ -142,7 +141,6 @@ class ExportMediawiki 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; this is
@ -160,7 +158,6 @@ class ExportMediawiki extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,

View File

@ -172,11 +172,10 @@ class ExportOds 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;
}

View File

@ -12,6 +12,7 @@ use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\OpenDocument;
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,10 +46,8 @@ class ExportOdt extends ExportPlugin
protected function setProperties(): ExportPluginProperties
{
$GLOBALS['plugin_param'] ??= null;
$hideStructure = false;
if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) {
if (ExportPlugin::$exportType === ExportType::Table && ! ExportPlugin::$singleTable) {
$hideStructure = true;
}
@ -198,11 +197,10 @@ class ExportOdt 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;
}
@ -610,7 +608,6 @@ class ExportOdt 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;
@ -625,7 +622,6 @@ class ExportOdt extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,

View File

@ -144,11 +144,10 @@ class ExportPdf 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;
}
@ -211,7 +210,6 @@ class ExportPdf 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;
@ -227,7 +225,6 @@ class ExportPdf extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,

View File

@ -129,11 +129,10 @@ class ExportPhparray 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;
}

View File

@ -16,6 +16,7 @@ use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\ConnectionType;
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;
@ -94,11 +95,9 @@ class ExportSql extends ExportPlugin
protected function setProperties(): ExportPluginProperties
{
$GLOBALS['plugin_param'] ??= null;
$hideSql = false;
$hideStructure = false;
if ($GLOBALS['plugin_param']['export_type'] === 'table' && ! $GLOBALS['plugin_param']['single_table']) {
if (ExportPlugin::$exportType === ExportType::Table && ! ExportPlugin::$singleTable) {
$hideStructure = true;
$hideSql = true;
}
@ -243,7 +242,7 @@ class ExportSql extends ExportPlugin
$subgroup->setSubgroupHeader($leaf);
// server export options
if ($GLOBALS['plugin_param']['export_type'] === 'server') {
if (ExportPlugin::$exportType === ExportType::Server) {
$leaf = new BoolPropertyItem(
'drop_database',
sprintf(__('Add %s statement'), '<code>DROP DATABASE IF EXISTS</code>'),
@ -251,7 +250,7 @@ class ExportSql extends ExportPlugin
$subgroup->addProperty($leaf);
}
if ($GLOBALS['plugin_param']['export_type'] === 'database') {
if (ExportPlugin::$exportType === ExportType::Database) {
$createClause = '<code>CREATE DATABASE / USE</code>';
$leaf = new BoolPropertyItem(
'create_database',
@ -260,7 +259,7 @@ class ExportSql extends ExportPlugin
$subgroup->addProperty($leaf);
}
if ($GLOBALS['plugin_param']['export_type'] === 'table') {
if (ExportPlugin::$exportType === ExportType::Table) {
$dropClause = $dbi->getTable(Current::$database, Current::$table)->isView()
? '<code>DROP VIEW</code>'
: '<code>DROP TABLE</code>';
@ -798,11 +797,10 @@ class ExportSql 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
{
if ($dbAlias === '') {
$dbAlias = $db;
@ -828,7 +826,7 @@ class ExportSql extends ExportPlugin
}
}
if ($exportType === 'database' && ! isset($GLOBALS['sql_create_database'])) {
if (ExportPlugin::$exportType === ExportType::Database && ! isset($GLOBALS['sql_create_database'])) {
return true;
}
@ -1874,7 +1872,6 @@ class ExportSql 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; this is
@ -1890,7 +1887,6 @@ class ExportSql extends ExportPlugin
string $db,
string $table,
string $exportMode,
string $exportType,
bool $doRelation = false,
bool $doComments = false,
bool $doMime = false,
@ -1974,7 +1970,7 @@ class ExportSql extends ExportPlugin
)
. $this->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";
}
@ -1989,7 +1985,7 @@ class ExportSql extends ExportPlugin
)
. $this->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";
}

View File

@ -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,

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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,

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Plugins;
enum ExportType: string
{
case Server = 'server';
case Database = 'database';
case Table = 'table';
case Raw = 'raw';
}

View File

@ -11,6 +11,7 @@ use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Plugins\ExportType;
use PhpMyAdmin\SqlParser\Components\Expression;
use PhpMyAdmin\SqlParser\Components\OptionsArray;
use PhpMyAdmin\SqlParser\Context;
@ -462,10 +463,7 @@ class TableMover
*
* @var ExportSql $exportSqlPlugin
*/
$exportSqlPlugin = Plugins::getPlugin('export', 'sql', [
'export_type' => 'table',
'single_table' => false,
]);
$exportSqlPlugin = Plugins::getPlugin('export', 'sql', ExportType::Table);
// It is better that all identifiers are quoted
$exportSqlPlugin->useSqlBackquotes(true);

View File

@ -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;
}

View File

@ -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',
]),

View File

@ -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',

View File

@ -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,

View File

@ -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' => '',
],

View File

@ -362,7 +362,7 @@ class ExportCsvTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -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();

View File

@ -160,7 +160,7 @@ class ExportJsonTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -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',
),
);
}

View File

@ -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();

View File

@ -207,7 +207,7 @@ class ExportOdsTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -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();

View File

@ -212,7 +212,7 @@ class ExportPdfTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -162,7 +162,7 @@ class ExportPhparrayTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -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();

View File

@ -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();

View File

@ -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'),
);
}

View File

@ -152,7 +152,7 @@ class ExportYamlTest extends AbstractTestCase
public function testExportDBCreate(): void
{
self::assertTrue(
$this->object->exportDBCreate('testDB', 'database'),
$this->object->exportDBCreate('testDB'),
);
}

View File

@ -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(

View File

@ -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\''

View File

@ -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',