diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8b1973b3b8..c2ae2c35c4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2181,30 +2181,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\, array\ 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\\) does not accept array\\.$#' identifier: assign.propertyType @@ -6165,30 +6147,12 @@ parameters: 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 - path: src/Export/Export.php - - message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#' identifier: argument.type 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 @@ -6261,6 +6225,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 @@ -9460,13 +9436,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 callable PhpMyAdmin\\Export\\OutputHandler expects string, mixed given\.$#' identifier: argument.type count: 1 path: src/Plugins/Export/ExportPdf.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a0d1a6fde9..2ae66f41a5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1275,32 +1275,6 @@ - - export->dumpBuffer]]> - export->dumpBuffer]]> - - - export->dumpBuffer]]> - export->dumpBuffer]]> - - - export->compress( - $this->export->dumpBuffer, - Export::$compression, - $filename, - )]]> - export->compress( - $this->export->dumpBufferObjects, - Export::$compression, - $filename, - )]]> - - - - - - getParsedBodyParamAsString('compression')]]> - @@ -4186,14 +4160,10 @@ - - - - @@ -4221,6 +4191,17 @@ settings['SaveDir'])]]> + + + fileHandle]]> + + + createFile($dumpBuffer, $filename)]]> + + + + + @@ -6161,17 +6142,14 @@ - getPDFData()]]> + pdf->getPDFData()]]> - - - + + pdfReportTitle]]> + - - - diff --git a/src/Controllers/Export/ExportController.php b/src/Controllers/Export/ExportController.php index f0c64b575e..24eaa90855 100644 --- a/src/Controllers/Export/ExportController.php +++ b/src/Controllers/Export/ExportController.php @@ -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; @@ -76,12 +77,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 +96,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,11 +135,6 @@ 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 = ''; @@ -150,21 +142,21 @@ final readonly class ExportController implements InvocableController $isQuickExport = $quickOrCustom === 'quick'; 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->compression = $compressionParam; + $this->export->outputHandler->bufferNeeded = true; } if (($isQuickExport && $quickExportOnServer) || (! $isQuickExport && $onServerParam)) { // Will we save dump on server? - Export::$saveOnServer = $this->config->settings['SaveDir'] !== ''; + $this->export->outputHandler->saveOnServer = $this->config->settings['SaveDir'] !== ''; } } @@ -212,33 +204,27 @@ 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(); + $this->export->outputHandler->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() && isset(Current::$charset) && 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(); + $this->export->outputHandler->onFlyCompression = $this->config->settings['CompressOnFly'] && ($this->export->outputHandler)->compression === 'gzip'; + 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 +233,21 @@ final readonly class ExportController implements InvocableController $filename = $this->export->getFinalFilename( $exportPlugin, - Export::$compression, + $this->export->outputHandler->compression, Sanitize::sanitizeFilename(Util::expandUserString($filenameTemplate), true), ); - $mimeType = $this->export->getMimeType($exportPlugin, Export::$compression); + $mimeType = $this->export->getMimeType($exportPlugin, $this->export->outputHandler->compression); } // 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, $this->export->outputHandler->compression, 'export'); } // Open file on server if needed - if (Export::$saveOnServer) { - [Export::$saveFilename, $message, Export::$fileHandle] = $this->export->openFile($filename, $isQuickExport); + if ($this->export->outputHandler->saveOnServer) { + $message = $this->export->openFile($filename, $isQuickExport); // problem opening export file on server? if ($message !== null) { @@ -270,7 +256,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 +286,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 +389,7 @@ final readonly class ExportController implements InvocableController // Ignore } - if (Export::$saveOnServer && Current::$message !== null) { + if ($this->export->outputHandler->saveOnServer && Current::$message !== null) { $location = $this->export->getPageLocationAndSaveMessage($exportType, Current::$message); $this->response->redirect($location); @@ -414,47 +399,27 @@ 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 ($this->export->outputHandler->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()); } } diff --git a/src/Export/Export.php b/src/Export/Export.php index a51ac386a2..a232df8e67 100644 --- a/src/Export/Export.php +++ b/src/Export/Export.php @@ -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,22 +23,14 @@ 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; @@ -50,57 +39,30 @@ 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 */ public static array $tableData = []; - public static string $saveFilename = ''; - public static int $timeStart = 0; + + public OutputHandler $outputHandler; public function __construct(private DatabaseInterface $dbi) { + $this->outputHandler = new OutputHandler(); } /** @@ -117,131 +79,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 * @@ -355,10 +192,8 @@ class Export * * @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 + public function openFile(string $filename, bool $quickExport): Message|null { $fileHandle = null; $message = null; @@ -403,83 +238,10 @@ class Export } } - return [$saveFilename, $message, $fileHandle]; - } + $this->outputHandler->saveFilename = $saveFilename; + $this->outputHandler->fileHandle = $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; + return $message; } /** @@ -550,7 +312,7 @@ class Export continue; } - $this->saveObjectInBuffer($currentDb); + $this->outputHandler->saveObjectInBuffer($currentDb); } } @@ -586,7 +348,7 @@ class Export } if ($separateFiles === 'database') { - $this->saveObjectInBuffer('database', true); + $this->outputHandler->saveObjectInBuffer('database', true); } $structureOrData = $exportPlugin->getStructureOrData(); @@ -599,7 +361,7 @@ class Export $exportPlugin->exportRoutines($db->getName(), $aliases); if ($separateFiles === 'database') { - $this->saveObjectInBuffer('routines'); + $this->outputHandler->saveObjectInBuffer('routines'); } } @@ -673,7 +435,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 +456,7 @@ class Export continue; } - $this->saveObjectInBuffer('table_' . $table, true); + $this->outputHandler->saveObjectInBuffer('table_' . $table, true); } if ($exportPlugin instanceof ExportSql && $exportPlugin->hasCreateView()) { @@ -712,7 +474,7 @@ class Export continue; } - $this->saveObjectInBuffer('view_' . $view); + $this->outputHandler->saveObjectInBuffer('view_' . $view); } } @@ -728,12 +490,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 +512,7 @@ class Export return; } - $this->saveObjectInBuffer('events'); + $this->outputHandler->saveObjectInBuffer('events'); } /** diff --git a/src/Export/OutputHandler.php b/src/Export/OutputHandler.php new file mode 100644 index 0000000000..5ea6ddd323 --- /dev/null +++ b/src/Export/OutputHandler.php @@ -0,0 +1,257 @@ +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->bufferNeeded) { + $this->dumpBuffer .= $line; + if ($this->onFlyCompression) { + $this->dumpBufferLength += strlen($line); + + if ($this->dumpBufferLength > $this->memoryLimit) { + if ($this->outputCharsetConversion) { + $this->dumpBuffer = Encoding::convertString( + 'utf-8', + Current::$charset ?? 'utf-8', + $this->dumpBuffer, + ); + } + + 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->saveOnServer && $this->fileHandle !== null) { + $writeResult = @fwrite($this->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 !== 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; + } + } else { + $timeNow = time(); + if ($this->timeStart >= $timeNow + 30) { + $this->timeStart = $timeNow; + header('X-pmaPing: Pong'); + } + } + } elseif (self::$asFile) { + if ($this->outputCharsetConversion) { + $line = Encoding::convertString('utf-8', Current::$charset ?? 'utf-8', $line); + } + + if ($this->saveOnServer && $this->fileHandle !== null && $line !== '') { + $writeResult = @fwrite($this->fileHandle, $line); + // Here, use strlen rather than mb_strlen to get the length + // in bytes to compare against the number of bytes written. + if ($writeResult !== strlen($line)) { + Current::$message = Message::error( + __('Insufficient space to save the file %s.'), + ); + Current::$message->addParam($this->saveFilename); + + return false; + } + + $timeNow = time(); + if ($this->timeStart >= $timeNow + 30) { + $this->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; + } + + /** + * 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; + } + + 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 closeFile(): Message + { + $writeResult = false; + if ($this->fileHandle !== null) { + $writeResult = @fwrite($this->fileHandle, $this->dumpBuffer); + fclose($this->fileHandle); + $this->fileHandle = null; + } + + // Here, use strlen rather than mb_strlen to get the length + // in bytes to compare against the number of bytes written. + 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->saveOnServer + || (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); + } +} diff --git a/src/Plugins/Export/ExportCodegen.php b/src/Plugins/Export/ExportCodegen.php index 6bbdc27b38..c5f5898c33 100644 --- a/src/Plugins/Export/ExportCodegen.php +++ b/src/Plugins/Export/ExportCodegen.php @@ -97,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->export->outputHandler)($this->handleNHibernateXMLBody($db, $table, $aliases)); } - return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $aliases)); + return ($this->export->outputHandler)($this->handleNHibernateCSBody($db, $table, $aliases)); } /** diff --git a/src/Plugins/Export/ExportCsv.php b/src/Plugins/Export/ExportCsv.php index f9fafda16a..89309c314f 100644 --- a/src/Plugins/Export/ExportCsv.php +++ b/src/Plugins/Export/ExportCsv.php @@ -164,7 +164,7 @@ class ExportCsv extends ExportPlugin } $schemaInsert = implode($this->separator, $insertFields); - if (! $this->export->outputHandler($schemaInsert . $this->terminated)) { + if (! ($this->export->outputHandler)($schemaInsert . $this->terminated)) { return false; } } @@ -218,7 +218,7 @@ class ExportCsv extends ExportPlugin } $schemaInsert = implode($this->separator, $insertValues); - if (! $this->export->outputHandler($schemaInsert . $this->terminated)) { + if (! ($this->export->outputHandler)($schemaInsert . $this->terminated)) { return false; } } diff --git a/src/Plugins/Export/ExportExcel.php b/src/Plugins/Export/ExportExcel.php index 2dff18dc0a..7ae97d3e10 100644 --- a/src/Plugins/Export/ExportExcel.php +++ b/src/Plugins/Export/ExportExcel.php @@ -155,7 +155,7 @@ class ExportExcel extends ExportPlugin } $schemaInsert = implode($this->separator, $insertFields); - if (! $this->export->outputHandler($schemaInsert . $this->terminated)) { + if (! ($this->export->outputHandler)($schemaInsert . $this->terminated)) { return false; } } @@ -206,7 +206,7 @@ class ExportExcel extends ExportPlugin } $schemaInsert = implode($this->separator, $insertValues); - if (! $this->export->outputHandler($schemaInsert . $this->terminated)) { + if (! ($this->export->outputHandler)($schemaInsert . $this->terminated)) { return false; } } diff --git a/src/Plugins/Export/ExportHtmlword.php b/src/Plugins/Export/ExportHtmlword.php index 68d4d1c529..311bfb9fe8 100644 --- a/src/Plugins/Export/ExportHtmlword.php +++ b/src/Plugins/Export/ExportHtmlword.php @@ -106,7 +106,7 @@ class ExportHtmlword extends ExportPlugin */ public function exportHeader(): bool { - return $this->export->outputHandler( + return ($this->export->outputHandler)( ' @@ -127,7 +127,7 @@ class ExportHtmlword extends ExportPlugin */ public function exportFooter(): bool { - return $this->export->outputHandler(''); + return ($this->export->outputHandler)(''); } /** @@ -142,7 +142,7 @@ class ExportHtmlword extends ExportPlugin $dbAlias = $db; } - return $this->export->outputHandler( + return ($this->export->outputHandler)( '

' . __('Database') . ' ' . htmlspecialchars($dbAlias) . '

', ); } @@ -164,7 +164,7 @@ class ExportHtmlword extends ExportPlugin $tableAlias = $this->getTableAlias($aliases, $db, $table); if ( - ! $this->export->outputHandler( + ! ($this->export->outputHandler)( '

' . __('Dumping data for table') . ' ' . htmlspecialchars($tableAlias) . '

', @@ -173,7 +173,7 @@ class ExportHtmlword extends ExportPlugin return false; } - if (! $this->export->outputHandler('')) { + if (! ($this->export->outputHandler)('
')) { return false; } @@ -195,7 +195,7 @@ class ExportHtmlword extends ExportPlugin } $schemaInsert .= ''; - if (! $this->export->outputHandler($schemaInsert)) { + if (! ($this->export->outputHandler)($schemaInsert)) { return false; } } @@ -210,12 +210,12 @@ class ExportHtmlword extends ExportPlugin } $schemaInsert .= ''; - if (! $this->export->outputHandler($schemaInsert)) { + if (! ($this->export->outputHandler)($schemaInsert)) { return false; } } - return $this->export->outputHandler('
'); + return ($this->export->outputHandler)(''); } /** @@ -480,7 +480,7 @@ class ExportHtmlword extends ExportPlugin $dump .= $this->getTableDefStandIn($db, $table, $aliases); } - return $this->export->outputHandler($dump); + return ($this->export->outputHandler)($dump); } /** diff --git a/src/Plugins/Export/ExportJson.php b/src/Plugins/Export/ExportJson.php index c41d8b5ff7..16b821fda7 100644 --- a/src/Plugins/Export/ExportJson.php +++ b/src/Plugins/Export/ExportJson.php @@ -116,7 +116,7 @@ class ExportJson extends ExportPlugin return false; } - return $this->export->outputHandler('[' . "\n" . $data . ',' . "\n"); + return ($this->export->outputHandler)('[' . "\n" . $data . ',' . "\n"); } /** @@ -124,7 +124,7 @@ class ExportJson extends ExportPlugin */ public function exportFooter(): bool { - return $this->export->outputHandler(']' . "\n"); + return ($this->export->outputHandler)(']' . "\n"); } /** @@ -144,7 +144,7 @@ class ExportJson extends ExportPlugin return false; } - return $this->export->outputHandler($data . ',' . "\n"); + return ($this->export->outputHandler)($data . ',' . "\n"); } /** @@ -165,7 +165,7 @@ class ExportJson extends ExportPlugin $tableAlias = $this->getTableAlias($aliases, $db, $table); if (! $this->first) { - if (! $this->export->outputHandler(',')) { + if (! ($this->export->outputHandler)(',')) { return false; } } else { @@ -208,7 +208,7 @@ class ExportJson extends ExportPlugin ): bool { [$header, $footer] = explode('"@@DATA@@"', $buffer); - if (! $this->export->outputHandler($header . "\n" . '[' . "\n")) { + if (! ($this->export->outputHandler)($header . "\n" . '[' . "\n")) { return false; } @@ -234,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->export->outputHandler)(',' . "\n")) { return false; } } @@ -272,12 +272,12 @@ class ExportJson extends ExportPlugin return false; } - if (! $this->export->outputHandler($encodedData)) { + if (! ($this->export->outputHandler)($encodedData)) { return false; } } - return $this->export->outputHandler("\n" . ']' . "\n" . $footer . "\n"); + return ($this->export->outputHandler)("\n" . ']' . "\n" . $footer . "\n"); } /** diff --git a/src/Plugins/Export/ExportLatex.php b/src/Plugins/Export/ExportLatex.php index 6296769eee..cb76cd0a51 100644 --- a/src/Plugins/Export/ExportLatex.php +++ b/src/Plugins/Export/ExportLatex.php @@ -233,7 +233,7 @@ class ExportLatex extends ExportPlugin . '% ' . __('Server version:') . ' ' . DatabaseInterface::getInstance()->getVersionString() . "\n" . '% ' . __('PHP Version:') . ' ' . PHP_VERSION . "\n"; - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($head); } /** @@ -252,7 +252,7 @@ class ExportLatex extends ExportPlugin . '% ' . __('Database:') . ' \'' . $dbAlias . '\'' . "\n" . '% ' . "\n"; - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($head); } /** @@ -309,7 +309,7 @@ class ExportLatex extends ExportPlugin . '} \\\\'; } - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } @@ -322,13 +322,13 @@ class ExportLatex extends ExportPlugin } $buffer = mb_substr($buffer, 0, -2) . '\\\\ \\hline \hline '; - if (! $this->export->outputHandler($buffer . ' \\endfirsthead ' . "\n")) { + if (! ($this->export->outputHandler)($buffer . ' \\endfirsthead ' . "\n")) { return false; } if ($this->caption) { if ( - ! $this->export->outputHandler( + ! ($this->export->outputHandler)( '\\caption{' . Util::expandUserString( $this->dataContinuedCaption, @@ -342,10 +342,10 @@ class ExportLatex extends ExportPlugin } } - if (! $this->export->outputHandler($buffer . '\\endhead \\endfoot' . "\n")) { + if (! ($this->export->outputHandler)($buffer . '\\endhead \\endfoot' . "\n")) { return false; } - } elseif (! $this->export->outputHandler('\\\\ \hline')) { + } elseif (! ($this->export->outputHandler)('\\\\ \hline')) { return false; } @@ -370,14 +370,14 @@ class ExportLatex extends ExportPlugin } $buffer .= ' \\\\ \\hline ' . "\n"; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } } $buffer = ' \\end{longtable}' . "\n"; - return $this->export->outputHandler($buffer); + return ($this->export->outputHandler)($buffer); } /** @@ -443,7 +443,7 @@ class ExportLatex extends ExportPlugin */ $buffer = "\n" . '%' . "\n" . '% ' . __('Structure:') . ' ' . $tableAlias . "\n" . '%' . "\n" . ' \\begin{longtable}{'; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } @@ -513,7 +513,7 @@ class ExportLatex extends ExportPlugin $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . "\n"; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } @@ -565,14 +565,14 @@ class ExportLatex extends ExportPlugin $buffer = str_replace("\000", ' & ', $localBuffer); $buffer .= ' \\\\ \\hline ' . "\n"; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } } $buffer = ' \\end{longtable}' . "\n"; - return $this->export->outputHandler($buffer); + return ($this->export->outputHandler)($buffer); } /** diff --git a/src/Plugins/Export/ExportMediawiki.php b/src/Plugins/Export/ExportMediawiki.php index 38709bd7ef..75be7b74e0 100644 --- a/src/Plugins/Export/ExportMediawiki.php +++ b/src/Plugins/Export/ExportMediawiki.php @@ -166,7 +166,7 @@ class ExportMediawiki extends ExportPlugin $output .= '|}' . str_repeat($this->exportCRLF(), 2); } - return $this->export->outputHandler($output); + return ($this->export->outputHandler)($output); } /** @@ -240,7 +240,7 @@ class ExportMediawiki extends ExportPlugin // End table construction $output .= '|}' . str_repeat($this->exportCRLF(), 2); - return $this->export->outputHandler($output); + return ($this->export->outputHandler)($output); } /** diff --git a/src/Plugins/Export/ExportOds.php b/src/Plugins/Export/ExportOds.php index b51b68f69d..d8dc2c45c1 100644 --- a/src/Plugins/Export/ExportOds.php +++ b/src/Plugins/Export/ExportOds.php @@ -142,11 +142,8 @@ class ExportOds extends ExportPlugin { $this->buffer .= ''; - return $this->export->outputHandler( - OpenDocument::create( - 'application/vnd.oasis.opendocument.spreadsheet', - $this->buffer, - ), + return ($this->export->outputHandler)( + OpenDocument::create('application/vnd.oasis.opendocument.spreadsheet', $this->buffer), ); } diff --git a/src/Plugins/Export/ExportOdt.php b/src/Plugins/Export/ExportOdt.php index e1842b1e18..f67377fc89 100644 --- a/src/Plugins/Export/ExportOdt.php +++ b/src/Plugins/Export/ExportOdt.php @@ -163,7 +163,7 @@ class ExportOdt extends ExportPlugin { $this->buffer .= ''; - return $this->export->outputHandler(OpenDocument::create( + return ($this->export->outputHandler)(OpenDocument::create( 'application/vnd.oasis.opendocument.text', $this->buffer, )); diff --git a/src/Plugins/Export/ExportPdf.php b/src/Plugins/Export/ExportPdf.php index 55fefca1a8..7da6bf7be9 100644 --- a/src/Plugins/Export/ExportPdf.php +++ b/src/Plugins/Export/ExportPdf.php @@ -104,7 +104,7 @@ class ExportPdf extends ExportPlugin public function exportFooter(): bool { // instead of $pdf->Output(): - return $this->export->outputHandler($this->pdf->getPDFData()); + return ($this->export->outputHandler)($this->pdf->getPDFData()); } /** diff --git a/src/Plugins/Export/ExportPhparray.php b/src/Plugins/Export/ExportPhparray.php index 7078187c19..2e010ad2c9 100644 --- a/src/Plugins/Export/ExportPhparray.php +++ b/src/Plugins/Export/ExportPhparray.php @@ -78,7 +78,7 @@ class ExportPhparray extends ExportPlugin */ public function exportHeader(): bool { - $this->export->outputHandler( + ($this->export->outputHandler)( 'export->outputHandler( + ($this->export->outputHandler)( '/**' . "\n" . ' * Database ' . $this->commentString(Util::backquote($dbAlias)) . "\n" . ' */' . "\n", @@ -160,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->export->outputHandler)($buffer)) { return false; } @@ -183,7 +183,7 @@ class ExportPhparray extends ExportPlugin } $buffer .= ')'; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } @@ -193,7 +193,7 @@ class ExportPhparray extends ExportPlugin $buffer .= "\n" . ');' . "\n"; - return $this->export->outputHandler($buffer); + return ($this->export->outputHandler)($buffer); } /** diff --git a/src/Plugins/Export/ExportSql.php b/src/Plugins/Export/ExportSql.php index 50711070f3..003ad3869f 100644 --- a/src/Plugins/Export/ExportSql.php +++ b/src/Plugins/Export/ExportSql.php @@ -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->export->outputHandler)($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->export->outputHandler)($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->export->outputHandler)($head); } /** @@ -845,13 +846,9 @@ class ExportSql extends ExportPlugin if ($this->structureOrData !== StructureOrData::Data && $this->dropDatabase) { if ( - ! $this->export->outputHandler( + ! ($this->export->outputHandler)( '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->export->outputHandler)($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->export->outputHandler)( 'USE ' - . Util::backquoteCompat( - $db, - $compat, - $this->useSqlBackquotes, - ) + . Util::backquoteCompat($db, $compat, $this->useSqlBackquotes) . ';' . "\n", ); } - return $this->export->outputHandler('USE ' . $db . ';' . "\n"); + return ($this->export->outputHandler)('USE ' . $db . ';' . "\n"); } /** @@ -932,7 +925,7 @@ class ExportSql extends ExportPlugin ) . $this->exportComment(); - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($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->export->outputHandler)($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->export->outputHandler)($this->sqlAutoIncrements); $this->sqlAutoIncrements = null; } //add views to the sql dump file if ($this->sqlViews !== '') { - $result = $this->export->outputHandler($this->sqlViews); + $result = ($this->export->outputHandler)($this->sqlViews); $this->sqlViews = ''; } //add constraints to the sql dump file if ($this->sqlConstraints !== null) { - $result = $this->export->outputHandler($this->sqlConstraints); + $result = ($this->export->outputHandler)($this->sqlConstraints); $this->sqlConstraints = null; } @@ -1022,7 +1015,7 @@ class ExportSql extends ExportPlugin } if ($text !== '') { - return $this->export->outputHandler($text); + return ($this->export->outputHandler)($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->export->outputHandler)($comment)) { return false; } @@ -1128,7 +1121,7 @@ class ExportSql extends ExportPlugin $comment .= $this->exportComment(); - if (! $this->export->outputHandler($comment)) { + if (! ($this->export->outputHandler)($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->export->outputHandler)($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->export->outputHandler)($dump); } /** @@ -2019,7 +2012,7 @@ class ExportSql extends ExportPlugin . $this->exportComment() . $this->possibleCRLF(); - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($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->export->outputHandler)($truncatehead); + ($this->export->outputHandler)($truncate); } // scheme for inserting fields @@ -2127,7 +2120,7 @@ class ExportSql extends ExportPlugin ) . $this->exportComment() . "\n"; - if (! $this->export->outputHandler($head)) { + if (! ($this->export->outputHandler)($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->export->outputHandler)( '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->export->outputHandler)(';' . "\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->export->outputHandler)(($currentRow === 1 ? '' : $separator . "\n") . $insertLine)) { return false; } } if ($currentRow > 0) { - if (! $this->export->outputHandler(';' . "\n")) { + if (! ($this->export->outputHandler)(';' . "\n")) { return false; } } // We need to SET IDENTITY_INSERT OFF for MSSQL if ($this->compatibility === 'MSSQL' && $currentRow > 0) { - $outputSucceeded = $this->export->outputHandler( + $outputSucceeded = ($this->export->outputHandler)( "\n" . 'SET IDENTITY_INSERT ' - . Util::backquoteCompat( - $tableAlias, - $this->compatibility, - $this->useSqlBackquotes, - ) + . Util::backquoteCompat($tableAlias, $this->compatibility, $this->useSqlBackquotes) . ' OFF;' . "\n", ); if (! $outputSucceeded) { diff --git a/src/Plugins/Export/ExportTexytext.php b/src/Plugins/Export/ExportTexytext.php index 276bf7471e..684583989b 100644 --- a/src/Plugins/Export/ExportTexytext.php +++ b/src/Plugins/Export/ExportTexytext.php @@ -111,7 +111,7 @@ class ExportTexytext extends ExportPlugin $dbAlias = $db; } - return $this->export->outputHandler( + return ($this->export->outputHandler)( '===' . __('Database') . ' ' . $dbAlias . "\n\n", ); } @@ -133,7 +133,7 @@ class ExportTexytext extends ExportPlugin $tableAlias = $this->getTableAlias($aliases, $db, $table); if ( - ! $this->export->outputHandler( + ! ($this->export->outputHandler)( $tableAlias !== '' ? '== ' . __('Dumping data for table') . ' ' . $tableAlias . "\n\n" : '==' . __('Dumping data for query result') . "\n\n", @@ -158,7 +158,7 @@ class ExportTexytext extends ExportPlugin } $textOutput .= "\n|------\n"; - if (! $this->export->outputHandler($textOutput)) { + if (! ($this->export->outputHandler)($textOutput)) { return false; } } @@ -184,7 +184,7 @@ class ExportTexytext extends ExportPlugin } $textOutput .= "\n"; - if (! $this->export->outputHandler($textOutput)) { + if (! ($this->export->outputHandler)($textOutput)) { return false; } } @@ -429,7 +429,7 @@ class ExportTexytext extends ExportPlugin $dump .= $this->getTableDefStandIn($db, $table, $aliases); } - return $this->export->outputHandler($dump); + return ($this->export->outputHandler)($dump); } /** diff --git a/src/Plugins/Export/ExportXml.php b/src/Plugins/Export/ExportXml.php index c4ab0b5a84..d9cf47d748 100644 --- a/src/Plugins/Export/ExportXml.php +++ b/src/Plugins/Export/ExportXml.php @@ -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->export->outputHandler->outputCharsetConversion ? Current::$charset : 'utf-8'; $config = Config::getInstance(); $head = '' . "\n" @@ -337,7 +336,7 @@ class ExportXml extends ExportPlugin } } - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($head); } /** @@ -347,7 +346,7 @@ class ExportXml extends ExportPlugin { $foot = ''; - return $this->export->outputHandler($foot); + return ($this->export->outputHandler)($foot); } /** @@ -369,7 +368,7 @@ class ExportXml extends ExportPlugin . ' -->' . "\n" . ' ' . "\n"; - return $this->export->outputHandler($head); + return ($this->export->outputHandler)($head); } return true; @@ -383,7 +382,7 @@ class ExportXml extends ExportPlugin public function exportDBFooter(string $db): bool { if ($this->exportContents) { - return $this->export->outputHandler(' ' . "\n"); + return ($this->export->outputHandler)(' ' . "\n"); } return true; @@ -418,7 +417,7 @@ class ExportXml extends ExportPlugin $buffer = ' ' . "\n"; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } @@ -442,7 +441,7 @@ class ExportXml extends ExportPlugin $buffer .= ' ' . "\n"; - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } } diff --git a/src/Plugins/Export/ExportYaml.php b/src/Plugins/Export/ExportYaml.php index 8ae7dda0be..dfe7292ed3 100644 --- a/src/Plugins/Export/ExportYaml.php +++ b/src/Plugins/Export/ExportYaml.php @@ -67,7 +67,7 @@ class ExportYaml extends ExportPlugin */ public function exportHeader(): bool { - $this->export->outputHandler('%YAML 1.1' . "\n" . '---' . "\n"); + ($this->export->outputHandler)('%YAML 1.1' . "\n" . '---' . "\n"); return true; } @@ -77,7 +77,7 @@ class ExportYaml extends ExportPlugin */ public function exportFooter(): bool { - $this->export->outputHandler('...' . "\n"); + ($this->export->outputHandler)('...' . "\n"); return true; } @@ -148,7 +148,7 @@ class ExportYaml extends ExportPlugin $buffer .= ' ' . $columns[$i] . ': "' . $record[$i] . '"' . "\n"; } - if (! $this->export->outputHandler($buffer)) { + if (! ($this->export->outputHandler)($buffer)) { return false; } } diff --git a/src/Table/TableMover.php b/src/Table/TableMover.php index 2a613c9584..2081350a67 100644 --- a/src/Table/TableMover.php +++ b/src/Table/TableMover.php @@ -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); diff --git a/tests/unit/Export/ExportTest.php b/tests/unit/Export/ExportTest.php index dc54bd1398..1875a36f14 100644 --- a/tests/unit/Export/ExportTest.php +++ b/tests/unit/Export/ExportTest.php @@ -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; @@ -92,9 +93,7 @@ class ExportTest extends AbstractTestCase 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 @@ -150,9 +149,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'] = ''; diff --git a/tests/unit/Plugins/Export/ExportCodegenTest.php b/tests/unit/Plugins/Export/ExportCodegenTest.php index d301e0633e..a2148531bb 100644 --- a/tests/unit/Plugins/Export/ExportCodegenTest.php +++ b/tests/unit/Plugins/Export/ExportCodegenTest.php @@ -7,6 +7,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; @@ -164,11 +165,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']); diff --git a/tests/unit/Plugins/Export/ExportCsvTest.php b/tests/unit/Plugins/Export/ExportCsvTest.php index 9d99d4e079..3504de5343 100644 --- a/tests/unit/Plugins/Export/ExportCsvTest.php +++ b/tests/unit/Plugins/Export/ExportCsvTest.php @@ -8,6 +8,7 @@ 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,7 +45,6 @@ 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)); @@ -255,27 +255,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']); diff --git a/tests/unit/Plugins/Export/ExportExcelTest.php b/tests/unit/Plugins/Export/ExportExcelTest.php index 22abec7a06..a2530482d0 100644 --- a/tests/unit/Plugins/Export/ExportExcelTest.php +++ b/tests/unit/Plugins/Export/ExportExcelTest.php @@ -7,6 +7,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; @@ -216,27 +217,7 @@ 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']); diff --git a/tests/unit/Plugins/Export/ExportHtmlwordTest.php b/tests/unit/Plugins/Export/ExportHtmlwordTest.php index 984f32f9ee..b364f557ca 100644 --- a/tests/unit/Plugins/Export/ExportHtmlwordTest.php +++ b/tests/unit/Plugins/Export/ExportHtmlwordTest.php @@ -11,6 +11,7 @@ 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; @@ -63,11 +64,7 @@ class ExportHtmlwordTest extends AbstractTestCase new Export($this->dbi), 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 +290,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']); diff --git a/tests/unit/Plugins/Export/ExportJsonTest.php b/tests/unit/Plugins/Export/ExportJsonTest.php index 8126674b63..c18f88266b 100644 --- a/tests/unit/Plugins/Export/ExportJsonTest.php +++ b/tests/unit/Plugins/Export/ExportJsonTest.php @@ -7,6 +7,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,11 +36,7 @@ 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)); } diff --git a/tests/unit/Plugins/Export/ExportLatexTest.php b/tests/unit/Plugins/Export/ExportLatexTest.php index 829ea47e18..8a44353ec1 100644 --- a/tests/unit/Plugins/Export/ExportLatexTest.php +++ b/tests/unit/Plugins/Export/ExportLatexTest.php @@ -11,6 +11,7 @@ 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,11 +50,7 @@ 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'; diff --git a/tests/unit/Plugins/Export/ExportMediawikiTest.php b/tests/unit/Plugins/Export/ExportMediawikiTest.php index e3a7ca4c02..db78381b01 100644 --- a/tests/unit/Plugins/Export/ExportMediawikiTest.php +++ b/tests/unit/Plugins/Export/ExportMediawikiTest.php @@ -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\Http\Factory\ServerRequestFactory; use PhpMyAdmin\Plugins\Export\ExportMediawiki; use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup; @@ -43,11 +44,7 @@ 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'; diff --git a/tests/unit/Plugins/Export/ExportOdsTest.php b/tests/unit/Plugins/Export/ExportOdsTest.php index 48eb44e16b..030410849a 100644 --- a/tests/unit/Plugins/Export/ExportOdsTest.php +++ b/tests/unit/Plugins/Export/ExportOdsTest.php @@ -8,6 +8,7 @@ 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,11 +53,7 @@ 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)); } diff --git a/tests/unit/Plugins/Export/ExportOdtTest.php b/tests/unit/Plugins/Export/ExportOdtTest.php index 61ce1512d6..49c668e552 100644 --- a/tests/unit/Plugins/Export/ExportOdtTest.php +++ b/tests/unit/Plugins/Export/ExportOdtTest.php @@ -11,6 +11,7 @@ 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,11 +68,7 @@ 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; diff --git a/tests/unit/Plugins/Export/ExportPdfTest.php b/tests/unit/Plugins/Export/ExportPdfTest.php index 4f2a80b2ba..2641ce7143 100644 --- a/tests/unit/Plugins/Export/ExportPdfTest.php +++ b/tests/unit/Plugins/Export/ExportPdfTest.php @@ -7,6 +7,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\ExportPdf; use PhpMyAdmin\Plugins\Export\Helpers\Pdf; @@ -39,11 +40,7 @@ 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)); } diff --git a/tests/unit/Plugins/Export/ExportPhparrayTest.php b/tests/unit/Plugins/Export/ExportPhparrayTest.php index 0b2c162444..974dda4c72 100644 --- a/tests/unit/Plugins/Export/ExportPhparrayTest.php +++ b/tests/unit/Plugins/Export/ExportPhparrayTest.php @@ -8,6 +8,7 @@ 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,11 +39,7 @@ 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'; diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index 8409d8ac31..35bdf6d17b 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -13,6 +13,7 @@ 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,10 +68,7 @@ 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; @@ -385,8 +383,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 +413,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) diff --git a/tests/unit/Plugins/Export/ExportTexytextTest.php b/tests/unit/Plugins/Export/ExportTexytextTest.php index 9435752189..d480c20741 100644 --- a/tests/unit/Plugins/Export/ExportTexytextTest.php +++ b/tests/unit/Plugins/Export/ExportTexytextTest.php @@ -12,6 +12,7 @@ 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 +59,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 = ''; diff --git a/tests/unit/Plugins/Export/ExportXmlTest.php b/tests/unit/Plugins/Export/ExportXmlTest.php index 22aaf91605..e2de0ff5db 100644 --- a/tests/unit/Plugins/Export/ExportXmlTest.php +++ b/tests/unit/Plugins/Export/ExportXmlTest.php @@ -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\Http\Factory\ServerRequestFactory; use PhpMyAdmin\Plugins\Export\ExportXml; use PhpMyAdmin\Plugins\ExportPlugin; @@ -43,10 +44,7 @@ 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'; @@ -168,7 +166,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 +287,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 +403,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']); diff --git a/tests/unit/Plugins/Export/ExportYamlTest.php b/tests/unit/Plugins/Export/ExportYamlTest.php index 51f075b8fa..cf0256701d 100644 --- a/tests/unit/Plugins/Export/ExportYamlTest.php +++ b/tests/unit/Plugins/Export/ExportYamlTest.php @@ -8,6 +8,7 @@ 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,10 +39,7 @@ 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';