Merge pull request #19957 from kamil-tekiela/Refactor-ExportPlugin

Refactor export plugins
This commit is contained in:
Maurício Meneghini Fauth 2025-12-15 21:02:02 -03:00 committed by GitHub
commit 88eb22bc57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
42 changed files with 691 additions and 1503 deletions

View File

@ -23,6 +23,7 @@ use PhpMyAdmin\Error\ErrorHandler;
use PhpMyAdmin\Error\ErrorReport;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\Options;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Export\TemplateModel;
use PhpMyAdmin\FileListing;
use PhpMyAdmin\FlashMessenger;
@ -99,7 +100,7 @@ return [
'arguments' => ['@http_request', '@relation', '@template', '@config'],
],
'events' => ['class' => Events::class, 'arguments' => ['@dbi']],
Export::class => ['class' => Export::class, 'arguments' => ['@dbi']],
Export::class => ['class' => Export::class, 'arguments' => ['@dbi', '@' . OutputHandler::class]],
'export' => Export::class,
'export_options' => [
'class' => Options::class,
@ -235,6 +236,7 @@ return [
'class' => Operations::class,
'arguments' => ['$dbi' => '@dbi', '$relation' => '@relation', '$tableMover' => '@table_mover'],
],
OutputHandler::class => ['class' => OutputHandler::class],
'partitioning_maintenance' => [
'class' => Maintenance::class,
'arguments' => ['$dbi' => '@dbi'],

View File

@ -2223,30 +2223,12 @@ parameters:
count: 1
path: src/Controllers/Export/ExportController.php
-
message: '#^Parameter \#1 \$fileHandle of method PhpMyAdmin\\Export\\Export\:\:closeFile\(\) expects resource, resource\|null given\.$#'
identifier: argument.type
count: 1
path: src/Controllers/Export/ExportController.php
-
message: '#^Parameter \#3 \$tableStructure of method PhpMyAdmin\\Export\\Export\:\:exportDatabase\(\) expects array\<string\>, array\<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
count: 2
path: src/Controllers/Export/ExportController.php
-
message: '#^Static property PhpMyAdmin\\Export\\Export\:\:\$compression \(''''\|''gzip''\|''none''\|''zip''\) does not accept string\.$#'
identifier: assign.propertyType
count: 1
path: src/Controllers/Export/ExportController.php
-
message: '#^Static property PhpMyAdmin\\Export\\Export\:\:\$tableData \(array\<string\>\) does not accept array\<mixed, mixed\>\.$#'
identifier: assign.propertyType
@ -6144,15 +6126,6 @@ parameters:
count: 2
path: src/Export/Export.php
-
message: '''
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
Use dependency injection instead\.$#
'''
identifier: staticMethod.deprecated
count: 1
path: src/Export/Export.php
-
message: '#^Call to function in_array\(\) requires parameter \#3 to be set\.$#'
identifier: function.strict
@ -6198,19 +6171,7 @@ parameters:
-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 4
path: src/Export/Export.php
-
message: '#^Method PhpMyAdmin\\Export\\Export\:\:compress\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/Export/Export.php
-
message: '#^Only booleans are allowed in a negated boolean, string\|false given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
count: 3
path: src/Export/Export.php
-
@ -6219,12 +6180,6 @@ parameters:
count: 1
path: src/Export/Export.php
-
message: '#^Parameter \#1 \$stream of function fwrite expects resource, resource\|null given\.$#'
identifier: argument.type
count: 1
path: src/Export/Export.php
-
message: '#^Parameter \#2 \$dbAlias of method PhpMyAdmin\\Plugins\\ExportPlugin\:\:exportDBCreate\(\) expects string, mixed given\.$#'
identifier: argument.type
@ -6297,6 +6252,18 @@ parameters:
count: 1
path: src/Export/Options.php
-
message: '#^Only booleans are allowed in a negated boolean, string\|false given\.$#'
identifier: booleanNot.exprNotBoolean
count: 1
path: src/Export/OutputHandler.php
-
message: '#^Property PhpMyAdmin\\Export\\OutputHandler\:\:\$dumpBuffer \(string\) does not accept string\|false\.$#'
identifier: assign.propertyType
count: 2
path: src/Export/OutputHandler.php
-
message: '#^Parameter \#1 \$id of class PhpMyAdmin\\Export\\Template constructor expects int, mixed given\.$#'
identifier: argument.type
@ -9496,13 +9463,7 @@ parameters:
path: src/Plugins/Export/ExportPdf.php
-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 1
path: src/Plugins/Export/ExportPdf.php
-
message: '#^Parameter \#1 \$line of method PhpMyAdmin\\Export\\Export\:\:outputHandler\(\) expects string, mixed given\.$#'
message: '#^Parameter \#1 \$line of method PhpMyAdmin\\Export\\OutputHandler\:\:addLine\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Plugins/Export/ExportPdf.php

View File

@ -1313,32 +1313,6 @@
<MixedPropertyTypeCoercion>
<code><![CDATA[$tableData]]></code>
</MixedPropertyTypeCoercion>
<PossiblyInvalidArgument>
<code><![CDATA[$this->export->dumpBuffer]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code><![CDATA[$this->export->dumpBuffer]]></code>
<code><![CDATA[$this->export->dumpBuffer]]></code>
</PossiblyInvalidCast>
<PossiblyInvalidPropertyAssignmentValue>
<code><![CDATA[$this->export->compress(
$this->export->dumpBuffer,
Export::$compression,
$filename,
)]]></code>
<code><![CDATA[$this->export->compress(
$this->export->dumpBufferObjects,
Export::$compression,
$filename,
)]]></code>
</PossiblyInvalidPropertyAssignmentValue>
<PossiblyNullArgument>
<code><![CDATA[Export::$fileHandle]]></code>
</PossiblyNullArgument>
<PropertyTypeCoercion>
<code><![CDATA[$request->getParsedBodyParamAsString('compression')]]></code>
</PropertyTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$asSeparateFiles]]></code>
<code><![CDATA[$onServerParam]]></code>
@ -4169,9 +4143,6 @@
<ArgumentTypeCoercion>
<code><![CDATA[(string) ini_get('memory_limit')]]></code>
</ArgumentTypeCoercion>
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$dbAlias]]></code>
<code><![CDATA[$dbAlias]]></code>
@ -4221,15 +4192,10 @@
<MixedOperand>
<code><![CDATA[$tmpSelect]]></code>
</MixedOperand>
<PossiblyNullArgument>
<code><![CDATA[self::$fileHandle]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$error['message']]]></code>
</PossiblyNullArrayAccess>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! ini_get('zlib.output_compression')]]></code>
<code><![CDATA[empty($_POST['onserver_overwrite'])]]></code>
<code><![CDATA[empty($postParams['structure_or_data_forced'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
@ -4256,6 +4222,14 @@
<code><![CDATA[empty($config->settings['SaveDir'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Export/OutputHandler.php">
<PossiblyFalsePropertyAssignmentValue>
<code><![CDATA[$zipExtension->createFile($dumpBuffer, $filename)]]></code>
</PossiblyFalsePropertyAssignmentValue>
<RiskyTruthyFalsyComparison>
<code><![CDATA[! ini_get('zlib.output_compression')]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Export/Template.php">
<MixedArgument>
<code><![CDATA[$state['data']]]></code>
@ -6175,17 +6149,14 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$pdf->getPDFData()]]></code>
<code><![CDATA[$this->pdf->getPDFData()]]></code>
</MixedArgument>
<PossiblyInvalidPropertyAssignmentValue>
<code><![CDATA[$_POST['pdf_report_title']]]></code>
</PossiblyInvalidPropertyAssignmentValue>
<MixedAssignment>
<code><![CDATA[$this->pdfReportTitle]]></code>
</MixedAssignment>
<PropertyNotSetInConstructor>
<code><![CDATA[$pdf]]></code>
</PropertyNotSetInConstructor>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($_POST['pdf_report_title'])]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Plugins/Export/ExportPhparray.php">
<DeprecatedMethod>

View File

@ -13,6 +13,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
@ -37,7 +38,6 @@ use function in_array;
use function ini_set;
use function is_array;
use function register_shutdown_function;
use function time;
#[Route('/export', ['GET', 'POST'])]
final readonly class ExportController implements InvocableController
@ -76,12 +76,8 @@ final readonly class ExportController implements InvocableController
Current::$charset = $request->getParsedBodyParamAsString('charset');
}
if ($request->hasBodyParam('compression')) {
Export::$compression = $request->getParsedBodyParamAsString('compression');
}
if ($request->hasBodyParam('knjenc')) {
Export::$kanjiEncoding = $request->getParsedBodyParamAsString('knjenc');
$this->export->outputHandler->kanjiEncoding = $request->getParsedBodyParamAsString('knjenc');
}
if ($request->hasBodyParam('maxsize')) {
@ -99,7 +95,7 @@ final readonly class ExportController implements InvocableController
}
if ($request->hasBodyParam('xkana')) {
Export::$xkana = $request->getParsedBodyParamAsString('xkana');
$this->export->outputHandler->xkana = $request->getParsedBodyParamAsString('xkana');
}
// sanitize this parameter which will be used below in a file inclusion
@ -138,33 +134,32 @@ final readonly class ExportController implements InvocableController
/**
* init and variable checking
*/
Export::$compression = '';
Export::$saveOnServer = false;
Export::$bufferNeeded = false;
Export::$saveFilename = '';
Export::$fileHandle = null;
$filename = '';
$separateFiles = '';
// Is it a quick or custom export?
$isQuickExport = $quickOrCustom === 'quick';
$saveOnServer = false;
if ($outputFormat === 'astext') {
Export::$asFile = false;
OutputHandler::$asFile = false;
} else {
Export::$asFile = true;
OutputHandler::$asFile = true;
if ($asSeparateFiles && $compressionParam === 'zip') {
$separateFiles = $asSeparateFiles;
}
if (in_array($compressionParam, $compressionMethods, true)) {
Export::$compression = $compressionParam;
Export::$bufferNeeded = true;
$this->export->outputHandler->setCompression(
$compressionParam,
$this->config->settings['CompressOnFly'],
);
}
if (($isQuickExport && $quickExportOnServer) || (! $isQuickExport && $onServerParam)) {
// Will we save dump on server?
Export::$saveOnServer = $this->config->settings['SaveDir'] !== '';
$saveOnServer = $this->config->settings['SaveDir'] !== '';
}
}
@ -212,33 +207,23 @@ final readonly class ExportController implements InvocableController
}
register_shutdown_function([$this->export, 'shutdown']);
// Start with empty buffer
$this->export->dumpBuffer = '';
$this->export->dumpBufferLength = 0;
// Array of dump buffers - used in separate file exports
$this->export->dumpBufferObjects = [];
// We send fake headers to avoid browser timeout when buffering
Export::$timeStart = time();
Export::$outputKanjiConversion = Encoding::canConvertKanji();
$this->export->outputHandler->outputKanjiConversion = Encoding::canConvertKanji();
// Do we need to convert charset?
Export::$outputCharsetConversion = Export::$asFile
$this->export->outputHandler->outputCharsetConversion = OutputHandler::$asFile
&& Encoding::isSupported()
&& Current::$charset !== null && Current::$charset !== 'utf-8'
&& in_array(Current::$charset, Encoding::listEncodings(), true);
// Use on the fly compression?
Export::$onFlyCompression = $this->config->settings['CompressOnFly'] && Export::$compression === 'gzip';
if (Export::$onFlyCompression) {
Export::$memoryLimit = $this->export->getMemoryLimit();
if ($this->export->outputHandler->onFlyCompression) {
$this->export->outputHandler->memoryLimit = $this->export->getMemoryLimit();
}
// Generate filename and mime type if needed
$mimeType = '';
if (Export::$asFile) {
if (OutputHandler::$asFile) {
$filenameTemplate = $request->getParsedBodyParamAsString('filename_template', '');
if ((bool) $rememberTemplate) {
@ -247,21 +232,26 @@ final readonly class ExportController implements InvocableController
$filename = $this->export->getFinalFilename(
$exportPlugin,
Export::$compression,
Sanitize::sanitizeFilename(Util::expandUserString($filenameTemplate), true),
);
$mimeType = $this->export->getMimeType($exportPlugin, Export::$compression);
$mimeType = $this->export->getMimeType($exportPlugin);
}
// For raw query export, filename will be export.extension
if ($exportType === ExportType::Raw) {
$filename = $this->export->getFinalFilename($exportPlugin, Export::$compression, 'export');
$filename = $this->export->getFinalFilename($exportPlugin, 'export');
}
// Open file on server if needed
if (Export::$saveOnServer) {
[Export::$saveFilename, $message, Export::$fileHandle] = $this->export->openFile($filename, $isQuickExport);
if ($saveOnServer) {
$message = $this->export->outputHandler->openFile(
$this->config->settings['SaveDir'] ?? '',
$filename,
$isQuickExport,
$request->getParsedBodyParam('quick_export_onserver_overwrite') === 'saveitover',
$request->getParsedBodyParam('onserver_overwrite') === 'saveitover',
);
// problem opening export file on server?
if ($message !== null) {
@ -270,7 +260,7 @@ final readonly class ExportController implements InvocableController
return $this->response->response();
}
} elseif (Export::$asFile) {
} elseif (OutputHandler::$asFile) {
/**
* Send headers depending on whether the user chose to download a dump file
* or not
@ -300,8 +290,7 @@ final readonly class ExportController implements InvocableController
try {
// Re - initialize
$this->export->dumpBuffer = '';
$this->export->dumpBufferLength = 0;
$this->export->outputHandler->clearBuffer();
// TODO: This is a temporary hack to avoid GLOBALS. Replace this with something better.
if ($exportPlugin instanceof ExportXml) {
@ -404,7 +393,7 @@ final readonly class ExportController implements InvocableController
// Ignore
}
if (Export::$saveOnServer && Current::$message !== null) {
if ($saveOnServer && Current::$message !== null) {
$location = $this->export->getPageLocationAndSaveMessage($exportType, Current::$message);
$this->response->redirect($location);
@ -414,47 +403,26 @@ final readonly class ExportController implements InvocableController
/**
* Send the dump as a file...
*/
if (! Export::$asFile) {
if (! OutputHandler::$asFile) {
echo $this->export->getHtmlForDisplayedExportFooter($exportType, Current::$database, Current::$table);
return $this->response->response();
}
// Convert the charset if required.
if (Export::$outputCharsetConversion) {
$this->export->dumpBuffer = Encoding::convertString(
'utf-8',
Current::$charset ?? 'utf-8',
$this->export->dumpBuffer,
);
}
$this->export->outputHandler->convertBufferCharset();
// Compression needed?
if (Export::$compression !== '') {
if ($separateFiles !== '') {
$this->export->dumpBuffer = $this->export->compress(
$this->export->dumpBufferObjects,
Export::$compression,
$filename,
);
} else {
$this->export->dumpBuffer = $this->export->compress(
$this->export->dumpBuffer,
Export::$compression,
$filename,
);
}
}
$this->export->outputHandler->compress($separateFiles !== '', $filename);
/* If we saved on server, we have to close file now */
if (Export::$saveOnServer) {
$message = $this->export->closeFile(Export::$fileHandle, $this->export->dumpBuffer, Export::$saveFilename);
if ($saveOnServer) {
$message = $this->export->outputHandler->closeFile();
$location = $this->export->getPageLocationAndSaveMessage($exportType, $message);
$this->response->redirect($location);
return $this->response->response();
}
return $this->responseFactory->createResponse()->write($this->export->dumpBuffer);
return $this->responseFactory->createResponse()->write($this->export->outputHandler->getBuffer());
}
}

View File

@ -9,15 +9,12 @@ namespace PhpMyAdmin\Export;
use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\FlashMessenger;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
use PhpMyAdmin\MessageType;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -26,80 +23,38 @@ use PhpMyAdmin\Plugins\SchemaPlugin;
use PhpMyAdmin\Table\Table;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\UserAgentParser;
use PhpMyAdmin\ZipExtension;
use function __;
use function array_filter;
use function array_merge_recursive;
use function error_get_last;
use function fclose;
use function file_exists;
use function fopen;
use function function_exists;
use function fwrite;
use function gzencode;
use function header;
use function htmlentities;
use function htmlspecialchars;
use function http_build_query;
use function implode;
use function in_array;
use function ini_get;
use function ini_parse_quantity;
use function is_array;
use function is_file;
use function is_numeric;
use function is_string;
use function is_writable;
use function mb_strlen;
use function mb_strtolower;
use function mb_substr;
use function ob_list_handlers;
use function preg_match;
use function preg_replace;
use function str_contains;
use function strlen;
use function substr;
use function time;
use const ENT_COMPAT;
/**
* PhpMyAdmin\Export\Export class
*/
class Export
{
public string $dumpBuffer = '';
public int $dumpBufferLength = 0;
/** @var string[] */
public array $dumpBufferObjects = [];
public static bool $asFile = false;
public static bool $saveOnServer = false;
public static bool $outputCharsetConversion = false;
public static bool $outputKanjiConversion = false;
public static bool $bufferNeeded = false;
public static bool $singleTable = false;
/** @var ''|'none'|'zip'|'gzip' */
public static string $compression = '';
/** @var resource|null */
public static mixed $fileHandle = null;
public static string $kanjiEncoding = '';
public static string $xkana = '';
public static string $maxSize = '';
public static int $memoryLimit = 0;
public static bool $onFlyCompression = false;
/** @var array<string> */
public static array $tableData = [];
public static string $saveFilename = '';
public static int $timeStart = 0;
public function __construct(private DatabaseInterface $dbi)
public function __construct(private DatabaseInterface $dbi, public OutputHandler $outputHandler)
{
}
@ -117,131 +72,6 @@ class Export
$_SESSION['pma_export_error'] = $error['message'];
}
/**
* Detect ob_gzhandler
*/
public function isGzHandlerEnabled(): bool
{
/** @var string[] $handlers */
$handlers = ob_list_handlers();
return in_array('ob_gzhandler', $handlers, true);
}
/**
* Detect whether gzencode is needed; it might not be needed if
* the server is already compressing by itself
*/
public function gzencodeNeeded(): bool
{
/**
* We should gzencode only if the function exists
* but we don't want to compress twice, therefore
* gzencode only if transparent compression is not enabled
* but transparent compression does not apply when saving to server
*/
return function_exists('gzencode')
&& ((! ini_get('zlib.output_compression')
&& ! $this->isGzHandlerEnabled())
|| self::$saveOnServer
|| (new UserAgentParser(Core::getEnv('HTTP_USER_AGENT')))->getUserBrowserAgent() === 'CHROME');
}
/**
* Output handler for all exports, if needed buffering, it stores data into
* $this->dumpBuffer, otherwise it prints them out.
*
* @param string $line the insert statement
*/
public function outputHandler(string $line): bool
{
// Kanji encoding convert feature
if (self::$outputKanjiConversion) {
$line = Encoding::kanjiStrConv($line, self::$kanjiEncoding, self::$xkana);
}
// If we have to buffer data, we will perform everything at once at the end
if (self::$bufferNeeded) {
$this->dumpBuffer .= $line;
if (self::$onFlyCompression) {
$this->dumpBufferLength += strlen($line);
if ($this->dumpBufferLength > self::$memoryLimit) {
if (self::$outputCharsetConversion) {
$this->dumpBuffer = Encoding::convertString(
'utf-8',
Current::$charset ?? 'utf-8',
$this->dumpBuffer,
);
}
if (self::$compression === 'gzip' && $this->gzencodeNeeded()) {
// as a gzipped file
// without the optional parameter level because it bugs
$this->dumpBuffer = (string) gzencode($this->dumpBuffer);
}
if (self::$saveOnServer) {
$writeResult = @fwrite(self::$fileHandle, $this->dumpBuffer);
// Here, use strlen rather than mb_strlen to get the length
// in bytes to compare against the number of bytes written.
if ($writeResult === false || $writeResult !== strlen($this->dumpBuffer)) {
Current::$message = Message::error(
__('Insufficient space to save the file %s.'),
);
Current::$message->addParam(self::$saveFilename);
return false;
}
} else {
echo $this->dumpBuffer;
}
$this->dumpBuffer = '';
$this->dumpBufferLength = 0;
}
} else {
$timeNow = time();
if (self::$timeStart >= $timeNow + 30) {
self::$timeStart = $timeNow;
header('X-pmaPing: Pong');
}
}
} elseif (self::$asFile) {
if (self::$outputCharsetConversion) {
$line = Encoding::convertString('utf-8', Current::$charset ?? 'utf-8', $line);
}
if (self::$saveOnServer && $line !== '') {
$writeResult = self::$fileHandle !== null ? @fwrite(self::$fileHandle, $line) : false;
// Here, use strlen rather than mb_strlen to get the length
// in bytes to compare against the number of bytes written.
if ($writeResult === 0 || $writeResult === false || $writeResult !== strlen($line)) {
Current::$message = Message::error(
__('Insufficient space to save the file %s.'),
);
Current::$message->addParam(self::$saveFilename);
return false;
}
$timeNow = time();
if (self::$timeStart >= $timeNow + 30) {
self::$timeStart = $timeNow;
header('X-pmaPing: Pong');
}
} else {
// We export as file - output normally
echo $line;
}
} else {
// We export as html - replace special chars
echo htmlspecialchars($line, ENT_COMPAT);
}
return true;
}
/**
* Returns HTML containing the footer for a displayed export
*
@ -302,7 +132,6 @@ class Export
public function getFinalFilename(
ExportPlugin $exportPlugin,
string $compression,
string $filename,
): string {
// Grab basic dump extension and mime type
@ -316,18 +145,18 @@ class Export
}
// If dump is going to be compressed, add compression to extension
if ($compression === 'gzip') {
if ($this->outputHandler->compression === 'gzip') {
$filename .= '.gz';
} elseif ($compression === 'zip') {
} elseif ($this->outputHandler->compression === 'zip') {
$filename .= '.zip';
}
return $filename;
}
public function getMimeType(ExportPlugin $exportPlugin, string $compression): string
public function getMimeType(ExportPlugin $exportPlugin): string
{
return match ($compression) {
return match ($this->outputHandler->compression) {
'gzip' => 'application/x-gzip',
'zip' => 'application/zip',
default => $exportPlugin->getProperties()->getMimeType(),
@ -350,138 +179,6 @@ class Export
}
}
/**
* Open the export file
*
* @param string $filename the export filename
* @param bool $quickExport whether it's a quick export or not
*
* @psalm-return array{string, Message|null, resource|null}
*/
public function openFile(string $filename, bool $quickExport): array
{
$fileHandle = null;
$message = null;
$doNotSaveItOver = true;
if (isset($_POST['quick_export_onserver_overwrite'])) {
$doNotSaveItOver = $_POST['quick_export_onserver_overwrite'] !== 'saveitover';
}
$saveFilename = Util::userDir(Config::getInstance()->settings['SaveDir'] ?? '')
. preg_replace('@[/\\\\]@', '_', $filename);
if (
@file_exists($saveFilename)
&& ((! $quickExport && empty($_POST['onserver_overwrite']))
|| ($quickExport
&& $doNotSaveItOver))
) {
$message = Message::error(
__(
'File %s already exists on server, change filename or check overwrite option.',
),
);
$message->addParam($saveFilename);
} elseif (@is_file($saveFilename) && ! @is_writable($saveFilename)) {
$message = Message::error(
__(
'The web server does not have permission to save the file %s.',
),
);
$message->addParam($saveFilename);
} else {
$fileHandle = @fopen($saveFilename, 'w');
if ($fileHandle === false) {
$fileHandle = null;
$message = Message::error(
__(
'The web server does not have permission to save the file %s.',
),
);
$message->addParam($saveFilename);
}
}
return [$saveFilename, $message, $fileHandle];
}
/**
* Close the export file
*
* @param resource $fileHandle the export file handle
* @param string $dumpBuffer the current dump buffer
* @param string $saveFilename the export filename
*
* @return Message a message object (or empty string)
*/
public function closeFile(
$fileHandle,
string $dumpBuffer,
string $saveFilename,
): Message {
$writeResult = @fwrite($fileHandle, $dumpBuffer);
fclose($fileHandle);
// Here, use strlen rather than mb_strlen to get the length
// in bytes to compare against the number of bytes written.
if ($dumpBuffer !== '' && $writeResult !== strlen($dumpBuffer)) {
return new Message(
__('Insufficient space to save the file %s.'),
MessageType::Error,
[$saveFilename],
);
}
return new Message(
__('Dump has been saved to file %s.'),
MessageType::Success,
[$saveFilename],
);
}
/**
* Compress the export buffer
*
* @param string[]|string $dumpBuffer the current dump buffer
* @param string $compression the compression mode
* @param string $filename the filename
*/
public function compress(array|string $dumpBuffer, string $compression, string $filename): array|string|bool
{
if ($compression === 'zip' && function_exists('gzcompress')) {
$zipExtension = new ZipExtension();
$filename = substr($filename, 0, -4); // remove extension (.zip)
$dumpBuffer = $zipExtension->createFile($dumpBuffer, $filename);
} elseif ($compression === 'gzip' && $this->gzencodeNeeded() && is_string($dumpBuffer)) {
// without the optional parameter level because it bugs
$dumpBuffer = gzencode($dumpBuffer);
}
return $dumpBuffer;
}
/**
* Saves the dump buffer for a particular table in an array
* Used in separate files export
*
* @param string $objectName the name of current object to be stored
* @param bool $append optional boolean to append to an existing index or not
*/
public function saveObjectInBuffer(string $objectName, bool $append = false): void
{
if ($this->dumpBuffer !== '') {
if ($append && isset($this->dumpBufferObjects[$objectName])) {
$this->dumpBufferObjects[$objectName] .= $this->dumpBuffer;
} else {
$this->dumpBufferObjects[$objectName] = $this->dumpBuffer;
}
}
// Re - initialize
$this->dumpBuffer = '';
$this->dumpBufferLength = 0;
}
/**
* Returns HTML containing the header for a displayed export
*
@ -550,7 +247,7 @@ class Export
continue;
}
$this->saveObjectInBuffer($currentDb);
$this->outputHandler->saveObjectInBuffer($currentDb);
}
}
@ -586,7 +283,7 @@ class Export
}
if ($separateFiles === 'database') {
$this->saveObjectInBuffer('database', true);
$this->outputHandler->saveObjectInBuffer('database', true);
}
$structureOrData = $exportPlugin->getStructureOrData();
@ -599,7 +296,7 @@ class Export
$exportPlugin->exportRoutines($db->getName(), $aliases);
if ($separateFiles === 'database') {
$this->saveObjectInBuffer('routines');
$this->outputHandler->saveObjectInBuffer('routines');
}
}
@ -673,7 +370,7 @@ class Export
// this buffer was filled, we save it and go to the next one
if ($separateFiles === 'database') {
$this->saveObjectInBuffer('table_' . $table);
$this->outputHandler->saveObjectInBuffer('table_' . $table);
}
// now export the triggers (needs to be done after the data because
@ -694,7 +391,7 @@ class Export
continue;
}
$this->saveObjectInBuffer('table_' . $table, true);
$this->outputHandler->saveObjectInBuffer('table_' . $table, true);
}
if ($exportPlugin instanceof ExportSql && $exportPlugin->hasCreateView()) {
@ -712,7 +409,7 @@ class Export
continue;
}
$this->saveObjectInBuffer('view_' . $view);
$this->outputHandler->saveObjectInBuffer('view_' . $view);
}
}
@ -728,12 +425,12 @@ class Export
$exportPlugin->exportMetadata($db->getName(), $tables, $metadataTypes);
if ($separateFiles === 'database') {
$this->saveObjectInBuffer('metadata');
$this->outputHandler->saveObjectInBuffer('metadata');
}
}
if ($separateFiles === 'database') {
$this->saveObjectInBuffer('extra');
$this->outputHandler->saveObjectInBuffer('extra');
}
if (
@ -750,7 +447,7 @@ class Export
return;
}
$this->saveObjectInBuffer('events');
$this->outputHandler->saveObjectInBuffer('events');
}
/**

View File

@ -0,0 +1,303 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Export;
use PhpMyAdmin\Core;
use PhpMyAdmin\Current;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Message;
use PhpMyAdmin\MessageType;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\UserAgentParser;
use PhpMyAdmin\ZipExtension;
use function __;
use function fclose;
use function file_exists;
use function fopen;
use function function_exists;
use function fwrite;
use function gzencode;
use function htmlspecialchars;
use function in_array;
use function ini_get;
use function is_file;
use function is_string;
use function is_writable;
use function ob_list_handlers;
use function preg_replace;
use function strlen;
use function substr;
use const ENT_COMPAT;
class OutputHandler
{
private string $dumpBuffer = '';
private int $dumpBufferLength = 0;
/** @var string[] */
private array $dumpBufferObjects = [];
public bool $outputCharsetConversion = false;
public bool $outputKanjiConversion = false;
public static bool $asFile = false;
private string $saveFilename = '';
/** @var resource|null */
private mixed $fileHandle = null;
/** @var ''|'zip'|'gzip' */
public string $compression = '';
public string $kanjiEncoding = '';
public string $xkana = '';
public int $memoryLimit = 0;
public bool $onFlyCompression = false;
public function addLine(string $line): bool
{
// Kanji encoding convert feature
if ($this->outputKanjiConversion) {
$line = Encoding::kanjiStrConv($line, $this->kanjiEncoding, $this->xkana);
}
// If we have to buffer data, we will perform everything at once at the end
if ($this->compression !== '') {
$this->dumpBuffer .= $line;
if ($this->onFlyCompression) {
$this->dumpBufferLength += strlen($line);
if ($this->dumpBufferLength > $this->memoryLimit) {
$this->convertBufferCharset();
if ($this->compression === 'gzip' && $this->gzencodeNeeded()) {
// as a gzipped file
// without the optional parameter level because it bugs
$this->dumpBuffer = (string) gzencode($this->dumpBuffer);
}
if ($this->fileHandle !== null) {
$writeResult = @fwrite($this->fileHandle, $this->dumpBuffer);
if ($writeResult !== strlen($this->dumpBuffer)) {
Current::$message = Message::error(__('Insufficient space to save the file %s.'));
Current::$message->addParam($this->saveFilename);
return false;
}
} else {
echo $this->dumpBuffer;
}
$this->dumpBuffer = '';
$this->dumpBufferLength = 0;
}
}
return true;
}
if (! self::$asFile) {
// We export as html - replace special chars
echo htmlspecialchars($line, ENT_COMPAT);
return true;
}
if ($this->outputCharsetConversion) {
$line = Encoding::convertString('utf-8', Current::$charset ?? 'utf-8', $line);
}
if ($this->fileHandle !== null && $line !== '') {
$writeResult = @fwrite($this->fileHandle, $line);
if ($writeResult !== strlen($line)) {
Current::$message = Message::error(__('Insufficient space to save the file %s.'));
Current::$message->addParam($this->saveFilename);
return false;
}
} else {
// We export as file - output normally
echo $line;
}
return true;
}
/**
* Saves the dump buffer for a particular table in an array
* Used in separate files export
*
* @param string $objectName the name of current object to be stored
* @param bool $append optional boolean to append to an existing index or not
*/
public function saveObjectInBuffer(string $objectName, bool $append = false): void
{
if ($this->dumpBuffer !== '') {
if ($append && isset($this->dumpBufferObjects[$objectName])) {
$this->dumpBufferObjects[$objectName] .= $this->dumpBuffer;
} else {
$this->dumpBufferObjects[$objectName] = $this->dumpBuffer;
}
}
// Re - initialize
$this->dumpBuffer = '';
$this->dumpBufferLength = 0;
}
/**
* Sets the compression method
*
* @param 'zip'|'gzip' $compression
*/
public function setCompression(string $compression, bool $compressOnFly = false): void
{
$this->compression = $compression;
if ($compression !== 'gzip' || ! $compressOnFly) {
return;
}
$this->onFlyCompression = true;
}
public function compress(bool $separateFiles, string $filename): void
{
$dumpBuffer = $separateFiles
? $this->dumpBufferObjects
: $this->dumpBuffer;
if ($this->compression === 'zip' && function_exists('gzcompress')) {
$zipExtension = new ZipExtension();
$filename = substr($filename, 0, -4); // remove extension (.zip)
$this->dumpBuffer = $zipExtension->createFile($dumpBuffer, $filename);
} elseif ($this->compression === 'gzip' && $this->gzencodeNeeded() && is_string($dumpBuffer)) {
// without the optional parameter level because it bugs
$this->dumpBuffer = gzencode($dumpBuffer);
}
}
public function openFile(
string $saveDirectory,
string $filename,
bool $quickExport,
bool $quickOverwriteFile,
bool $overwriteFile,
): Message|null {
$this->saveFilename = Util::userDir($saveDirectory) . preg_replace('@[/\\\\]@', '_', $filename);
if (
@file_exists($this->saveFilename)
&& ((! $quickExport && ! $overwriteFile)
|| ($quickExport && ! $quickOverwriteFile))
) {
$message = Message::error(
__(
'File %s already exists on server, change filename or check overwrite option.',
),
);
$message->addParam($this->saveFilename);
return $message;
}
if (@is_file($this->saveFilename) && ! @is_writable($this->saveFilename)) {
$message = Message::error(
__(
'The web server does not have permission to save the file %s.',
),
);
$message->addParam($this->saveFilename);
return $message;
}
$fileHandle = @fopen($this->saveFilename, 'w');
if ($fileHandle === false) {
$message = Message::error(
__(
'The web server does not have permission to save the file %s.',
),
);
$message->addParam($this->saveFilename);
return $message;
}
$this->fileHandle = $fileHandle;
return null;
}
public function closeFile(): Message
{
if ($this->fileHandle !== null) {
$fileHandle = $this->fileHandle;
$this->fileHandle = null;
$writeResult = @fwrite($fileHandle, $this->dumpBuffer);
fclose($fileHandle);
if ($this->dumpBuffer !== '' && $writeResult !== strlen($this->dumpBuffer)) {
return new Message(
__('Insufficient space to save the file %s.'),
MessageType::Error,
[$this->saveFilename],
);
}
}
return new Message(
__('Dump has been saved to file %s.'),
MessageType::Success,
[$this->saveFilename],
);
}
public function clearBuffer(): void
{
$this->dumpBuffer = '';
$this->dumpBufferLength = 0;
}
public function getBuffer(): string
{
return $this->dumpBuffer;
}
public function convertBufferCharset(): void
{
if (! $this->outputCharsetConversion || $this->dumpBuffer === '') {
return;
}
$this->dumpBuffer = Encoding::convertString('utf-8', Current::$charset ?? 'utf-8', $this->dumpBuffer);
}
/**
* Detect whether gzencode is needed; it might not be needed if
* the server is already compressing by itself
*/
private function gzencodeNeeded(): bool
{
/**
* We should gzencode only if the function exists
* but we don't want to compress twice, therefore
* gzencode only if transparent compression is not enabled
* but transparent compression does not apply when saving to server
*/
return function_exists('gzencode')
&& ((! ini_get('zlib.output_compression')
&& ! $this->isGzHandlerEnabled())
|| $this->fileHandle !== null
|| (new UserAgentParser(Core::getEnv('HTTP_USER_AGENT')))->getUserBrowserAgent() === 'CHROME');
}
/**
* Detect ob_gzhandler
*/
private function isGzHandlerEnabled(): bool
{
/** @var string[] $handlers */
$handlers = ob_list_handlers();
return in_array('ob_gzhandler', $handlers, true);
}
}

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin;
use FilesystemIterator;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -78,7 +78,7 @@ class Plugins
/** @psalm-suppress MixedMethodCall */
return new $class(
$container->get(Relation::class),
$container->get(Export::class),
$container->get(OutputHandler::class),
$container->get(Transformations::class),
);
}
@ -158,7 +158,7 @@ class Plugins
$container = ContainerBuilder::getContainer();
$plugins[] = new $class(
$container->get(Relation::class),
$container->get(Export::class),
$container->get(OutputHandler::class),
$container->get(Transformations::class),
);
} elseif ($type === 'Import' && is_subclass_of($class, ImportPlugin::class)) {

View File

@ -82,54 +82,6 @@ class ExportCodegen extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
{
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in NHibernate format
*
@ -145,10 +97,10 @@ class ExportCodegen extends ExportPlugin
array $aliases = [],
): bool {
if ($this->format === self::HANDLER_NHIBERNATE_XML) {
return $this->export->outputHandler($this->handleNHibernateXMLBody($db, $table, $aliases));
return $this->outputHandler->addLine($this->handleNHibernateXMLBody($db, $table, $aliases));
}
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $aliases));
return $this->outputHandler->addLine($this->handleNHibernateCSBody($db, $table, $aliases));
}
/**

View File

@ -22,8 +22,9 @@ use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use function __;
use function implode;
use function is_string;
use function str_contains;
use function str_replace;
use function strcspn;
use function strlen;
use function strtolower;
/**
@ -107,12 +108,8 @@ class ExportCsv extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
private function setupExportConfiguration(): void
{
// Here we just prepare some values for export
if ($this->terminated === '' || strtolower($this->terminated) === 'auto') {
$this->terminated = "\n";
} else {
@ -124,48 +121,6 @@ class ExportCsv extends ExportPlugin
}
$this->separator = str_replace('\\t', "\011", $this->separator);
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Alias of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
@ -183,34 +138,28 @@ class ExportCsv extends ExportPlugin
array $aliases = [],
): bool {
$dbi = DatabaseInterface::getInstance();
/**
* Gets the data from the database
*/
$result = $dbi->query($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
$charsNeedingEnclosure = $this->separator . $this->enclosed . $this->terminated;
// If required, get fields name at the first line
if ($this->columns) {
$insertFields = [];
foreach ($result->getFieldNames() as $colAs) {
$colAs = $this->getColumnAlias($aliases, $db, $table, $colAs);
if (
$this->enclosed === ''
|| (! str_contains($colAs, $this->separator)
&& ! str_contains($colAs, $this->enclosed)
&& ! str_contains($colAs, $this->terminated)
)
) {
$needsEnclosing = strcspn($colAs, $charsNeedingEnclosure) !== strlen($colAs);
if ($this->enclosed === '' || ! $needsEnclosing) {
$insertFields[] = $colAs;
} else {
$insertFields[] = $this->enclosed
. str_replace($this->enclosed, $this->escaped . $this->enclosed, $colAs)
. $this->enclosed;
continue;
}
$insertFields[] = $this->enclosed
. str_replace($this->enclosed, $this->escaped . $this->enclosed, $colAs)
. $this->enclosed;
}
$schemaInsert = implode($this->separator, $insertFields);
if (! $this->export->outputHandler($schemaInsert . $this->terminated)) {
if (! $this->outputHandler->addLine($schemaInsert . $this->terminated)) {
return false;
}
}
@ -221,50 +170,45 @@ class ExportCsv extends ExportPlugin
foreach ($row as $field) {
if ($field === null) {
$insertValues[] = $this->null;
} elseif ($field !== '') {
// remove CRLF characters within field
if ($this->removeCrLf) {
$field = str_replace(
["\r", "\n"],
'',
$field,
);
}
if (
$this->enclosed === ''
|| (! str_contains($field, $this->separator)
&& ! str_contains($field, $this->enclosed)
&& ! str_contains($field, $this->terminated)
)
) {
$insertValues[] = $field;
} elseif ($this->escaped !== $this->enclosed) {
// also double the escape string if found in the data
$insertValues[] = $this->enclosed
. str_replace(
$this->enclosed,
$this->escaped . $this->enclosed,
str_replace(
$this->escaped,
$this->escaped . $this->escaped,
$field,
),
)
. $this->enclosed;
} else {
// avoid a problem when escape string equals enclose
$insertValues[] = $this->enclosed
. str_replace($this->enclosed, $this->escaped . $this->enclosed, $field)
. $this->enclosed;
}
} else {
$insertValues[] = '';
continue;
}
if ($field === '') {
$insertValues[] = '';
continue;
}
// remove CRLF characters within field
if ($this->removeCrLf) {
$field = str_replace(["\r", "\n"], '', $field);
}
if ($this->enclosed === '') {
$insertValues[] = $field;
continue;
}
$needsEnclosing = strcspn($field, $charsNeedingEnclosure) !== strlen($field);
if (! $needsEnclosing) {
$insertValues[] = $field;
continue;
}
if ($this->escaped !== $this->enclosed) {
// also double the escape string if found in the data
$field = str_replace($this->escaped, $this->escaped . $this->escaped, $field);
$field = str_replace($this->enclosed, $this->escaped . $this->enclosed, $field);
} else {
// avoid a problem when escape string equals enclose
$field = str_replace($this->enclosed, $this->escaped . $this->enclosed, $field);
}
$insertValues[] = $this->enclosed . $field . $this->enclosed;
}
$schemaInsert = implode($this->separator, $insertValues);
if (! $this->export->outputHandler($schemaInsert . $this->terminated)) {
if (! $this->outputHandler->addLine($schemaInsert . $this->terminated)) {
return false;
}
}
@ -319,6 +263,8 @@ class ExportCsv extends ExportPlugin
$request->getParsedBodyParam('csv_null'),
$exportConfig['csv_null'] ?? $this->null,
);
$this->setupExportConfiguration();
}
private function setStringValue(mixed $fromRequest, mixed $fromConfig): string

View File

@ -102,12 +102,8 @@ class ExportExcel extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
private function setupExportConfiguration(): void
{
// Here we just prepare some values for export
$this->terminated = "\015\012";
switch ($this->edition) {
case 'win': // as tested on Windows with Excel 2002 and Excel 2007
@ -121,48 +117,6 @@ class ExportExcel extends ExportPlugin
$this->enclosed = '"';
$this->escaped = '"';
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Alias of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
@ -201,7 +155,7 @@ class ExportExcel extends ExportPlugin
}
$schemaInsert = implode($this->separator, $insertFields);
if (! $this->export->outputHandler($schemaInsert . $this->terminated)) {
if (! $this->outputHandler->addLine($schemaInsert . $this->terminated)) {
return false;
}
}
@ -252,7 +206,7 @@ class ExportExcel extends ExportPlugin
}
$schemaInsert = implode($this->separator, $insertValues);
if (! $this->export->outputHandler($schemaInsert . $this->terminated)) {
if (! $this->outputHandler->addLine($schemaInsert . $this->terminated)) {
return false;
}
}
@ -295,22 +249,8 @@ class ExportExcel extends ExportPlugin
$request->getParsedBodyParam('excel_null'),
$exportConfig['excel_null'] ?? null,
);
$this->separator = $this->setStringValue(
$request->getParsedBodyParam('excel_separator'),
$exportConfig['excel_separator'] ?? null,
);
$this->enclosed = $this->setStringValue(
$request->getParsedBodyParam('excel_enclosed'),
$exportConfig['excel_enclosed'] ?? null,
);
$this->escaped = $this->setStringValue(
$request->getParsedBodyParam('excel_escaped'),
$exportConfig['excel_escaped'] ?? null,
);
$this->terminated = $this->setStringValue(
$request->getParsedBodyParam('excel_terminated'),
$exportConfig['excel_terminated'] ?? null,
);
$this->setupExportConfiguration();
}
private function setStringValue(mixed $fromRequest, mixed $fromConfig): string

View File

@ -106,7 +106,7 @@ class ExportHtmlword extends ExportPlugin
*/
public function exportHeader(): bool
{
return $this->export->outputHandler(
return $this->outputHandler->addLine(
'<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
@ -127,7 +127,7 @@ class ExportHtmlword extends ExportPlugin
*/
public function exportFooter(): bool
{
return $this->export->outputHandler('</body></html>');
return $this->outputHandler->addLine('</body></html>');
}
/**
@ -142,32 +142,11 @@ class ExportHtmlword extends ExportPlugin
$dbAlias = $db;
}
return $this->export->outputHandler(
return $this->outputHandler->addLine(
'<h1>' . __('Database') . ' ' . htmlspecialchars($dbAlias) . '</h1>',
);
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in HTML-Word format
*
@ -185,7 +164,7 @@ class ExportHtmlword extends ExportPlugin
$tableAlias = $this->getTableAlias($aliases, $db, $table);
if (
! $this->export->outputHandler(
! $this->outputHandler->addLine(
'<h2>'
. __('Dumping data for table') . ' ' . htmlspecialchars($tableAlias)
. '</h2>',
@ -194,7 +173,7 @@ class ExportHtmlword extends ExportPlugin
return false;
}
if (! $this->export->outputHandler('<table width="100%" cellspacing="1">')) {
if (! $this->outputHandler->addLine('<table width="100%" cellspacing="1">')) {
return false;
}
@ -216,7 +195,7 @@ class ExportHtmlword extends ExportPlugin
}
$schemaInsert .= '</tr>';
if (! $this->export->outputHandler($schemaInsert)) {
if (! $this->outputHandler->addLine($schemaInsert)) {
return false;
}
}
@ -231,12 +210,12 @@ class ExportHtmlword extends ExportPlugin
}
$schemaInsert .= '</tr>';
if (! $this->export->outputHandler($schemaInsert)) {
if (! $this->outputHandler->addLine($schemaInsert)) {
return false;
}
}
return $this->export->outputHandler('</table>');
return $this->outputHandler->addLine('</table>');
}
/**
@ -501,7 +480,7 @@ class ExportHtmlword extends ExportPlugin
$dump .= $this->getTableDefStandIn($db, $table, $aliases);
}
return $this->export->outputHandler($dump);
return $this->outputHandler->addLine($dump);
}
/**

View File

@ -116,7 +116,7 @@ class ExportJson extends ExportPlugin
return false;
}
return $this->export->outputHandler('[' . "\n" . $data . ',' . "\n");
return $this->outputHandler->addLine('[' . "\n" . $data . ',' . "\n");
}
/**
@ -124,7 +124,7 @@ class ExportJson extends ExportPlugin
*/
public function exportFooter(): bool
{
return $this->export->outputHandler(']' . "\n");
return $this->outputHandler->addLine(']' . "\n");
}
/**
@ -144,28 +144,7 @@ class ExportJson extends ExportPlugin
return false;
}
return $this->export->outputHandler($data . ',' . "\n");
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
return $this->outputHandler->addLine($data . ',' . "\n");
}
/**
@ -186,7 +165,7 @@ class ExportJson extends ExportPlugin
$tableAlias = $this->getTableAlias($aliases, $db, $table);
if (! $this->first) {
if (! $this->export->outputHandler(',')) {
if (! $this->outputHandler->addLine(',')) {
return false;
}
} else {
@ -229,7 +208,7 @@ class ExportJson extends ExportPlugin
): bool {
[$header, $footer] = explode('"@@DATA@@"', $buffer);
if (! $this->export->outputHandler($header . "\n" . '[' . "\n")) {
if (! $this->outputHandler->addLine($header . "\n" . '[' . "\n")) {
return false;
}
@ -255,7 +234,7 @@ class ExportJson extends ExportPlugin
// Output table name as comment if this is the first record of the table
if ($recordCnt > 1) {
if (! $this->export->outputHandler(',' . "\n")) {
if (! $this->outputHandler->addLine(',' . "\n")) {
return false;
}
}
@ -293,12 +272,12 @@ class ExportJson extends ExportPlugin
return false;
}
if (! $this->export->outputHandler($encodedData)) {
if (! $this->outputHandler->addLine($encodedData)) {
return false;
}
}
return $this->export->outputHandler("\n" . ']' . "\n" . $footer . "\n");
return $this->outputHandler->addLine("\n" . ']' . "\n" . $footer . "\n");
}
/**

View File

@ -233,15 +233,7 @@ class ExportLatex extends ExportPlugin
. '% ' . __('Server version:') . ' ' . DatabaseInterface::getInstance()->getVersionString() . "\n"
. '% ' . __('PHP Version:') . ' ' . PHP_VERSION . "\n";
return $this->export->outputHandler($head);
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
return $this->outputHandler->addLine($head);
}
/**
@ -260,28 +252,7 @@ class ExportLatex extends ExportPlugin
. '% ' . __('Database:') . ' \'' . $dbAlias . '\'' . "\n"
. '% ' . "\n";
return $this->export->outputHandler($head);
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
return $this->outputHandler->addLine($head);
}
/**
@ -338,7 +309,7 @@ class ExportLatex extends ExportPlugin
. '} \\\\';
}
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -351,13 +322,13 @@ class ExportLatex extends ExportPlugin
}
$buffer = mb_substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
if (! $this->export->outputHandler($buffer . ' \\endfirsthead ' . "\n")) {
if (! $this->outputHandler->addLine($buffer . ' \\endfirsthead ' . "\n")) {
return false;
}
if ($this->caption) {
if (
! $this->export->outputHandler(
! $this->outputHandler->addLine(
'\\caption{'
. Util::expandUserString(
$this->dataContinuedCaption,
@ -371,10 +342,10 @@ class ExportLatex extends ExportPlugin
}
}
if (! $this->export->outputHandler($buffer . '\\endhead \\endfoot' . "\n")) {
if (! $this->outputHandler->addLine($buffer . '\\endhead \\endfoot' . "\n")) {
return false;
}
} elseif (! $this->export->outputHandler('\\\\ \hline')) {
} elseif (! $this->outputHandler->addLine('\\\\ \hline')) {
return false;
}
@ -399,14 +370,14 @@ class ExportLatex extends ExportPlugin
}
$buffer .= ' \\\\ \\hline ' . "\n";
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
}
$buffer = ' \\end{longtable}' . "\n";
return $this->export->outputHandler($buffer);
return $this->outputHandler->addLine($buffer);
}
/**
@ -472,7 +443,7 @@ class ExportLatex extends ExportPlugin
*/
$buffer = "\n" . '%' . "\n" . '% ' . __('Structure:') . ' '
. $tableAlias . "\n" . '%' . "\n" . ' \\begin{longtable}{';
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -542,7 +513,7 @@ class ExportLatex extends ExportPlugin
$buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . "\n";
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -594,14 +565,14 @@ class ExportLatex extends ExportPlugin
$buffer = str_replace("\000", ' & ', $localBuffer);
$buffer .= ' \\\\ \\hline ' . "\n";
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
}
$buffer = ' \\end{longtable}' . "\n";
return $this->export->outputHandler($buffer);
return $this->outputHandler->addLine($buffer);
}
/**

View File

@ -92,54 +92,6 @@ class ExportMediawiki extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
{
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Alias of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs table's structure
*
@ -214,7 +166,7 @@ class ExportMediawiki extends ExportPlugin
$output .= '|}' . str_repeat($this->exportCRLF(), 2);
}
return $this->export->outputHandler($output);
return $this->outputHandler->addLine($output);
}
/**
@ -288,7 +240,7 @@ class ExportMediawiki extends ExportPlugin
// End table construction
$output .= '|}' . str_repeat($this->exportCRLF(), 2);
return $this->export->outputHandler($output);
return $this->outputHandler->addLine($output);
}
/**

View File

@ -37,11 +37,6 @@ class ExportOds extends ExportPlugin
private bool $columns = false;
private string $null = '';
protected function init(): void
{
$this->buffer = '';
}
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
{
@ -147,46 +142,11 @@ class ExportOds extends ExportPlugin
{
$this->buffer .= '</office:spreadsheet></office:body></office:document-content>';
return $this->export->outputHandler(
OpenDocument::create(
'application/vnd.oasis.opendocument.spreadsheet',
$this->buffer,
),
return $this->outputHandler->addLine(
OpenDocument::create('application/vnd.oasis.opendocument.spreadsheet', $this->buffer),
);
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in NHibernate format
*

View File

@ -43,11 +43,6 @@ class ExportOdt extends ExportPlugin
private bool $doRelation = false;
private string $null = '';
protected function init(): void
{
$this->buffer = '';
}
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
{
@ -168,7 +163,7 @@ class ExportOdt extends ExportPlugin
{
$this->buffer .= '</office:text></office:body></office:document-content>';
return $this->export->outputHandler(OpenDocument::create(
return $this->outputHandler->addLine(OpenDocument::create(
'application/vnd.oasis.opendocument.text',
$this->buffer,
));
@ -194,27 +189,6 @@ class ExportOdt extends ExportPlugin
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in NHibernate format
*

View File

@ -45,18 +45,6 @@ class ExportPdf extends ExportPlugin
return 'pdf';
}
/**
* Initialize the local variables that are used for export PDF.
*/
protected function init(): void
{
if (! empty($_POST['pdf_report_title'])) {
$this->pdfReportTitle = $_POST['pdf_report_title'];
}
$this->setPdf(new Pdf('L', 'pt', 'A3'));
}
protected function setProperties(): ExportPluginProperties
{
$exportPluginProperties = new ExportPluginProperties();
@ -101,19 +89,13 @@ class ExportPdf extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
private function setupExportConfiguration(): void
{
$pdf = $this->getPdf();
$pdf->Open();
$this->pdf->Open();
$pdf->setTitleFontSize(18);
$pdf->setTitleText($this->pdfReportTitle);
$pdf->setTopMargin(30);
return true;
$this->pdf->setTitleFontSize(18);
$this->pdf->setTitleText($this->pdfReportTitle);
$this->pdf->setTopMargin(30);
}
/**
@ -121,42 +103,8 @@ class ExportPdf extends ExportPlugin
*/
public function exportFooter(): bool
{
$pdf = $this->getPdf();
// instead of $pdf->Output():
return $this->export->outputHandler($pdf->getPDFData());
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
return $this->outputHandler->addLine($this->pdf->getPDFData());
}
/**
@ -175,14 +123,13 @@ class ExportPdf extends ExportPlugin
): bool {
$dbAlias = $this->getDbAlias($aliases, $db);
$tableAlias = $this->getTableAlias($aliases, $db, $table);
$pdf = $this->getPdf();
$pdf->setCurrentDb($db);
$pdf->setCurrentTable($table);
$pdf->setDbAlias($dbAlias);
$pdf->setTableAlias($tableAlias);
$pdf->setAliases($aliases);
$pdf->setPurpose(__('Dumping data'));
$pdf->mysqlReport($sqlQuery);
$this->pdf->setCurrentDb($db);
$this->pdf->setCurrentTable($table);
$this->pdf->setDbAlias($dbAlias);
$this->pdf->setTableAlias($tableAlias);
$this->pdf->setAliases($aliases);
$this->pdf->setPurpose(__('Dumping data'));
$this->pdf->mysqlReport($sqlQuery);
return true;
}
@ -195,17 +142,16 @@ class ExportPdf extends ExportPlugin
*/
public function exportRawQuery(string|null $db, string $sqlQuery): bool
{
$pdf = $this->getPdf();
$pdf->setDbAlias('----');
$pdf->setTableAlias('----');
$pdf->setPurpose(__('Query result data'));
$this->pdf->setDbAlias('----');
$this->pdf->setTableAlias('----');
$this->pdf->setPurpose(__('Query result data'));
if ($db !== null) {
$pdf->setCurrentDb($db);
$this->pdf->setCurrentDb($db);
DatabaseInterface::getInstance()->selectDb($db);
}
$pdf->mysqlReport($sqlQuery);
$this->pdf->mysqlReport($sqlQuery);
return true;
}
@ -223,7 +169,6 @@ class ExportPdf extends ExportPlugin
$purpose = '';
$dbAlias = $this->getDbAlias($aliases, $db);
$tableAlias = $this->getTableAlias($aliases, $db, $table);
$pdf = $this->getPdf();
// getting purpose to show at top
switch ($exportMode) {
case 'create_table':
@ -239,42 +184,23 @@ class ExportPdf extends ExportPlugin
$purpose = __('Stand in');
}
$pdf->setCurrentDb($db);
$pdf->setCurrentTable($table);
$pdf->setDbAlias($dbAlias);
$pdf->setTableAlias($tableAlias);
$pdf->setAliases($aliases);
$pdf->setPurpose($purpose);
$this->pdf->setCurrentDb($db);
$this->pdf->setCurrentTable($table);
$this->pdf->setDbAlias($dbAlias);
$this->pdf->setTableAlias($tableAlias);
$this->pdf->setAliases($aliases);
$this->pdf->setPurpose($purpose);
match ($exportMode) {
'create_table', 'create_view' => $pdf->getTableDef($db, $table, $this->doRelation, true, $this->doMime),
'triggers' => $pdf->getTriggers($db, $table),
'create_table',
'create_view' => $this->pdf->getTableDef($db, $table, $this->doRelation, true, $this->doMime),
'triggers' => $this->pdf->getTriggers($db, $table),
default => true,
};
return true;
}
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
/**
* Gets the PhpMyAdmin\Plugins\Export\Helpers\Pdf instance
*/
private function getPdf(): Pdf
{
return $this->pdf;
}
/**
* Instantiates the PhpMyAdmin\Plugins\Export\Helpers\Pdf class
*
* @param Pdf $pdf The instance
*/
private function setPdf(Pdf $pdf): void
{
$this->pdf = $pdf;
}
public static function isAvailable(): bool
{
return class_exists(TCPDF::class) && extension_loaded('curl');
@ -283,6 +209,10 @@ class ExportPdf extends ExportPlugin
/** @inheritDoc */
public function setExportOptions(ServerRequest $request, array $exportConfig): void
{
$this->pdfReportTitle = $request->getParsedBodyParam('pdf_report_title', '');
$this->pdf = new Pdf('L', 'pt', 'A3');
$this->structureOrData = $this->setStructureOrData(
$request->getParsedBodyParam('pdf_structure_or_data'),
$exportConfig['pdf_structure_or_data'] ?? null,
@ -291,5 +221,7 @@ class ExportPdf extends ExportPlugin
$this->doRelation = (bool) ($request->getParsedBodyParam('pdf_relation')
?? $exportConfig['pdf_relation'] ?? false);
$this->doMime = (bool) ($request->getParsedBodyParam('pdf_mime') ?? $exportConfig['pdf_mime'] ?? false);
$this->setupExportConfiguration();
}
}

View File

@ -78,7 +78,7 @@ class ExportPhparray extends ExportPlugin
*/
public function exportHeader(): bool
{
$this->export->outputHandler(
$this->outputHandler->addLine(
'<?php' . "\n"
. '/**' . "\n"
. ' * Export to PHP Array plugin for phpMyAdmin' . "\n"
@ -89,14 +89,6 @@ class ExportPhparray extends ExportPlugin
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
@ -109,7 +101,7 @@ class ExportPhparray extends ExportPlugin
$dbAlias = $db;
}
$this->export->outputHandler(
$this->outputHandler->addLine(
'/**' . "\n"
. ' * Database ' . $this->commentString(Util::backquote($dbAlias))
. "\n" . ' */' . "\n",
@ -118,27 +110,6 @@ class ExportPhparray extends ExportPlugin
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in PHP array format
*
@ -189,7 +160,7 @@ class ExportPhparray extends ExportPlugin
. $this->commentString(Util::backquote($dbAlias)) . '.'
. $this->commentString(Util::backquote($tableAlias)) . ' */' . "\n";
$buffer .= '$' . $tableFixed . ' = array(';
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -212,7 +183,7 @@ class ExportPhparray extends ExportPlugin
}
$buffer .= ')';
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -222,7 +193,7 @@ class ExportPhparray extends ExportPlugin
$buffer .= "\n" . ');' . "\n";
return $this->export->outputHandler($buffer);
return $this->outputHandler->addLine($buffer);
}
/**

View File

@ -19,6 +19,7 @@ use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Export\StructureOrData;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -649,7 +650,7 @@ class ExportSql extends ExportPlugin
}
if ($text !== '') {
return $this->export->outputHandler($text);
return $this->outputHandler->addLine($text);
}
return false;
@ -732,7 +733,7 @@ class ExportSql extends ExportPlugin
DatabaseInterface::getInstance()->query('SET time_zone = "' . self::$oldTimezone . '"');
}
return $this->export->outputHandler($foot);
return $this->outputHandler->addLine($foot);
}
/**
@ -801,7 +802,7 @@ class ExportSql extends ExportPlugin
$head .= $this->possibleCRLF();
if (Export::$asFile) {
if (OutputHandler::$asFile) {
// we are saving as file, therefore we provide charset information
// so that a utility like the mysql client can interpret
// the file correctly
@ -828,7 +829,7 @@ class ExportSql extends ExportPlugin
$this->sentCharset = true;
}
return $this->export->outputHandler($head);
return $this->outputHandler->addLine($head);
}
/**
@ -845,13 +846,9 @@ class ExportSql extends ExportPlugin
if ($this->structureOrData !== StructureOrData::Data && $this->dropDatabase) {
if (
! $this->export->outputHandler(
! $this->outputHandler->addLine(
'DROP DATABASE IF EXISTS '
. Util::backquoteCompat(
$dbAlias,
$this->compatibility,
$this->useSqlBackquotes,
)
. Util::backquoteCompat($dbAlias, $this->compatibility, $this->useSqlBackquotes)
. ';' . "\n",
)
) {
@ -879,7 +876,7 @@ class ExportSql extends ExportPlugin
}
$createQuery .= ';' . "\n";
if (! $this->export->outputHandler($createQuery)) {
if (! $this->outputHandler->addLine($createQuery)) {
return false;
}
@ -895,18 +892,14 @@ class ExportSql extends ExportPlugin
private function exportUseStatement(string $db, string $compat): bool
{
if ($compat === 'NONE') {
return $this->export->outputHandler(
return $this->outputHandler->addLine(
'USE '
. Util::backquoteCompat(
$db,
$compat,
$this->useSqlBackquotes,
)
. Util::backquoteCompat($db, $compat, $this->useSqlBackquotes)
. ';' . "\n",
);
}
return $this->export->outputHandler('USE ' . $db . ';' . "\n");
return $this->outputHandler->addLine('USE ' . $db . ';' . "\n");
}
/**
@ -932,7 +925,7 @@ class ExportSql extends ExportPlugin
)
. $this->exportComment();
return $this->export->outputHandler($head);
return $this->outputHandler->addLine($head);
}
/**
@ -946,25 +939,25 @@ class ExportSql extends ExportPlugin
//add indexes to the sql dump file
if ($this->sqlIndexes !== null) {
$result = $this->export->outputHandler($this->sqlIndexes);
$result = $this->outputHandler->addLine($this->sqlIndexes);
$this->sqlIndexes = null;
}
//add auto increments to the sql dump file
if ($this->sqlAutoIncrements !== null) {
$result = $this->export->outputHandler($this->sqlAutoIncrements);
$result = $this->outputHandler->addLine($this->sqlAutoIncrements);
$this->sqlAutoIncrements = null;
}
//add views to the sql dump file
if ($this->sqlViews !== '') {
$result = $this->export->outputHandler($this->sqlViews);
$result = $this->outputHandler->addLine($this->sqlViews);
$this->sqlViews = '';
}
//add constraints to the sql dump file
if ($this->sqlConstraints !== null) {
$result = $this->export->outputHandler($this->sqlConstraints);
$result = $this->outputHandler->addLine($this->sqlConstraints);
$this->sqlConstraints = null;
}
@ -1022,7 +1015,7 @@ class ExportSql extends ExportPlugin
}
if ($text !== '') {
return $this->export->outputHandler($text);
return $this->outputHandler->addLine($text);
}
return false;
@ -1050,7 +1043,7 @@ class ExportSql extends ExportPlugin
. $this->exportComment()
. $this->exportComment(__('Metadata'))
. $this->exportComment();
if (! $this->export->outputHandler($comment)) {
if (! $this->outputHandler->addLine($comment)) {
return false;
}
@ -1128,7 +1121,7 @@ class ExportSql extends ExportPlugin
$comment .= $this->exportComment();
if (! $this->export->outputHandler($comment)) {
if (! $this->outputHandler->addLine($comment)) {
return false;
}
@ -1173,7 +1166,7 @@ class ExportSql extends ExportPlugin
$lastPage = "\n"
. 'SET @LAST_PAGE = LAST_INSERT_ID();'
. "\n";
if (! $this->export->outputHandler($lastPage)) {
if (! $this->outputHandler->addLine($lastPage)) {
return false;
}
@ -1982,7 +1975,7 @@ class ExportSql extends ExportPlugin
// but not in the case of export
$this->sqlConstraintsQuery = '';
return $this->export->outputHandler($dump);
return $this->outputHandler->addLine($dump);
}
/**
@ -2019,7 +2012,7 @@ class ExportSql extends ExportPlugin
. $this->exportComment()
. $this->possibleCRLF();
return $this->export->outputHandler($head);
return $this->outputHandler->addLine($head);
}
$result = $dbi->tryQuery($sqlQuery, ConnectionType::User, DatabaseInterface::QUERY_UNBUFFERED);
@ -2090,8 +2083,8 @@ class ExportSql extends ExportPlugin
)
. $this->exportComment()
. "\n";
$this->export->outputHandler($truncatehead);
$this->export->outputHandler($truncate);
$this->outputHandler->addLine($truncatehead);
$this->outputHandler->addLine($truncate);
}
// scheme for inserting fields
@ -2127,7 +2120,7 @@ class ExportSql extends ExportPlugin
)
. $this->exportComment()
. "\n";
if (! $this->export->outputHandler($head)) {
if (! $this->outputHandler->addLine($head)) {
return false;
}
}
@ -2135,13 +2128,9 @@ class ExportSql extends ExportPlugin
// We need to SET IDENTITY_INSERT ON for MSSQL
if ($currentRow === 0 && $this->compatibility === 'MSSQL') {
if (
! $this->export->outputHandler(
! $this->outputHandler->addLine(
'SET IDENTITY_INSERT '
. Util::backquoteCompat(
$tableAlias,
$this->compatibility,
$this->useSqlBackquotes,
)
. Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes)
. ' ON ;' . "\n",
)
) {
@ -2218,7 +2207,7 @@ class ExportSql extends ExportPlugin
$insertLine = '(' . implode(', ', $values) . ')';
$insertLineSize = mb_strlen($insertLine);
if ($this->maxQuerySize > 0 && $querySize + $insertLineSize > $this->maxQuerySize) {
if (! $this->export->outputHandler(';' . "\n")) {
if (! $this->outputHandler->addLine(';' . "\n")) {
return false;
}
@ -2234,26 +2223,22 @@ class ExportSql extends ExportPlugin
$insertLine = $schemaInsert . '(' . implode(', ', $values) . ')';
}
if (! $this->export->outputHandler(($currentRow === 1 ? '' : $separator . "\n") . $insertLine)) {
if (! $this->outputHandler->addLine(($currentRow === 1 ? '' : $separator . "\n") . $insertLine)) {
return false;
}
}
if ($currentRow > 0) {
if (! $this->export->outputHandler(';' . "\n")) {
if (! $this->outputHandler->addLine(';' . "\n")) {
return false;
}
}
// We need to SET IDENTITY_INSERT OFF for MSSQL
if ($this->compatibility === 'MSSQL' && $currentRow > 0) {
$outputSucceeded = $this->export->outputHandler(
$outputSucceeded = $this->outputHandler->addLine(
"\n" . 'SET IDENTITY_INSERT '
. Util::backquoteCompat(
$tableAlias,
$this->compatibility,
$this->useSqlBackquotes,
)
. Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes)
. ' OFF;' . "\n",
);
if (! $outputSucceeded) {

View File

@ -99,22 +99,6 @@ class ExportTexytext extends ExportPlugin
return $exportPluginProperties;
}
/**
* Outputs export header
*/
public function exportHeader(): bool
{
return true;
}
/**
* Outputs export footer
*/
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
*
@ -127,32 +111,11 @@ class ExportTexytext extends ExportPlugin
$dbAlias = $db;
}
return $this->export->outputHandler(
return $this->outputHandler->addLine(
'===' . __('Database') . ' ' . $dbAlias . "\n\n",
);
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in NHibernate format
*
@ -170,7 +133,7 @@ class ExportTexytext extends ExportPlugin
$tableAlias = $this->getTableAlias($aliases, $db, $table);
if (
! $this->export->outputHandler(
! $this->outputHandler->addLine(
$tableAlias !== ''
? '== ' . __('Dumping data for table') . ' ' . $tableAlias . "\n\n"
: '==' . __('Dumping data for query result') . "\n\n",
@ -195,7 +158,7 @@ class ExportTexytext extends ExportPlugin
}
$textOutput .= "\n|------\n";
if (! $this->export->outputHandler($textOutput)) {
if (! $this->outputHandler->addLine($textOutput)) {
return false;
}
}
@ -221,7 +184,7 @@ class ExportTexytext extends ExportPlugin
}
$textOutput .= "\n";
if (! $this->export->outputHandler($textOutput)) {
if (! $this->outputHandler->addLine($textOutput)) {
return false;
}
}
@ -466,7 +429,7 @@ class ExportTexytext extends ExportPlugin
$dump .= $this->getTableDefStandIn($db, $table, $aliases);
}
return $this->export->outputHandler($dump);
return $this->outputHandler->addLine($dump);
}
/**

View File

@ -12,7 +12,6 @@ use PhpMyAdmin\Database\Routines;
use PhpMyAdmin\Database\RoutineType;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\StructureOrData;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -195,7 +194,7 @@ class ExportXml extends ExportPlugin
|| $this->exportTriggers
|| $this->exportViews;
$charset = Export::$outputCharsetConversion ? Current::$charset : 'utf-8';
$charset = $this->outputHandler->outputCharsetConversion ? Current::$charset : 'utf-8';
$config = Config::getInstance();
$head = '<?xml version="1.0" encoding="' . $charset . '"?>' . "\n"
@ -337,7 +336,7 @@ class ExportXml extends ExportPlugin
}
}
return $this->export->outputHandler($head);
return $this->outputHandler->addLine($head);
}
/**
@ -347,7 +346,7 @@ class ExportXml extends ExportPlugin
{
$foot = '</pma_xml_export>';
return $this->export->outputHandler($foot);
return $this->outputHandler->addLine($foot);
}
/**
@ -369,7 +368,7 @@ class ExportXml extends ExportPlugin
. ' -->' . "\n" . ' <database name="'
. htmlspecialchars($dbAlias) . '">' . "\n";
return $this->export->outputHandler($head);
return $this->outputHandler->addLine($head);
}
return true;
@ -383,23 +382,12 @@ class ExportXml extends ExportPlugin
public function exportDBFooter(string $db): bool
{
if ($this->exportContents) {
return $this->export->outputHandler(' </database>' . "\n");
return $this->outputHandler->addLine(' </database>' . "\n");
}
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in XML format
*
@ -429,7 +417,7 @@ class ExportXml extends ExportPlugin
$buffer = ' <!-- ' . __('Table') . ' '
. htmlspecialchars($tableAlias) . ' -->' . "\n";
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
@ -453,7 +441,7 @@ class ExportXml extends ExportPlugin
$buffer .= ' </table>' . "\n";
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
}

View File

@ -67,7 +67,7 @@ class ExportYaml extends ExportPlugin
*/
public function exportHeader(): bool
{
$this->export->outputHandler('%YAML 1.1' . "\n" . '---' . "\n");
$this->outputHandler->addLine('%YAML 1.1' . "\n" . '---' . "\n");
return true;
}
@ -77,43 +77,11 @@ class ExportYaml extends ExportPlugin
*/
public function exportFooter(): bool
{
$this->export->outputHandler('...' . "\n");
$this->outputHandler->addLine('...' . "\n");
return true;
}
/**
* Outputs database header
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
*
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table in JSON format
*
@ -180,7 +148,7 @@ class ExportYaml extends ExportPlugin
$buffer .= ' ' . $columns[$i] . ': "' . $record[$i] . '"' . "\n";
}
if (! $this->export->outputHandler($buffer)) {
if (! $this->outputHandler->addLine($buffer)) {
return false;
}
}

View File

@ -8,7 +8,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Plugins;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Export\StructureOrData;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
@ -37,22 +37,27 @@ abstract class ExportPlugin implements Plugin
final public function __construct(
public Relation $relation,
protected Export $export,
protected OutputHandler $outputHandler,
public Transformations $transformations,
) {
$this->init();
$this->properties = $this->setProperties();
}
/**
* Outputs export header
*/
abstract public function exportHeader(): bool;
public function exportHeader(): bool
{
return true;
}
/**
* Outputs export footer
*/
abstract public function exportFooter(): bool;
public function exportFooter(): bool
{
return true;
}
/**
* Outputs database header
@ -60,14 +65,20 @@ abstract class ExportPlugin implements Plugin
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
abstract public function exportDBHeader(string $db, string $dbAlias = ''): bool;
public function exportDBHeader(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs database footer
*
* @param string $db Database name
*/
abstract public function exportDBFooter(string $db): bool;
public function exportDBFooter(string $db): bool
{
return true;
}
/**
* Outputs CREATE DATABASE statement
@ -75,7 +86,10 @@ abstract class ExportPlugin implements Plugin
* @param string $db Database name
* @param string $dbAlias Aliases of db
*/
abstract public function exportDBCreate(string $db, string $dbAlias = ''): bool;
public function exportDBCreate(string $db, string $dbAlias = ''): bool
{
return true;
}
/**
* Outputs the content of a table
@ -171,13 +185,6 @@ abstract class ExportPlugin implements Plugin
return '';
}
/**
* Plugin specific initializations.
*/
protected function init(): void
{
}
/**
* Gets the export specific format plugin properties
*

View File

@ -9,7 +9,7 @@ use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
@ -66,9 +66,6 @@ class TableMover
return false;
}
// Setting required export settings.
Export::$asFile = true;
// Selecting the database could avoid some problems with replicated
// databases, when moving table from replicated one to not replicated one.
$this->dbi->selectDb($targetDb);
@ -484,6 +481,8 @@ class TableMover
* @var ExportSql $exportSqlPlugin
*/
$exportSqlPlugin = Plugins::getPlugin('export', 'sql', ExportType::Table);
// Setting required export settings.
OutputHandler::$asFile = true;
// It is better that all identifiers are quoted
$exportSqlPlugin->useSqlBackquotes(true);

View File

@ -11,6 +11,7 @@ use PhpMyAdmin\Controllers\Export\ExportController;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Http\ServerRequest;
@ -190,7 +191,7 @@ final class ExportControllerTest extends AbstractTestCase
$exportController = new ExportController(
new ResponseRenderer(),
new Export($dbi),
new Export($dbi, new OutputHandler()),
ResponseFactory::create(),
$config,
);
@ -355,7 +356,7 @@ final class ExportControllerTest extends AbstractTestCase
$exportController = new ExportController(
new ResponseRenderer(),
new Export($dbi),
new Export($dbi, new OutputHandler()),
ResponseFactory::create(),
$config,
);

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\FlashMessenger;
use PhpMyAdmin\Identifiers\DatabaseName;
use PhpMyAdmin\Message;
@ -32,7 +33,7 @@ class ExportTest extends AbstractTestCase
public function testMergeAliases(): void
{
DatabaseInterface::$instance = $this->createDatabaseInterface();
$export = new Export(DatabaseInterface::getInstance());
$export = new Export(DatabaseInterface::getInstance(), new OutputHandler());
$aliases1 = [
'test_db' => [
'alias' => 'aliastest',
@ -66,14 +67,18 @@ class ExportTest extends AbstractTestCase
{
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$relation = new Relation($dbi);
$exportPlugin = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation));
$finalFileName = $export->getFinalFilename($exportPlugin, 'zip', 'myfilename');
$exportPlugin = new ExportPhparray($relation, $export->outputHandler, new Transformations($dbi, $relation));
$export->outputHandler->setCompression('zip');
$finalFileName = $export->getFinalFilename($exportPlugin, 'myfilename');
self::assertSame('myfilename.php.zip', $finalFileName);
$finalFileName = $export->getFinalFilename($exportPlugin, 'gzip', 'myfilename');
$export->outputHandler->setCompression('gzip');
$finalFileName = $export->getFinalFilename($exportPlugin, 'myfilename');
self::assertSame('myfilename.php.gz', $finalFileName);
$finalFileName = $export->getFinalFilename($exportPlugin, 'gzip', 'export.db1.table1.file');
$finalFileName = $export->getFinalFilename($exportPlugin, 'export.db1.table1.file');
self::assertSame('export.db1.table1.file.php.gz', $finalFileName);
}
@ -81,20 +86,22 @@ class ExportTest extends AbstractTestCase
{
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$relation = new Relation($dbi);
$exportPlugin = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation));
$mimeType = $export->getMimeType($exportPlugin, 'zip');
$exportPlugin = new ExportPhparray($relation, $export->outputHandler, new Transformations($dbi, $relation));
$export->outputHandler->setCompression('zip');
$mimeType = $export->getMimeType($exportPlugin);
self::assertSame('application/zip', $mimeType);
$mimeType = $export->getMimeType($exportPlugin, 'gzip');
$export->outputHandler->setCompression('gzip');
$mimeType = $export->getMimeType($exportPlugin);
self::assertSame('application/x-gzip', $mimeType);
}
public function testExportDatabase(): void
{
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
OutputHandler::$asFile = false;
Config::getInstance()->selectedServer['DisableIS'] = false;
// phpcs:disable Generic.Files.LineLength.TooLong
@ -122,7 +129,7 @@ class ExportTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface($dbiDummy);
DatabaseInterface::$instance = $dbi;
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
ExportPlugin::$exportType = ExportType::Database;
$relation = new Relation($dbi);
@ -131,7 +138,7 @@ class ExportTest extends AbstractTestCase
['test_table'],
['test_table'],
['test_table'],
new ExportSql($relation, $export, new Transformations($dbi, $relation)),
new ExportSql($relation, $export->outputHandler, new Transformations($dbi, $relation)),
[],
'',
);
@ -150,9 +157,7 @@ class ExportTest extends AbstractTestCase
public function testExportServer(): void
{
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
OutputHandler::$asFile = false;
$config = Config::getInstance();
$config->selectedServer['DisableIS'] = false;
$config->selectedServer['only_db'] = '';
@ -198,12 +203,12 @@ class ExportTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface($dbiDummy);
DatabaseInterface::$instance = $dbi;
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$relation = new Relation($dbi);
$export->exportServer(
['test_db'],
new ExportSql($relation, $export, new Transformations($dbi, $relation)),
new ExportSql($relation, $export->outputHandler, new Transformations($dbi, $relation)),
[],
'',
);
@ -228,7 +233,7 @@ class ExportTest extends AbstractTestCase
Current::$server = 2;
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$location = $export->getPageLocationAndSaveMessage(ExportType::Server, Message::error('Error message!'));
self::assertSame('index.php?route=/server/export&server=2&lang=en', $location);
self::assertSame(
@ -243,7 +248,7 @@ class ExportTest extends AbstractTestCase
Current::$server = 2;
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$location = $export->getPageLocationAndSaveMessage(ExportType::Server, Message::success('Success message!'));
self::assertSame('index.php?route=/server/export&server=2&lang=en', $location);
self::assertSame(
@ -259,7 +264,7 @@ class ExportTest extends AbstractTestCase
Current::$database = 'test_db';
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$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(
@ -275,7 +280,7 @@ class ExportTest extends AbstractTestCase
Current::$database = 'test_db';
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$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(
@ -292,7 +297,7 @@ class ExportTest extends AbstractTestCase
Current::$table = 'test_table';
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$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',
@ -312,7 +317,7 @@ class ExportTest extends AbstractTestCase
Current::$table = 'test_table';
$_SESSION = [];
$dbi = $this->createDatabaseInterface();
$export = new Export($dbi);
$export = new Export($dbi, new OutputHandler());
$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',

View File

@ -6,7 +6,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportCodegen;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -40,7 +40,7 @@ class ExportCodegenTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
$relation = new Relation($dbi);
$this->object = new ExportCodegen($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportCodegen($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**
@ -164,11 +164,7 @@ class ExportCodegenTest extends AbstractTestCase
public function testExportData(): void
{
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['codegen_format' => '1']);

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportCsv;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -44,10 +44,9 @@ class ExportCsvTest extends AbstractTestCase
Current::$database = '';
Current::$table = '';
Current::$lang = '';
Export::$saveFilename = '';
$relation = new Relation($dbi);
$this->object = new ExportCsv($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportCsv($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**
@ -255,27 +254,7 @@ class ExportCsvTest extends AbstractTestCase
public function testExportData(): void
{
// case 1
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = true;
Export::$fileHandle = null;
ob_start();
self::assertFalse($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
ob_get_clean();
// case 2
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['csv_terminated' => ';', 'csv_columns' => 'On']);

View File

@ -6,7 +6,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportExcel;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -42,7 +42,7 @@ class ExportExcelTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
$relation = new Relation($dbi);
$this->object = new ExportExcel($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportExcel($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**
@ -216,30 +216,10 @@ class ExportExcelTest extends AbstractTestCase
public function testExportData(): void
{
// case 1
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = true;
Export::$fileHandle = null;
ob_start();
self::assertFalse($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
ob_get_clean();
// case 2
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['excel_columns' => 'On', 'excel_terminated' => ';']);
->withParsedBody(['excel_columns' => 'On']);
$this->object->setExportOptions($request, []);
@ -252,72 +232,10 @@ class ExportExcelTest extends AbstractTestCase
$result = ob_get_clean();
self::assertSame(
'idnamedatetimefield;1abcd2011-01-20 02:00:02;2foo2010-01-20 02:00:02;3Abcd2012-01-20 02:00:02;',
$result,
);
// case 3
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['excel_columns' => 'On', 'excel_enclosed' => '"', 'excel_terminated' => ';']);
$this->object->setExportOptions($request, []);
ob_start();
self::assertTrue($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
$result = ob_get_clean();
self::assertSame(
'"id""name""datetimefield";"1""abcd""2011-01-20 02:00:02";'
. '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";',
$result,
);
// case 4
ob_start();
self::assertTrue($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
$result = ob_get_clean();
self::assertSame(
'"id""name""datetimefield";"1""abcd""2011-01-20 02:00:02";'
. '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";',
$result,
);
// case 5
ob_start();
self::assertTrue($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
$result = ob_get_clean();
self::assertSame(
'"id""name""datetimefield";"1""abcd""2011-01-20 02:00:02";'
. '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";',
$result,
);
// case 6
ob_start();
self::assertTrue($this->object->exportData(
'test_db',
'test_table',
'SELECT * FROM `test_db`.`test_table`;',
));
$result = ob_get_clean();
self::assertSame(
'"id""name""datetimefield";"1""abcd""2011-01-20 02:00:02";'
. '"2""foo""2010-01-20 02:00:02";"3""Abcd""2012-01-20 02:00:02";',
'"id";"name";"datetimefield"' . "\015\012"
. '"1";"abcd";"2011-01-20 02:00:02"' . "\015\012"
. '"2";"foo";"2010-01-20 02:00:02"' . "\015\012"
. '"3";"Abcd";"2012-01-20 02:00:02"' . "\015\012",
$result,
);
}

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Identifiers\TriggerName;
@ -60,14 +60,10 @@ class ExportHtmlwordTest extends AbstractTestCase
$relation = new Relation($this->dbi);
$this->object = new ExportHtmlword(
$relation,
new Export($this->dbi),
new OutputHandler(),
new Transformations($this->dbi, $relation),
);
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
Current::$database = '';
Current::$table = '';
Current::$lang = '';
@ -293,11 +289,7 @@ class ExportHtmlwordTest extends AbstractTestCase
public function testExportData(): void
{
// case 1
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['htmlword_columns' => 'On']);
@ -379,7 +371,7 @@ class ExportHtmlwordTest extends AbstractTestCase
$relation = new Relation($this->dbi);
$this->object = $this->getMockBuilder(ExportHtmlword::class)
->onlyMethods(['formatOneColumnDefinition'])
->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)])
->setConstructorArgs([$relation, new OutputHandler(), new Transformations($this->dbi, $relation)])
->getMock();
$keys = [['Non_unique' => 0, 'Column_name' => 'name1'], ['Non_unique' => 1, 'Column_name' => 'name2']];

View File

@ -6,7 +6,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Plugins\Export\ExportJson;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
@ -35,13 +35,9 @@ class ExportJsonTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$relation = new Relation($dbi);
$this->object = new ExportJson($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportJson($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportLatex;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -49,17 +49,13 @@ class ExportLatexTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
ExportPlugin::$exportType = ExportType::Table;
ExportPlugin::$singleTable = false;
Current::$database = 'db';
Current::$table = 'table';
$relation = new Relation($dbi);
$this->object = new ExportLatex($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportLatex($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -8,7 +8,7 @@ use PhpMyAdmin\Column;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportMediawiki;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -43,16 +43,12 @@ class ExportMediawikiTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
Current::$database = '';
Current::$table = '';
Current::$lang = 'en';
$relation = new Relation($dbi);
$this->object = new ExportMediawiki($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportMediawiki($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportOds;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -52,13 +52,9 @@ class ExportOdsTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$relation = new Relation($dbi);
$this->object = new ExportOds($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportOds($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -10,7 +10,7 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Identifiers\TriggerName;
@ -67,16 +67,12 @@ class ExportOdtTest extends AbstractTestCase
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
DatabaseInterface::$instance = $this->dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
ExportPlugin::$exportType = ExportType::Table;
ExportPlugin::$singleTable = false;
Config::getInstance()->selectedServer['DisableIS'] = true;
$relation = new Relation($this->dbi);
$this->object = new ExportOdt($relation, new Export($this->dbi), new Transformations($this->dbi, $relation));
$this->object = new ExportOdt($relation, new OutputHandler(), new Transformations($this->dbi, $relation));
}
/**
@ -574,7 +570,7 @@ class ExportOdtTest extends AbstractTestCase
$relation = new Relation($this->dbi);
$this->object = $this->getMockBuilder(ExportOdt::class)
->onlyMethods(['formatOneColumnDefinition'])
->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)])
->setConstructorArgs([$relation, new OutputHandler(), new Transformations($this->dbi, $relation)])
->getMock();
// case 1

View File

@ -6,7 +6,8 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportPdf;
use PhpMyAdmin\Plugins\Export\Helpers\Pdf;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
@ -38,13 +39,9 @@ class ExportPdfTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
$relation = new Relation($dbi);
$this->object = new ExportPdf($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportPdf($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**
@ -154,24 +151,15 @@ class ExportPdfTest extends AbstractTestCase
);
}
public function testExportHeader(): void
public function testSetExportOptions(): void
{
$pdf = $this->getMockBuilder(Pdf::class)
->disableOriginalConstructor()
->getMock();
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/');
$pdf->expects(self::once())
->method('Open');
$pdf->expects(self::once())
->method('setTopMargin');
$this->object->setExportOptions($request, []);
$attrPdf = new ReflectionProperty(ExportPdf::class, 'pdf');
$attrPdf->setValue($this->object, $pdf);
self::assertTrue(
$this->object->exportHeader(),
);
$pdf = $attrPdf->getValue($this->object);
self::assertInstanceOf(Pdf::class, $pdf);
}
public function testExportFooter(): void
@ -234,21 +222,4 @@ class ExportPdfTest extends AbstractTestCase
),
);
}
/**
* Test for
* - PhpMyAdmin\Plugins\Export\ExportPdf::setPdf
* - PhpMyAdmin\Plugins\Export\ExportPdf::getPdf
*/
public function testSetGetPdf(): void
{
$setter = new ReflectionMethod(ExportPdf::class, 'setPdf');
$setter->invoke($this->object, new Pdf());
$getter = new ReflectionMethod(ExportPdf::class, 'getPdf');
self::assertInstanceOf(
Pdf::class,
$getter->invoke($this->object),
);
}
}

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Plugins\Export\ExportPhparray;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
@ -38,16 +38,12 @@ class ExportPhparrayTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$outputCharsetConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = true;
Export::$saveOnServer = false;
OutputHandler::$asFile = true;
Current::$database = '';
Current::$table = '';
Current::$lang = 'en';
$relation = new Relation($dbi);
$this->object = new ExportPhparray($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportPhparray($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -12,7 +12,7 @@ use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Exceptions\ExportException;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -67,15 +67,12 @@ class ExportSqlTest extends AbstractTestCase
Current::$table = '';
Current::$lang = 'en';
Config::getInstance()->selectedServer['DisableIS'] = true;
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
Export::$saveOnServer = false;
OutputHandler::$asFile = false;
ExportPlugin::$exportType = ExportType::Table;
ExportPlugin::$singleTable = false;
$relation = new Relation($dbi);
$this->object = new ExportSql($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportSql($relation, new OutputHandler(), new Transformations($dbi, $relation));
$this->object->useSqlBackquotes(false);
}
@ -385,8 +382,7 @@ class ExportSqlTest extends AbstractTestCase
{
Current::$charset = 'utf-8';
ExportSql::$oldTimezone = 'GMT';
Export::$asFile = true;
Export::$outputCharsetConversion = true;
OutputHandler::$asFile = true;
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
@ -416,8 +412,7 @@ class ExportSqlTest extends AbstractTestCase
$config->selectedServer['host'] = 'localhost';
$config->selectedServer['port'] = 80;
ExportSql::$oldTimezone = 'GMT';
Export::$asFile = true;
Export::$outputCharsetConversion = true;
OutputHandler::$asFile = true;
Current::$charset = 'utf-8';
$dbi = $this->getMockBuilder(DatabaseInterface::class)
@ -887,7 +882,7 @@ class ExportSqlTest extends AbstractTestCase
DatabaseInterface::$instance = $dbi;
$relation = new Relation($dbi);
$this->object = new ExportSql($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportSql($relation, new OutputHandler(), new Transformations($dbi, $relation));
$this->object->useSqlBackquotes(false);
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')

View File

@ -11,7 +11,7 @@ use PhpMyAdmin\ConfigStorage\RelationParameters;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\ConnectionType;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Identifiers\TableName;
use PhpMyAdmin\Identifiers\TriggerName;
@ -58,10 +58,7 @@ class ExportTexytextTest extends AbstractTestCase
$this->dummyDbi = $this->createDbiDummy();
$this->dbi = $this->createDatabaseInterface($this->dummyDbi);
DatabaseInterface::$instance = $this->dbi;
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
Export::$saveOnServer = false;
OutputHandler::$asFile = false;
ExportPlugin::$exportType = ExportType::Table;
ExportPlugin::$singleTable = false;
Current::$database = '';
@ -71,7 +68,7 @@ class ExportTexytextTest extends AbstractTestCase
$relation = new Relation($this->dbi);
$this->object = new ExportTexytext(
$relation,
new Export($this->dbi),
new OutputHandler(),
new Transformations($this->dbi, $relation),
);
}
@ -263,7 +260,7 @@ class ExportTexytextTest extends AbstractTestCase
$relation = new Relation($this->dbi);
$this->object = $this->getMockBuilder(ExportTexytext::class)
->onlyMethods(['formatOneColumnDefinition'])
->setConstructorArgs([$relation, new Export($this->dbi), new Transformations($this->dbi, $relation)])
->setConstructorArgs([$relation, new OutputHandler(), new Transformations($this->dbi, $relation)])
->getMock();
// case 1

View File

@ -8,7 +8,7 @@ use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Plugins\Export\ExportXml;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -43,16 +43,13 @@ class ExportXmlTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
Export::$saveOnServer = false;
OutputHandler::$asFile = false;
ExportPlugin::$exportType = ExportType::Table;
ExportPlugin::$singleTable = false;
Current::$database = 'db';
Config::getInstance()->selectedServer['DisableIS'] = true;
$relation = new Relation($dbi);
$this->object = new ExportXml($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportXml($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**
@ -168,7 +165,6 @@ class ExportXmlTest extends AbstractTestCase
public function testExportHeader(): void
{
Export::$outputCharsetConversion = true;
Current::$charset = 'iso-8859-1';
$config = Config::getInstance();
$config->selectedServer['port'] = 80;
@ -290,8 +286,6 @@ class ExportXmlTest extends AbstractTestCase
// case 2 with isView as true and false
Export::$outputCharsetConversion = false;
$dbiDummy->addResult(
'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`'
. " FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME` = 'd<\\\"b' LIMIT 1",
@ -408,8 +402,7 @@ class ExportXmlTest extends AbstractTestCase
public function testExportData(): void
{
Export::$asFile = true;
Export::$outputCharsetConversion = false;
OutputHandler::$asFile = true;
$request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/')
->withParsedBody(['xml_export_contents' => 'On']);

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins\Export;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Plugins\Export\ExportYaml;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
@ -38,15 +38,12 @@ class ExportYamlTest extends AbstractTestCase
$dbi = $this->createDatabaseInterface();
DatabaseInterface::$instance = $dbi;
Export::$outputKanjiConversion = false;
Export::$bufferNeeded = false;
Export::$asFile = false;
Export::$saveOnServer = false;
OutputHandler::$asFile = false;
Current::$database = '';
Current::$table = '';
Current::$lang = 'en';
$relation = new Relation($dbi);
$this->object = new ExportYaml($relation, new Export($dbi), new Transformations($dbi, $relation));
$this->object = new ExportYaml($relation, new OutputHandler(), new Transformations($dbi, $relation));
}
/**

View File

@ -7,7 +7,7 @@ namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Config;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Export\Export;
use PhpMyAdmin\Export\OutputHandler;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
@ -105,12 +105,12 @@ class PluginsTest extends AbstractTestCase
$dbi = DatabaseInterface::getInstance();
$relation = new Relation($dbi);
$transformations = new Transformations($dbi, $relation);
$export = new Export($dbi);
$outputHandler = new OutputHandler();
$exportList = [
new Plugins\Export\ExportJson($relation, $export, $transformations),
new Plugins\Export\ExportOds($relation, $export, $transformations),
new Plugins\Export\ExportSql($relation, $export, $transformations),
new Plugins\Export\ExportXml($relation, $export, $transformations),
new Plugins\Export\ExportJson($relation, $outputHandler, $transformations),
new Plugins\Export\ExportOds($relation, $outputHandler, $transformations),
new Plugins\Export\ExportSql($relation, $outputHandler, $transformations),
new Plugins\Export\ExportXml($relation, $outputHandler, $transformations),
];
$actual = Plugins::getChoice($exportList, 'xml');
$expected = [