From ca27f9303ba92c035712e2b5f8d612eb9547dfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 14 Sep 2017 14:42:33 -0300 Subject: [PATCH] Refactor schema_export function to a static method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Export.php | 39 ++++++++++++++++++++++++++++++ schema_export.php | 46 ++++-------------------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/libraries/classes/Export.php b/libraries/classes/Export.php index 98102076e1..c8c0466d9e 100644 --- a/libraries/classes/Export.php +++ b/libraries/classes/Export.php @@ -7,8 +7,10 @@ */ namespace PhpMyAdmin; +use PhpMyAdmin\Core; use PhpMyAdmin\Encoding; use PhpMyAdmin\Message; +use PhpMyAdmin\Plugins; use PhpMyAdmin\Plugins\ExportPlugin; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Table; @@ -1046,4 +1048,41 @@ class Export return ''; } } + + /** + * get all the export options and verify + * call and include the appropriate Schema Class depending on $export_type + * + * @param string $export_type format of the export + * + * @return void + */ + public static function processExportSchema($export_type) + { + /** + * default is PDF, otherwise validate it's only letters a-z + */ + if (! isset($export_type) || ! preg_match('/^[a-zA-Z]+$/', $export_type)) { + $export_type = 'pdf'; + } + + // sanitize this parameter which will be used below in a file inclusion + $export_type = Core::securePath($export_type); + + // get the specific plugin + /* @var $export_plugin SchemaPlugin */ + $export_plugin = Plugins::getPlugin( + "schema", + $export_type, + 'libraries/classes/Plugins/Schema/' + ); + + // Check schema export type + if (! isset($export_plugin)) { + Core::fatalError(__('Bad type!')); + } + + $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $export_plugin->exportSchema($GLOBALS['db']); + } } diff --git a/schema_export.php b/schema_export.php index fd5d2d13ce..6a007512e6 100644 --- a/schema_export.php +++ b/schema_export.php @@ -6,10 +6,9 @@ * @package PhpMyAdmin */ -use PhpMyAdmin\Core; -use PhpMyAdmin\Plugins; -use PhpMyAdmin\Plugins\SchemaPlugin; +use PhpMyAdmin\Export; use PhpMyAdmin\Relation; +use PhpMyAdmin\Util; /** * Gets some core libraries @@ -23,48 +22,11 @@ require_once 'libraries/common.inc.php'; $cfgRelation = Relation::getRelationsParam(); if (! isset($_REQUEST['export_type'])) { - PhpMyAdmin\Util::checkParameters(array('export_type')); + Util::checkParameters(array('export_type')); } /** * Include the appropriate Schema Class depending on $export_type * default is PDF */ -PMA_processExportSchema($_REQUEST['export_type']); - -/** - * get all the export options and verify - * call and include the appropriate Schema Class depending on $export_type - * - * @param string $export_type format of the export - * - * @return void - */ -function PMA_processExportSchema($export_type) -{ - /** - * default is PDF, otherwise validate it's only letters a-z - */ - if (! isset($export_type) || ! preg_match('/^[a-zA-Z]+$/', $export_type)) { - $export_type = 'pdf'; - } - - // sanitize this parameter which will be used below in a file inclusion - $export_type = Core::securePath($export_type); - - // get the specific plugin - /* @var $export_plugin SchemaPlugin */ - $export_plugin = Plugins::getPlugin( - "schema", - $export_type, - 'libraries/classes/Plugins/Schema/' - ); - - // Check schema export type - if (! isset($export_plugin)) { - Core::fatalError(__('Bad type!')); - } - - $GLOBALS['dbi']->selectDb($GLOBALS['db']); - $export_plugin->exportSchema($GLOBALS['db']); -} +Export::processExportSchema($_REQUEST['export_type']);