From 55151381fa3e1666b9745c9ddb8051f76e187838 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Tue, 4 Feb 2014 22:47:00 +0530 Subject: [PATCH 1/2] rfe-1403 : Support for export only triggers/stored procedures Signed-off-by: Chanaka Indrajith --- ChangeLog | 1 + export.php | 1 + libraries/config.default.php | 7 +++ libraries/config/messages.inc.php | 1 + libraries/config/setup.forms.php | 1 + libraries/config/user_preferences.forms.php | 1 + libraries/export.lib.php | 56 +++++++++++++++---- libraries/plugins/export/ExportSql.class.php | 9 +++ .../plugin/export/PMA_ExportSql_test.php | 9 ++- 9 files changed, 73 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 954b761290..986a752d03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.2.0.0 (not yet released) ++ rfe #1403 Export only triggers + rfe #1483 Export Server/Database/Table without triggers + rfe #1662 Add table comment tool tip in database structure page + rfe #1447 Single table for display Character Sets and Collations diff --git a/export.php b/export.php index 37edf065cd..d39372b474 100644 --- a/export.php +++ b/export.php @@ -109,6 +109,7 @@ if (!defined('TESTSUITE')) { 'sql_drop_table', 'sql_procedure_function', 'sql_create_table_statements', + 'sql_create_table', 'sql_create_trigger', 'sql_if_not_exists', 'sql_auto_increment', diff --git a/libraries/config.default.php b/libraries/config.default.php index ae91b42a72..3be563241c 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -1820,6 +1820,13 @@ $cfg['Export']['sql_if_not_exists'] = true; */ $cfg['Export']['sql_procedure_function'] = true; +/** + * + * + * @global boolean $cfg['Export']['sql_create_table'] + */ +$cfg['Export']['sql_create_table'] = true; + /** * * diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 45c8a89485..2933000593 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -171,6 +171,7 @@ $strConfigExport_sql_views_as_tables_name = __('Export views as tables'); $strConfigExport_sql_drop_database_name = sprintf(__('Add %s'), 'DROP DATABASE'); $strConfigExport_sql_drop_table_name = sprintf(__('Add %s'), 'DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER'); +$strConfigExport_sql_create_table_name = sprintf(__('Add %s'), 'CREATE TABLE'); $strConfigExport_sql_create_trigger_name = sprintf(__('Add %s'), 'CREATE TRIGGER'); $strConfigExport_sql_hex_for_blob_name = __('Use hexadecimal for BLOB'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 545cdc1412..bfc3a2e6df 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -301,6 +301,7 @@ $forms['Export']['Sql'] = array('Export' => array( ':group:' . __('Structure'), 'sql_drop_table', 'sql_procedure_function', + 'sql_create_table', 'sql_create_trigger', 'sql_create_table_statements' => ':group', 'sql_if_not_exists', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 4c088fd7f6..2bb9dc3fb0 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -200,6 +200,7 @@ $forms['Export']['Sql'] = array( ':group:' . __('Structure'), 'Export/sql_drop_table', 'Export/sql_procedure_function', + 'Export/sql_create_table', 'Export/sql_create_trigger', 'Export/sql_create_table_statements' => ':group', 'Export/sql_if_not_exists', diff --git a/libraries/export.lib.php b/libraries/export.lib.php index 5f8d733a98..22fe70a053 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -532,13 +532,29 @@ function PMA_exportDatabase( ) { // for a view, export a stand-in definition of the table // to resolve view dependencies - if (! $export_plugin->exportStructure( - $db, $table, $crlf, $err_url, - $is_view ? 'stand_in' : 'create_table', $export_type, - $do_relation, $do_comments, $do_mime, $do_dates - )) { - break 1; + + if ($is_view) { + + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'stand_in', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + break 1; + } + + } else if (isset($GLOBALS['sql_create_table'])) { + + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'create_table', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + break 1; + } + } + } // if this is a view or a merge table, don't export data if (($whatStrucOrData == 'data' @@ -632,13 +648,29 @@ function PMA_exportTable( if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data' ) { - if (! $export_plugin->exportStructure( - $db, $table, $crlf, $err_url, - $is_view ? 'create_view' : 'create_table', $export_type, - $do_relation, $do_comments, $do_mime, $do_dates - )) { - return; + + if ($is_view) { + + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'create_view', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + return; + } + + } else if (isset($GLOBALS['sql_create_table'])) { + + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'create_table', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + return; + } + } + } // If this is an export of a single view, we have to export data; // for example, a PDF report diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 584ff520c1..0837267c5c 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -259,6 +259,15 @@ class ExportSql extends ExportPlugin $leaf->setName('drop_table'); $leaf->setText(sprintf(__('Add %s statement'), $drop_clause)); $subgroup->addProperty($leaf); + + // Add table structure option + $leaf = new BoolPropertyItem(); + $leaf->setName('create_table'); + $leaf->setText( + sprintf(__('Add %s statement'), 'CREATE TABLE') + ); + $subgroup->addProperty($leaf); + // Drizzle doesn't support procedures and functions if (! PMA_DRIZZLE) { $leaf = new BoolPropertyItem(); diff --git a/test/classes/plugin/export/PMA_ExportSql_test.php b/test/classes/plugin/export/PMA_ExportSql_test.php index fdcc67c026..f5e28946bf 100644 --- a/test/classes/plugin/export/PMA_ExportSql_test.php +++ b/test/classes/plugin/export/PMA_ExportSql_test.php @@ -265,6 +265,12 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase ' / EVENT / TRIGGER statement', $leaf->getText() ); + + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); $leaf = array_shift($leaves); $this->assertInstanceOf( @@ -405,7 +411,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $properties = $properties[0]->getProperties(); $this->assertCount( - 4, + 5, $properties ); @@ -747,6 +753,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $GLOBALS['sql_drop_database'] = true; $GLOBALS['sql_backquotes'] = true; $GLOBALS['sql_create_database'] = true; + $GLOBALS['sql_create_table'] = true; $GLOBALS['crlf'] = "\n"; $dbi = $this->getMockBuilder('PMA_DatabaseInterface') From 4457f40ef42ba4bd7bc30aa4c012f96238d71616 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Thu, 6 Feb 2014 23:03:04 +0530 Subject: [PATCH 2/2] Support for export server/db/table without views Signed-off-by: Chanaka Indrajith --- export.php | 1 + libraries/config.default.php | 7 +++ libraries/config/messages.inc.php | 1 + libraries/config/setup.forms.php | 1 + libraries/config/user_preferences.forms.php | 1 + libraries/export.lib.php | 55 +++++++++++-------- libraries/plugins/export/ExportSql.class.php | 8 +++ .../plugin/export/PMA_ExportSql_test.php | 9 ++- 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/export.php b/export.php index d39372b474..8fb1d2d846 100644 --- a/export.php +++ b/export.php @@ -110,6 +110,7 @@ if (!defined('TESTSUITE')) { 'sql_procedure_function', 'sql_create_table_statements', 'sql_create_table', + 'sql_create_view', 'sql_create_trigger', 'sql_if_not_exists', 'sql_auto_increment', diff --git a/libraries/config.default.php b/libraries/config.default.php index 3be563241c..a4694bf9e8 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -1827,6 +1827,13 @@ $cfg['Export']['sql_procedure_function'] = true; */ $cfg['Export']['sql_create_table'] = true; +/** + * + * + * @global boolean $cfg['Export']['sql_create_view'] + */ +$cfg['Export']['sql_create_view'] = true; + /** * * diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 2933000593..26257a75e3 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -172,6 +172,7 @@ $strConfigExport_sql_drop_database_name = sprintf(__('Add %s'), 'DROP DATABASE') $strConfigExport_sql_drop_table_name = sprintf(__('Add %s'), 'DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER'); $strConfigExport_sql_create_table_name = sprintf(__('Add %s'), 'CREATE TABLE'); +$strConfigExport_sql_create_view_name = sprintf(__('Add %s'), 'CREATE VIEW'); $strConfigExport_sql_create_trigger_name = sprintf(__('Add %s'), 'CREATE TRIGGER'); $strConfigExport_sql_hex_for_blob_name = __('Use hexadecimal for BLOB'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index bfc3a2e6df..611c1480b8 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -302,6 +302,7 @@ $forms['Export']['Sql'] = array('Export' => array( 'sql_drop_table', 'sql_procedure_function', 'sql_create_table', + 'sql_create_view', 'sql_create_trigger', 'sql_create_table_statements' => ':group', 'sql_if_not_exists', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 2bb9dc3fb0..b66e9f434a 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -201,6 +201,7 @@ $forms['Export']['Sql'] = array( 'Export/sql_drop_table', 'Export/sql_procedure_function', 'Export/sql_create_table', + 'Export/sql_create_view', 'Export/sql_create_trigger', 'Export/sql_create_table_statements' => ':group', 'Export/sql_if_not_exists', diff --git a/libraries/export.lib.php b/libraries/export.lib.php index 22fe70a053..1ae7834a6f 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -535,12 +535,14 @@ function PMA_exportDatabase( if ($is_view) { - if (! $export_plugin->exportStructure( - $db, $table, $crlf, $err_url, - 'stand_in', $export_type, - $do_relation, $do_comments, $do_mime, $do_dates - )) { - break 1; + if (isset($GLOBALS['sql_create_view'])) { + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'stand_in', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + break 1; + } } } else if (isset($GLOBALS['sql_create_table'])) { @@ -583,19 +585,24 @@ function PMA_exportDatabase( } } } - foreach ($views as $view) { - // no data export for a view - if ($whatStrucOrData == 'structure' - || $whatStrucOrData == 'structure_and_data' - ) { - if (! $export_plugin->exportStructure( - $db, $view, $crlf, $err_url, - 'create_view', $export_type, - $do_relation, $do_comments, $do_mime, $do_dates - )) { - break 1; + + if (isset($GLOBALS['sql_create_view'])) { + + foreach ($views as $view) { + // no data export for a view + if ($whatStrucOrData == 'structure' + || $whatStrucOrData == 'structure_and_data' + ) { + if (! $export_plugin->exportStructure( + $db, $view, $crlf, $err_url, + 'create_view', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + break 1; + } } } + } if (! $export_plugin->exportDBFooter($db)) { @@ -651,12 +658,14 @@ function PMA_exportTable( if ($is_view) { - if (! $export_plugin->exportStructure( - $db, $table, $crlf, $err_url, - 'create_view', $export_type, - $do_relation, $do_comments, $do_mime, $do_dates - )) { - return; + if (isset($GLOBALS['sql_create_view'])) { + if (! $export_plugin->exportStructure( + $db, $table, $crlf, $err_url, + 'create_view', $export_type, + $do_relation, $do_comments, $do_mime, $do_dates + )) { + return; + } } } else if (isset($GLOBALS['sql_create_table'])) { diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 0837267c5c..3a6f335680 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -268,6 +268,14 @@ class ExportSql extends ExportPlugin ); $subgroup->addProperty($leaf); + // Add view option + $leaf = new BoolPropertyItem(); + $leaf->setName('create_view'); + $leaf->setText( + sprintf(__('Add %s statement'), 'CREATE VIEW') + ); + $subgroup->addProperty($leaf); + // Drizzle doesn't support procedures and functions if (! PMA_DRIZZLE) { $leaf = new BoolPropertyItem(); diff --git a/test/classes/plugin/export/PMA_ExportSql_test.php b/test/classes/plugin/export/PMA_ExportSql_test.php index f5e28946bf..749d781483 100644 --- a/test/classes/plugin/export/PMA_ExportSql_test.php +++ b/test/classes/plugin/export/PMA_ExportSql_test.php @@ -272,6 +272,12 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $leaf ); + $leaf = array_shift($leaves); + $this->assertInstanceOf( + 'BoolPropertyItem', + $leaf + ); + $leaf = array_shift($leaves); $this->assertInstanceOf( 'BoolPropertyItem', @@ -411,7 +417,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $properties = $properties[0]->getProperties(); $this->assertCount( - 5, + 6, $properties ); @@ -754,6 +760,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $GLOBALS['sql_backquotes'] = true; $GLOBALS['sql_create_database'] = true; $GLOBALS['sql_create_table'] = true; + $GLOBALS['sql_create_view'] = true; $GLOBALS['crlf'] = "\n"; $dbi = $this->getMockBuilder('PMA_DatabaseInterface')