From 2638eb920796bf85c15c9f0752855c6271180507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 31 Mar 2018 19:28:25 -0300 Subject: [PATCH] Refactor PhpMyAdmin\Export static methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces static methods with instance methods. Signed-off-by: MaurĂ­cio Meneghini Fauth --- db_export.php | 10 ++- export.php | 46 +++++------ libraries/classes/Display/Results.php | 2 +- libraries/classes/Export.php | 76 +++++++++---------- .../classes/Plugins/Export/ExportCodegen.php | 5 +- .../classes/Plugins/Export/ExportCsv.php | 5 +- .../classes/Plugins/Export/ExportHtmlword.php | 18 ++--- .../classes/Plugins/Export/ExportJson.php | 17 +++-- .../classes/Plugins/Export/ExportLatex.php | 26 +++---- .../Plugins/Export/ExportMediawiki.php | 5 +- .../classes/Plugins/Export/ExportOds.php | 3 +- .../classes/Plugins/Export/ExportOdt.php | 3 +- .../classes/Plugins/Export/ExportPdf.php | 5 +- .../classes/Plugins/Export/ExportPhparray.php | 7 +- .../classes/Plugins/Export/ExportSql.php | 53 +++++++------ .../classes/Plugins/Export/ExportTexytext.php | 10 +-- .../classes/Plugins/Export/ExportXml.php | 13 ++-- .../classes/Plugins/Export/ExportYaml.php | 7 +- libraries/classes/Plugins/ExportPlugin.php | 7 ++ schema_export.php | 3 +- test/classes/ExportTest.php | 21 ++++- 21 files changed, 189 insertions(+), 153 deletions(-) diff --git a/db_export.php b/db_export.php index b04a8b0193..05df8d9767 100644 --- a/db_export.php +++ b/db_export.php @@ -24,6 +24,8 @@ $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('export.js'); +$export = new Export(); + // $sub_part is used in Util::getDbInfo() to see if we are coming from // db_export.php, in which case we don't obey $cfg['MaxTableList'] $sub_part = '_export'; @@ -95,25 +97,25 @@ foreach (array('table_select', 'table_structure', 'table_data') as $one_key) { foreach ($tables as $each_table) { if (isset($_GET['table_select']) && is_array($_GET['table_select'])) { - $is_checked = Export::getCheckedClause( + $is_checked = $export->getCheckedClause( $each_table['Name'], $_GET['table_select'] ); } elseif (isset($table_select)) { - $is_checked = Export::getCheckedClause( + $is_checked = $export->getCheckedClause( $each_table['Name'], $table_select ); } else { $is_checked = ' checked="checked"'; } if (isset($_GET['table_structure']) && is_array($_GET['table_structure'])) { - $structure_checked = Export::getCheckedClause( + $structure_checked = $export->getCheckedClause( $each_table['Name'], $_GET['table_structure'] ); } else { $structure_checked = $is_checked; } if (isset($_GET['table_data']) && is_array($_GET['table_data'])) { - $data_checked = Export::getCheckedClause( + $data_checked = $export->getCheckedClause( $each_table['Name'], $_GET['table_data'] ); } else { diff --git a/export.php b/export.php index 376bd020c2..e1255ae631 100644 --- a/export.php +++ b/export.php @@ -35,6 +35,8 @@ $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('export_output.js'); +$export = new Export(); + //check if it's the GET request to check export time out if (isset($_GET['check_time_out'])) { if (isset($_SESSION['pma_export_error'])) { @@ -298,7 +300,7 @@ if ((!empty($parser->statements[0])) $aliases = \PhpMyAdmin\SqlParser\Utils\Misc::getAliases($parser->statements[0], $db); } if (!empty($_REQUEST['aliases'])) { - $aliases = Export::mergeAliases($aliases, $_REQUEST['aliases']); + $aliases = $export->mergeAliases($aliases, $_REQUEST['aliases']); $_SESSION['tmpval']['aliases'] = $_REQUEST['aliases']; } @@ -309,7 +311,7 @@ Util::setTimeLimit(); if (! empty($cfg['MemoryLimit'])) { ini_set('memory_limit', $cfg['MemoryLimit']); } -register_shutdown_function('PhpMyAdmin\Export::shutdown'); +register_shutdown_function([$export, 'shutdown']); // Start with empty buffer $dump_buffer = ''; $dump_buffer_len = 0; @@ -339,7 +341,7 @@ $output_charset_conversion = $asfile $GLOBALS['onfly_compression'] = $GLOBALS['cfg']['CompressOnFly'] && $compression == 'gzip'; if ($GLOBALS['onfly_compression']) { - $GLOBALS['memory_limit'] = Export::getMemoryLimit(); + $GLOBALS['memory_limit'] = $export->getMemoryLimit(); } // Generate filename and mime type if needed @@ -347,7 +349,7 @@ if ($asfile) { if (empty($remember_template)) { $remember_template = ''; } - list($filename, $mime_type) = Export::getFilenameAndMimetype( + list($filename, $mime_type) = $export->getFilenameAndMimetype( $export_type, $remember_template, $export_plugin, $compression, $filename_template ); @@ -357,13 +359,13 @@ if ($asfile) { // Open file on server if needed if ($save_on_server) { - list($save_filename, $message, $file_handle) = Export::openFile( + list($save_filename, $message, $file_handle) = $export->openFile( $filename, $quick_export ); // problem opening export file on server? if (! empty($message)) { - Export::showPage($db, $table, $export_type); + $export->showPage($db, $table, $export_type); } } else { /** @@ -391,7 +393,7 @@ if ($save_on_server) { exit(); } } - list($html, $back_button, $refreshButton) = Export::getHtmlForDisplayedExportHeader( + list($html, $back_button, $refreshButton) = $export->getHtmlForDisplayedExportHeader( $export_type, $db, $table ); echo $html; @@ -434,7 +436,7 @@ do { if (! isset($db_select)) { $db_select = ''; } - Export::exportServer( + $export->exportServer( $db_select, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases, $separate_files @@ -451,19 +453,19 @@ do { $table_data = $tables; } if (isset($lock_tables)) { - Export::lockTables($db, $tables, "READ"); + $export->lockTables($db, $tables, "READ"); try { - Export::exportDatabase( + $export->exportDatabase( $db, $tables, $whatStrucOrData, $table_structure, $table_data, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases, $separate_files ); } finally { - Export::unlockTables(); + $export->unlockTables(); } } else { - Export::exportDatabase( + $export->exportDatabase( $db, $tables, $whatStrucOrData, $table_structure, $table_data, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases, $separate_files @@ -483,18 +485,18 @@ do { } if (isset($lock_tables)) { try { - Export::lockTables($db, array($table), "READ"); - Export::exportTable( + $export->lockTables($db, array($table), "READ"); + $export->exportTable( $db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, $aliases ); } finally { - Export::unlockTables(); + $export->unlockTables(); } } else { - Export::exportTable( + $export->exportTable( $db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, $aliases @@ -509,14 +511,14 @@ do { // End of fake loop if ($save_on_server && ! empty($message)) { - Export::showPage($db, $table, $export_type); + $export->showPage($db, $table, $export_type); } /** * Send the dump as a file... */ if (empty($asfile)) { - echo Export::getHtmlForDisplayedExportFooter($back_button, $refreshButton); + echo $export->getHtmlForDisplayedExportFooter($back_button, $refreshButton); return; } // end if @@ -532,21 +534,21 @@ if ($output_charset_conversion) { // Compression needed? if ($compression) { if (! empty($separate_files)) { - $dump_buffer = Export::compress( + $dump_buffer = $export->compress( $dump_buffer_objects, $compression, $filename ); } else { - $dump_buffer = Export::compress($dump_buffer, $compression, $filename); + $dump_buffer = $export->compress($dump_buffer, $compression, $filename); } } /* If we saved on server, we have to close file now */ if ($save_on_server) { - $message = Export::closeFile( + $message = $export->closeFile( $file_handle, $dump_buffer, $save_filename ); - Export::showPage($db, $table, $export_type); + $export->showPage($db, $table, $export_type); } else { echo $dump_buffer; } diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 7b772145bc..20619259ed 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -4938,7 +4938,7 @@ class Results // Export link // (the url_query has extra parameters that won't be used to export) - // (the single_table parameter is used in Export::getDisplay() + // (the single_table parameter is used in \PhpMyAdmin\Export->getDisplay() // to hide the SQL and the structure export dialogs) // If the parser found a PROCEDURE clause // (most probably PROCEDURE ANALYSE()) it makes no sense to diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 1f48b5f0c9..71cbfe50e2 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -30,7 +30,7 @@ class Export * * @return void */ - public static function shutdown() + public function shutdown() { $error = error_get_last(); if ($error != null && mb_strpos($error['message'], "execution time")) { @@ -44,7 +44,7 @@ class Export * * @return bool */ - public static function isGzHandlerEnabled() + public function isGzHandlerEnabled() { return in_array('ob_gzhandler', ob_list_handlers()); } @@ -55,7 +55,7 @@ class Export * * @return bool Whether gzencode is needed */ - public static function gzencodeNeeded() + public function gzencodeNeeded() { /* * We should gzencode only if the function exists @@ -69,7 +69,7 @@ class Export if (function_exists('gzencode') && ((! ini_get('zlib.output_compression') - && ! self::isGzHandlerEnabled()) + && ! $this->isGzHandlerEnabled()) || $GLOBALS['save_on_server'] || $chromeAndGreaterThan43) ) { @@ -87,7 +87,7 @@ class Export * * @return bool Whether output succeeded */ - public static function outputHandler($line) + public function outputHandler($line) { global $time_start, $dump_buffer, $dump_buffer_len, $save_filename; @@ -117,7 +117,7 @@ class Export ); } if ($GLOBALS['compression'] == 'gzip' - && self::gzencodeNeeded() + && $this->gzencodeNeeded() ) { // as a gzipped file // without the optional parameter level because it bugs @@ -184,7 +184,7 @@ class Export } } return true; - } // end of the 'self::outputHandler()' function + } /** * Returns HTML containing the footer for a displayed export @@ -194,7 +194,7 @@ class Export * * @return string $html the HTML output */ - public static function getHtmlForDisplayedExportFooter($back_button, $refreshButton) + public function getHtmlForDisplayedExportFooter($back_button, $refreshButton) { /** * Close the html tags and add the footers for on-screen export @@ -222,7 +222,7 @@ class Export * * @return int $memory_limit the memory limit */ - public static function getMemoryLimit() + public function getMemoryLimit() { $memory_limit = trim(ini_get('memory_limit')); $memory_limit_num = (int)substr($memory_limit, 0, -1); @@ -263,7 +263,7 @@ class Export * * @return string[] the filename template and mime type */ - public static function getFilenameAndMimetype( + public function getFilenameAndMimetype( $export_type, $remember_template, $export_plugin, $compression, $filename_template ) { @@ -332,7 +332,7 @@ class Export * * @return array the full save filename, possible message and the file handle */ - public static function openFile($filename, $quick_export) + public function openFile($filename, $quick_export) { $file_handle = null; $message = ''; @@ -381,7 +381,7 @@ class Export * * @return Message $message a message object (or empty string) */ - public static function closeFile($file_handle, $dump_buffer, $save_filename) + public function closeFile($file_handle, $dump_buffer, $save_filename) { $write_result = @fwrite($file_handle, $dump_buffer); fclose($file_handle); @@ -414,13 +414,13 @@ class Export * * @return object $message a message object (or empty string) */ - public static function compress($dump_buffer, $compression, $filename) + public function compress($dump_buffer, $compression, $filename) { if ($compression == 'zip' && function_exists('gzcompress')) { $zipExtension = new ZipExtension(); $filename = substr($filename, 0, -4); // remove extension (.zip) $dump_buffer = $zipExtension->createFile($dump_buffer, $filename); - } elseif ($compression == 'gzip' && self::gzencodeNeeded()) { + } elseif ($compression == 'gzip' && $this->gzencodeNeeded()) { // without the optional parameter level because it bugs $dump_buffer = gzencode($dump_buffer); } @@ -436,7 +436,7 @@ class Export * * @return void */ - public static function saveObjectInBuffer($object_name, $append = false) + public function saveObjectInBuffer($object_name, $append = false) { global $dump_buffer_objects, $dump_buffer, $dump_buffer_len; @@ -464,7 +464,7 @@ class Export * * @return string[] the generated HTML and back button */ - public static function getHtmlForDisplayedExportHeader($export_type, $db, $table) + public function getHtmlForDisplayedExportHeader($export_type, $db, $table) { $html = '
'; @@ -555,7 +555,7 @@ class Export * * @return void */ - public static function exportServer( + public function exportServer( $db_select, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, array $aliases, $separate_files @@ -570,14 +570,14 @@ class Export && mb_strpos(' ' . $tmp_select, '|' . $current_db . '|') ) { $tables = $GLOBALS['dbi']->getTables($current_db); - self::exportDatabase( + $this->exportDatabase( $current_db, $tables, $whatStrucOrData, $tables, $tables, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases, $separate_files == 'database' ? $separate_files : '' ); if ($separate_files == 'server') { - self::saveObjectInBuffer($current_db); + $this->saveObjectInBuffer($current_db); } } } // end foreach database @@ -604,7 +604,7 @@ class Export * * @return void */ - public static function exportDatabase( + public function exportDatabase( $db, array $tables, $whatStrucOrData, array $table_structure, array $table_data, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, array $aliases, $separate_files @@ -619,7 +619,7 @@ class Export return; } if ($separate_files == 'database') { - self::saveObjectInBuffer('database', true); + $this->saveObjectInBuffer('database', true); } if (($GLOBALS['sql_structure_or_data'] == 'structure' @@ -629,7 +629,7 @@ class Export $export_plugin->exportRoutines($db, $aliases); if ($separate_files == 'database') { - self::saveObjectInBuffer('routines'); + $this->saveObjectInBuffer('routines'); } } @@ -712,7 +712,7 @@ class Export // this buffer was filled, we save it and go to the next one if ($separate_files == 'database') { - self::saveObjectInBuffer('table_' . $table); + $this->saveObjectInBuffer('table_' . $table); } // now export the triggers (needs to be done after the data because @@ -730,7 +730,7 @@ class Export } if ($separate_files == 'database') { - self::saveObjectInBuffer('table_' . $table, true); + $this->saveObjectInBuffer('table_' . $table, true); } } @@ -752,7 +752,7 @@ class Export } if ($separate_files == 'database') { - self::saveObjectInBuffer('view_' . $view); + $this->saveObjectInBuffer('view_' . $view); } } } @@ -767,16 +767,16 @@ class Export if (isset($GLOBALS['sql_metadata'])) { // Types of metadata to export. // In the future these can be allowed to be selected by the user - $metadataTypes = self::getMetadataTypes(); + $metadataTypes = $this->getMetadataTypes(); $export_plugin->exportMetadata($db, $tables, $metadataTypes); if ($separate_files == 'database') { - self::saveObjectInBuffer('metadata'); + $this->saveObjectInBuffer('metadata'); } } if ($separate_files == 'database') { - self::saveObjectInBuffer('extra'); + $this->saveObjectInBuffer('extra'); } if (($GLOBALS['sql_structure_or_data'] == 'structure' @@ -786,7 +786,7 @@ class Export $export_plugin->exportEvents($db); if ($separate_files == 'database') { - self::saveObjectInBuffer('events'); + $this->saveObjectInBuffer('events'); } } } @@ -813,7 +813,7 @@ class Export * * @return void */ - public static function exportTable( + public function exportTable( $db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, array $aliases @@ -915,7 +915,7 @@ class Export if (isset($GLOBALS['sql_metadata'])) { // Types of metadata to export. // In the future these can be allowed to be selected by the user - $metadataTypes = self::getMetadataTypes(); + $metadataTypes = $this->getMetadataTypes(); $export_plugin->exportMetadata($db, $table, $metadataTypes); } } @@ -929,7 +929,7 @@ class Export * * @return void */ - public static function showPage($db, $table, $export_type) + public function showPage($db, $table, $export_type) { global $cfg; if ($export_type == 'server') { @@ -955,7 +955,7 @@ class Export * * @return array resultant merged aliases info */ - public static function mergeAliases(array $aliases1, array $aliases2) + public function mergeAliases(array $aliases1, array $aliases2) { // First do a recursive array merge // on aliases arrays. @@ -1008,7 +1008,7 @@ class Export * * @return mixed result of the query */ - public static function lockTables($db, array $tables, $lockType = "WRITE") + public function lockTables($db, array $tables, $lockType = "WRITE") { $locks = array(); foreach ($tables as $table) { @@ -1025,7 +1025,7 @@ class Export * * @return mixed result of the query */ - public static function unlockTables() + public function unlockTables() { return $GLOBALS['dbi']->tryQuery("UNLOCK TABLES"); } @@ -1035,7 +1035,7 @@ class Export * * @return string[] metadata types. */ - public static function getMetadataTypes() + public function getMetadataTypes() { return array( 'column_info', @@ -1059,7 +1059,7 @@ class Export * * @return string the checked clause */ - public static function getCheckedClause($key, array $array) + public function getCheckedClause($key, array $array) { if (in_array($key, $array)) { return ' checked="checked"'; @@ -1076,7 +1076,7 @@ class Export * * @return void */ - public static function processExportSchema($export_type) + public function processExportSchema($export_type) { /** * default is PDF, otherwise validate it's only letters a-z diff --git a/libraries/classes/Plugins/Export/ExportCodegen.php b/libraries/classes/Plugins/Export/ExportCodegen.php index b2a2763fd4..e00f22462b 100644 --- a/libraries/classes/Plugins/Export/ExportCodegen.php +++ b/libraries/classes/Plugins/Export/ExportCodegen.php @@ -44,6 +44,7 @@ class ExportCodegen extends ExportPlugin */ public function __construct() { + parent::__construct(); // initialize the specific export CodeGen variables $this->initSpecificVariables(); $this->setProperties(); @@ -196,12 +197,12 @@ class ExportCodegen extends ExportPlugin if (isset($CG_FORMATS[$format])) { $method = $CG_HANDLERS[$format]; - return Export::outputHandler( + return $this->export->outputHandler( $this->$method($db, $table, $crlf, $aliases) ); } - return Export::outputHandler(sprintf("%s is not supported.", $format)); + return $this->export->outputHandler(sprintf("%s is not supported.", $format)); } /** diff --git a/libraries/classes/Plugins/Export/ExportCsv.php b/libraries/classes/Plugins/Export/ExportCsv.php index 13f2c87bad..40effaf1ce 100644 --- a/libraries/classes/Plugins/Export/ExportCsv.php +++ b/libraries/classes/Plugins/Export/ExportCsv.php @@ -32,6 +32,7 @@ class ExportCsv extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -256,7 +257,7 @@ class ExportCsv extends ExportPlugin $schema_insert .= $csv_separator; } // end for $schema_insert = trim(mb_substr($schema_insert, 0, -1)); - if (!Export::outputHandler($schema_insert . $csv_terminated)) { + if (!$this->export->outputHandler($schema_insert . $csv_terminated)) { return false; } } // end if @@ -321,7 +322,7 @@ class ExportCsv extends ExportPlugin } } // end for - if (!Export::outputHandler($schema_insert . $csv_terminated)) { + if (!$this->export->outputHandler($schema_insert . $csv_terminated)) { return false; } } // end while diff --git a/libraries/classes/Plugins/Export/ExportHtmlword.php b/libraries/classes/Plugins/Export/ExportHtmlword.php index 5aa72935c9..fda8fa1e6a 100644 --- a/libraries/classes/Plugins/Export/ExportHtmlword.php +++ b/libraries/classes/Plugins/Export/ExportHtmlword.php @@ -109,7 +109,7 @@ class ExportHtmlword extends ExportPlugin { global $charset; - return Export::outputHandler( + return $this->export->outputHandler( ' @@ -132,7 +132,7 @@ class ExportHtmlword extends ExportPlugin */ public function exportFooter() { - return Export::outputHandler(''); + return $this->export->outputHandler(''); } /** @@ -149,7 +149,7 @@ class ExportHtmlword extends ExportPlugin $db_alias = $db; } - return Export::outputHandler( + return $this->export->outputHandler( '

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

' ); } @@ -206,7 +206,7 @@ class ExportHtmlword extends ExportPlugin $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); - if (!Export::outputHandler( + if (!$this->export->outputHandler( '

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

' @@ -214,7 +214,7 @@ class ExportHtmlword extends ExportPlugin ) { return false; } - if (!Export::outputHandler( + if (!$this->export->outputHandler( '' ) ) { @@ -243,7 +243,7 @@ class ExportHtmlword extends ExportPlugin . ''; } // end for $schema_insert .= ''; - if (!Export::outputHandler($schema_insert)) { + if (!$this->export->outputHandler($schema_insert)) { return false; } } // end if @@ -264,13 +264,13 @@ class ExportHtmlword extends ExportPlugin . ''; } // end for $schema_insert .= ''; - if (!Export::outputHandler($schema_insert)) { + if (!$this->export->outputHandler($schema_insert)) { return false; } } // end while $GLOBALS['dbi']->freeResult($result); - return Export::outputHandler('
'); + return $this->export->outputHandler(''); } /** @@ -604,7 +604,7 @@ class ExportHtmlword extends ExportPlugin $dump .= $this->getTableDefStandIn($db, $table, $crlf, $aliases); } // end switch - return Export::outputHandler($dump); + return $this->export->outputHandler($dump); } /** diff --git a/libraries/classes/Plugins/Export/ExportJson.php b/libraries/classes/Plugins/Export/ExportJson.php index 326a371b84..70ebcc8bd6 100644 --- a/libraries/classes/Plugins/Export/ExportJson.php +++ b/libraries/classes/Plugins/Export/ExportJson.php @@ -32,6 +32,7 @@ class ExportJson extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -119,7 +120,7 @@ class ExportJson extends ExportPlugin 'comment' => 'Export to JSON plugin for PHPMyAdmin', ); - return Export::outputHandler( + return $this->export->outputHandler( '[' . $crlf . $this->encode($meta) . ',' . $crlf ); } @@ -133,7 +134,7 @@ class ExportJson extends ExportPlugin { global $crlf; - return Export::outputHandler(']' . $crlf); + return $this->export->outputHandler(']' . $crlf); } /** @@ -157,7 +158,7 @@ class ExportJson extends ExportPlugin 'name' => $db_alias ); - return Export::outputHandler( + return $this->export->outputHandler( $this->encode($meta) . ',' . $crlf ); } @@ -213,7 +214,7 @@ class ExportJson extends ExportPlugin $this->initAlias($aliases, $db_alias, $table_alias); if (! $this->first) { - if (!Export::outputHandler(',')) { + if (!$this->export->outputHandler(',')) { return false; } } else { @@ -230,7 +231,7 @@ class ExportJson extends ExportPlugin ); list($header, $footer) = explode('"@@DATA@@"', $buffer); - if (!Export::outputHandler($header . $crlf . '[' . $crlf)) { + if (!$this->export->outputHandler($header . $crlf . '[' . $crlf)) { return false; } @@ -257,7 +258,7 @@ class ExportJson extends ExportPlugin // Output table name as comment if this is the first record of the table if ($record_cnt > 1) { - if (!Export::outputHandler(',' . $crlf)) { + if (!$this->export->outputHandler(',' . $crlf)) { return false; } } @@ -268,12 +269,12 @@ class ExportJson extends ExportPlugin $data[$columns[$i]] = $record[$i]; } - if (!Export::outputHandler($this->encode($data))) { + if (!$this->export->outputHandler($this->encode($data))) { return false; } } - if (!Export::outputHandler($crlf . ']' . $crlf . $footer . $crlf)) { + if (!$this->export->outputHandler($crlf . ']' . $crlf . $footer . $crlf)) { return false; } diff --git a/libraries/classes/Plugins/Export/ExportLatex.php b/libraries/classes/Plugins/Export/ExportLatex.php index f9cebe18ab..c915dac97e 100644 --- a/libraries/classes/Plugins/Export/ExportLatex.php +++ b/libraries/classes/Plugins/Export/ExportLatex.php @@ -223,7 +223,7 @@ class ExportLatex extends ExportPlugin . '% ' . __('Server version:') . ' ' . $GLOBALS['dbi']->getVersionString() . $crlf . '% ' . __('PHP Version:') . ' ' . phpversion() . $crlf; - return Export::outputHandler($head); + return $this->export->outputHandler($head); } /** @@ -254,7 +254,7 @@ class ExportLatex extends ExportPlugin . '% ' . __('Database:') . ' ' . '\'' . $db_alias . '\'' . $crlf . '% ' . $crlf; - return Export::outputHandler($head); + return $this->export->outputHandler($head); } /** @@ -351,7 +351,7 @@ class ExportLatex extends ExportPlugin ) . '} \\\\'; } - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } @@ -364,11 +364,11 @@ class ExportLatex extends ExportPlugin } $buffer = mb_substr($buffer, 0, -2) . '\\\\ \\hline \hline '; - if (!Export::outputHandler($buffer . ' \\endfirsthead ' . $crlf)) { + if (!$this->export->outputHandler($buffer . ' \\endfirsthead ' . $crlf)) { return false; } if (isset($GLOBALS['latex_caption'])) { - if (!Export::outputHandler( + if (!$this->export->outputHandler( '\\caption{' . Util::expandUserString( $GLOBALS['latex_data_continued_caption'], @@ -384,11 +384,11 @@ class ExportLatex extends ExportPlugin return false; } } - if (!Export::outputHandler($buffer . '\\endhead \\endfoot' . $crlf)) { + if (!$this->export->outputHandler($buffer . '\\endhead \\endfoot' . $crlf)) { return false; } } else { - if (!Export::outputHandler('\\\\ \hline')) { + if (!$this->export->outputHandler('\\\\ \hline')) { return false; } } @@ -417,13 +417,13 @@ class ExportLatex extends ExportPlugin } } $buffer .= ' \\\\ \\hline ' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } } $buffer = ' \\end{longtable}' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } @@ -506,7 +506,7 @@ class ExportLatex extends ExportPlugin */ $buffer = $crlf . '%' . $crlf . '% ' . __('Structure:') . ' ' . $table_alias . $crlf . '%' . $crlf . ' \\begin{longtable}{'; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } @@ -575,7 +575,7 @@ class ExportLatex extends ExportPlugin } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot ' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } @@ -648,14 +648,14 @@ class ExportLatex extends ExportPlugin $buffer = str_replace("\000", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } } // end while $buffer = ' \\end{longtable}' . $crlf; - return Export::outputHandler($buffer); + return $this->export->outputHandler($buffer); } // end of the 'exportStructure' method /** diff --git a/libraries/classes/Plugins/Export/ExportMediawiki.php b/libraries/classes/Plugins/Export/ExportMediawiki.php index 93210d5168..efe09f4f33 100644 --- a/libraries/classes/Plugins/Export/ExportMediawiki.php +++ b/libraries/classes/Plugins/Export/ExportMediawiki.php @@ -32,6 +32,7 @@ class ExportMediawiki extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -262,7 +263,7 @@ class ExportMediawiki extends ExportPlugin break; } // end switch - return Export::outputHandler($output); + return $this->export->outputHandler($output); } /** @@ -347,7 +348,7 @@ class ExportMediawiki extends ExportPlugin // End table construction $output .= "|}" . str_repeat($this->_exportCRLF(), 2); - return Export::outputHandler($output); + return $this->export->outputHandler($output); } /** diff --git a/libraries/classes/Plugins/Export/ExportOds.php b/libraries/classes/Plugins/Export/ExportOds.php index ca822b7890..5a444140a5 100644 --- a/libraries/classes/Plugins/Export/ExportOds.php +++ b/libraries/classes/Plugins/Export/ExportOds.php @@ -32,6 +32,7 @@ class ExportOds extends ExportPlugin */ public function __construct() { + parent::__construct(); $GLOBALS['ods_buffer'] = ''; $this->setProperties(); } @@ -149,7 +150,7 @@ class ExportOds extends ExportPlugin . '' . ''; - return Export::outputHandler( + return $this->export->outputHandler( OpenDocument::create( 'application/vnd.oasis.opendocument.spreadsheet', $GLOBALS['ods_buffer'] diff --git a/libraries/classes/Plugins/Export/ExportOdt.php b/libraries/classes/Plugins/Export/ExportOdt.php index 9f840d4dd2..a7a0566219 100644 --- a/libraries/classes/Plugins/Export/ExportOdt.php +++ b/libraries/classes/Plugins/Export/ExportOdt.php @@ -18,7 +18,6 @@ use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup; use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; -use PhpMyAdmin\Relation; use PhpMyAdmin\Transformations; use PhpMyAdmin\Util; @@ -168,7 +167,7 @@ class ExportOdt extends ExportPlugin $GLOBALS['odt_buffer'] .= '' . '' . ''; - if (!Export::outputHandler( + if (!$this->export->outputHandler( OpenDocument::create( 'application/vnd.oasis.opendocument.text', $GLOBALS['odt_buffer'] diff --git a/libraries/classes/Plugins/Export/ExportPdf.php b/libraries/classes/Plugins/Export/ExportPdf.php index ff08fbc9ab..8441a907f8 100644 --- a/libraries/classes/Plugins/Export/ExportPdf.php +++ b/libraries/classes/Plugins/Export/ExportPdf.php @@ -39,6 +39,7 @@ class ExportPdf extends ExportPlugin * @var Pdf */ private $_pdf; + /** * PDF Report Title * @@ -51,6 +52,8 @@ class ExportPdf extends ExportPlugin */ public function __construct() { + parent::__construct(); + // initialize the specific export PDF variables $this->initSpecificVariables(); @@ -151,7 +154,7 @@ class ExportPdf extends ExportPlugin $pdf = $this->_getPdf(); // instead of $pdf->Output(): - return Export::outputHandler($pdf->getPDFData()); + return $this->export->outputHandler($pdf->getPDFData()); } /** diff --git a/libraries/classes/Plugins/Export/ExportPhparray.php b/libraries/classes/Plugins/Export/ExportPhparray.php index 051ee3bfad..3199ec588b 100644 --- a/libraries/classes/Plugins/Export/ExportPhparray.php +++ b/libraries/classes/Plugins/Export/ExportPhparray.php @@ -31,6 +31,7 @@ class ExportPhparray extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -87,7 +88,7 @@ class ExportPhparray extends ExportPlugin */ public function exportHeader() { - Export::outputHandler( + $this->export->outputHandler( 'export->outputHandler( '/**' . $GLOBALS['crlf'] . ' * Database ' . $this->commentString(Util::backquote($db_alias)) . $GLOBALS['crlf'] . ' */' . $GLOBALS['crlf'] @@ -246,7 +247,7 @@ class ExportPhparray extends ExportPlugin } $buffer .= $crlf . ');' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index d9a9f6d82b..92ced9d10d 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -22,7 +22,6 @@ use PhpMyAdmin\Properties\Options\Items\NumberPropertyItem; use PhpMyAdmin\Properties\Options\Items\RadioPropertyItem; use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem; use PhpMyAdmin\Properties\Options\Items\TextPropertyItem; -use PhpMyAdmin\Relation; use PhpMyAdmin\SqlParser\Components\CreateDefinition; use PhpMyAdmin\SqlParser\Context; use PhpMyAdmin\SqlParser\Parser; @@ -581,7 +580,7 @@ class ExportSql extends ExportPlugin } if (!empty($text)) { - return Export::outputHandler($text); + return $this->export->outputHandler($text); } return false; @@ -667,7 +666,7 @@ class ExportSql extends ExportPlugin $GLOBALS['dbi']->query('SET time_zone = "' . $GLOBALS['old_tz'] . '"'); } - return Export::outputHandler($foot); + return $this->export->outputHandler($foot); } /** @@ -774,7 +773,7 @@ class ExportSql extends ExportPlugin $this->_sent_charset = true; } - return Export::outputHandler($head); + return $this->export->outputHandler($head); } /** @@ -799,7 +798,7 @@ class ExportSql extends ExportPlugin $compat = 'NONE'; } if (isset($GLOBALS['sql_drop_database'])) { - if (!Export::outputHandler( + if (!$this->export->outputHandler( 'DROP DATABASE IF EXISTS ' . Util::backquoteCompat( $db_alias, @@ -835,7 +834,7 @@ class ExportSql extends ExportPlugin $create_query .= ' DEFAULT CHARACTER SET ' . $collation; } $create_query .= ';' . $crlf; - if (!Export::outputHandler($create_query)) { + if (!$this->export->outputHandler($create_query)) { return false; } @@ -857,7 +856,7 @@ class ExportSql extends ExportPlugin if (isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'NONE' ) { - $result = Export::outputHandler( + $result = $this->export->outputHandler( 'USE ' . Util::backquoteCompat( $db, @@ -867,7 +866,7 @@ class ExportSql extends ExportPlugin . ';' . $crlf ); } else { - $result = Export::outputHandler('USE ' . $db . ';' . $crlf); + $result = $this->export->outputHandler('USE ' . $db . ';' . $crlf); } return $result; @@ -902,7 +901,7 @@ class ExportSql extends ExportPlugin ) . $this->_exportComment(); - return Export::outputHandler($head); + return $this->export->outputHandler($head); } /** @@ -920,17 +919,17 @@ class ExportSql extends ExportPlugin //add indexes to the sql dump file if (isset($GLOBALS['sql_indexes'])) { - $result = Export::outputHandler($GLOBALS['sql_indexes']); + $result = $this->export->outputHandler($GLOBALS['sql_indexes']); unset($GLOBALS['sql_indexes']); } //add auto increments to the sql dump file if (isset($GLOBALS['sql_auto_increments'])) { - $result = Export::outputHandler($GLOBALS['sql_auto_increments']); + $result = $this->export->outputHandler($GLOBALS['sql_auto_increments']); unset($GLOBALS['sql_auto_increments']); } //add constraints to the sql dump file if (isset($GLOBALS['sql_constraints'])) { - $result = Export::outputHandler($GLOBALS['sql_constraints']); + $result = $this->export->outputHandler($GLOBALS['sql_constraints']); unset($GLOBALS['sql_constraints']); } @@ -979,7 +978,7 @@ class ExportSql extends ExportPlugin } if (!empty($text)) { - return Export::outputHandler($text); + return $this->export->outputHandler($text); } return false; @@ -1009,7 +1008,7 @@ class ExportSql extends ExportPlugin . $this->_exportComment() . $this->_exportComment(__('Metadata')) . $this->_exportComment(); - if (!Export::outputHandler($comment)) { + if (!$this->export->outputHandler($comment)) { return false; } @@ -1092,7 +1091,7 @@ class ExportSql extends ExportPlugin $comment .= $this->_exportComment(); - if (!Export::outputHandler($comment)) { + if (!$this->export->outputHandler($comment)) { return false; } @@ -1142,7 +1141,7 @@ class ExportSql extends ExportPlugin $lastPage = $GLOBALS['crlf'] . "SET @LAST_PAGE = LAST_INSERT_ID();" . $GLOBALS['crlf']; - if (!Export::outputHandler($lastPage)) { + if (!$this->export->outputHandler($lastPage)) { return false; } @@ -2132,7 +2131,7 @@ class ExportSql extends ExportPlugin // but not in the case of export unset($GLOBALS['sql_constraints_query']); - return Export::outputHandler($dump); + return $this->export->outputHandler($dump); } /** @@ -2190,7 +2189,7 @@ class ExportSql extends ExportPlugin . $this->_exportComment() . $this->_possibleCRLF(); - return Export::outputHandler($head); + return $this->export->outputHandler($head); } $result = $GLOBALS['dbi']->tryQuery( @@ -2206,7 +2205,7 @@ class ExportSql extends ExportPlugin if (! defined('TESTSUITE')) { trigger_error($message, E_USER_ERROR); } - return Export::outputHandler( + return $this->export->outputHandler( $this->_exportComment($message) ); } @@ -2296,8 +2295,8 @@ class ExportSql extends ExportPlugin ) . $this->_exportComment() . $crlf; - Export::outputHandler($truncatehead); - Export::outputHandler($truncate); + $this->export->outputHandler($truncatehead); + $this->export->outputHandler($truncate); } // scheme for inserting fields @@ -2348,7 +2347,7 @@ class ExportSql extends ExportPlugin ) . $this->_exportComment() . $crlf; - if (!Export::outputHandler($head)) { + if (!$this->export->outputHandler($head)) { return false; } } @@ -2357,7 +2356,7 @@ class ExportSql extends ExportPlugin && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row == 0 ) { - if (!Export::outputHandler( + if (!$this->export->outputHandler( 'SET IDENTITY_INSERT ' . Util::backquoteCompat( $table_alias, @@ -2468,7 +2467,7 @@ class ExportSql extends ExportPlugin && $sql_max_size > 0 && $query_size + $insertLineSize > $sql_max_size ) { - if (!Export::outputHandler(';' . $crlf)) { + if (!$this->export->outputHandler(';' . $crlf)) { return false; } $query_size = 0; @@ -2485,7 +2484,7 @@ class ExportSql extends ExportPlugin } unset($values); - if (!Export::outputHandler( + if (!$this->export->outputHandler( ($current_row == 1 ? '' : $separator . $crlf) . $insert_line ) @@ -2495,7 +2494,7 @@ class ExportSql extends ExportPlugin } // end while if ($current_row > 0) { - if (!Export::outputHandler(';' . $crlf)) { + if (!$this->export->outputHandler(';' . $crlf)) { return false; } } @@ -2505,7 +2504,7 @@ class ExportSql extends ExportPlugin && $GLOBALS['sql_compatibility'] == 'MSSQL' && $current_row > 0 ) { - $outputSucceeded = Export::outputHandler( + $outputSucceeded = $this->export->outputHandler( $crlf . 'SET IDENTITY_INSERT ' . Util::backquoteCompat( $table_alias, diff --git a/libraries/classes/Plugins/Export/ExportTexytext.php b/libraries/classes/Plugins/Export/ExportTexytext.php index 3100f3aa87..ac39db79fa 100644 --- a/libraries/classes/Plugins/Export/ExportTexytext.php +++ b/libraries/classes/Plugins/Export/ExportTexytext.php @@ -133,7 +133,7 @@ class ExportTexytext extends ExportPlugin $db_alias = $db; } - return Export::outputHandler( + return $this->export->outputHandler( '===' . __('Database') . ' ' . $db_alias . "\n\n" ); } @@ -190,7 +190,7 @@ class ExportTexytext extends ExportPlugin $table_alias = $table; $this->initAlias($aliases, $db_alias, $table_alias); - if (!Export::outputHandler( + if (!$this->export->outputHandler( '== ' . __('Dumping data for table') . ' ' . $table_alias . "\n\n" ) ) { @@ -217,7 +217,7 @@ class ExportTexytext extends ExportPlugin . htmlspecialchars(stripslashes($col_as)); } // end for $text_output .= "\n|------\n"; - if (!Export::outputHandler($text_output)) { + if (!$this->export->outputHandler($text_output)) { return false; } } // end if @@ -241,7 +241,7 @@ class ExportTexytext extends ExportPlugin ); } // end for $text_output .= "\n"; - if (!Export::outputHandler($text_output)) { + if (!$this->export->outputHandler($text_output)) { return false; } } // end while @@ -561,7 +561,7 @@ class ExportTexytext extends ExportPlugin $dump .= $this->getTableDefStandIn($db, $table, $crlf, $aliases); } // end switch - return Export::outputHandler($dump); + return $this->export->outputHandler($dump); } /** diff --git a/libraries/classes/Plugins/Export/ExportXml.php b/libraries/classes/Plugins/Export/ExportXml.php index 80731fb965..821026a2ed 100644 --- a/libraries/classes/Plugins/Export/ExportXml.php +++ b/libraries/classes/Plugins/Export/ExportXml.php @@ -49,6 +49,7 @@ class ExportXml extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -368,7 +369,7 @@ class ExportXml extends ExportPlugin } } - return Export::outputHandler($head); + return $this->export->outputHandler($head); } /** @@ -380,7 +381,7 @@ class ExportXml extends ExportPlugin { $foot = ''; - return Export::outputHandler($foot); + return $this->export->outputHandler($foot); } /** @@ -407,7 +408,7 @@ class ExportXml extends ExportPlugin . ' -->' . $crlf . ' ' . $crlf; - return Export::outputHandler($head); + return $this->export->outputHandler($head); } return true; @@ -427,7 +428,7 @@ class ExportXml extends ExportPlugin if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents'] ) { - return Export::outputHandler(' ' . $crlf); + return $this->export->outputHandler(' ' . $crlf); } return true; @@ -493,7 +494,7 @@ class ExportXml extends ExportPlugin $buffer = ' ' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } @@ -519,7 +520,7 @@ class ExportXml extends ExportPlugin } $buffer .= ' ' . $crlf; - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } } diff --git a/libraries/classes/Plugins/Export/ExportYaml.php b/libraries/classes/Plugins/Export/ExportYaml.php index 0e49fc65e1..ea3ab279b5 100644 --- a/libraries/classes/Plugins/Export/ExportYaml.php +++ b/libraries/classes/Plugins/Export/ExportYaml.php @@ -30,6 +30,7 @@ class ExportYaml extends ExportPlugin */ public function __construct() { + parent::__construct(); $this->setProperties(); } @@ -74,7 +75,7 @@ class ExportYaml extends ExportPlugin */ public function exportHeader() { - Export::outputHandler( + $this->export->outputHandler( '%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf'] ); @@ -88,7 +89,7 @@ class ExportYaml extends ExportPlugin */ public function exportFooter() { - Export::outputHandler('...' . $GLOBALS['crlf']); + $this->export->outputHandler('...' . $GLOBALS['crlf']); return true; } @@ -207,7 +208,7 @@ class ExportYaml extends ExportPlugin $buffer .= ' ' . $columns[$i] . ': "' . $record[$i] . '"' . $crlf; } - if (!Export::outputHandler($buffer)) { + if (!$this->export->outputHandler($buffer)) { return false; } } diff --git a/libraries/classes/Plugins/ExportPlugin.php b/libraries/classes/Plugins/ExportPlugin.php index 56710ad733..6185d9324c 100644 --- a/libraries/classes/Plugins/ExportPlugin.php +++ b/libraries/classes/Plugins/ExportPlugin.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin\Plugins; +use PhpMyAdmin\Export; use PhpMyAdmin\Properties\Plugins\ExportPluginProperties; use PhpMyAdmin\Relation; @@ -34,12 +35,18 @@ abstract class ExportPlugin */ protected $relation; + /** + * @var Export $export + */ + protected $export; + /** * Constructor */ public function __construct() { $this->relation = new Relation(); + $this->export = new Export(); } /** diff --git a/schema_export.php b/schema_export.php index d25657e8c2..2a5d4c62d1 100644 --- a/schema_export.php +++ b/schema_export.php @@ -30,4 +30,5 @@ if (! isset($_REQUEST['export_type'])) { * Include the appropriate Schema Class depending on $export_type * default is PDF */ -Export::processExportSchema($_REQUEST['export_type']); +$export = new Export(); +$export->processExportSchema($_REQUEST['export_type']); diff --git a/test/classes/ExportTest.php b/test/classes/ExportTest.php index 7f0709c226..0f27626bc6 100644 --- a/test/classes/ExportTest.php +++ b/test/classes/ExportTest.php @@ -21,11 +21,26 @@ use PHPUnit\Framework\TestCase; class ExportTest extends TestCase { /** - * Test for Export::mergeAliases + * @var Export + */ + private $export; + + /** + * Sets up the fixture * * @return void */ - public function testPMAMergeAliases() + protected function setUp() + { + $this->export = new Export(); + } + + /** + * Test for mergeAliases + * + * @return void + */ + public function testMergeAliases() { $aliases1 = array( 'test_db' => array( @@ -91,7 +106,7 @@ class ExportTest extends TestCase ) ) ); - $actual = Export::mergeAliases($aliases1, $aliases2); + $actual = $this->export->mergeAliases($aliases1, $aliases2); $this->assertEquals($expected, $actual); } }