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 79142b4703..cd2cc0b00c 100644 --- a/export.php +++ b/export.php @@ -109,6 +109,8 @@ if (!defined('TESTSUITE')) { 'sql_drop_table', '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 ae91b42a72..a4694bf9e8 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -1820,6 +1820,20 @@ $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; + +/** + * + * + * @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 45c8a89485..26257a75e3 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -171,6 +171,8 @@ $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_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 545cdc1412..611c1480b8 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -301,6 +301,8 @@ $forms['Export']['Sql'] = array('Export' => array( ':group:' . __('Structure'), '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 4c088fd7f6..b66e9f434a 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -200,6 +200,8 @@ $forms['Export']['Sql'] = array( ':group:' . __('Structure'), '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 5f8d733a98..1ae7834a6f 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -532,13 +532,31 @@ 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 (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'])) { + + 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' @@ -567,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)) { @@ -632,13 +655,31 @@ 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 (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'])) { + + 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 2495e16db3..519f14667e 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -259,6 +259,23 @@ 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); + + // 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 fdcc67c026..749d781483 100644 --- a/test/classes/plugin/export/PMA_ExportSql_test.php +++ b/test/classes/plugin/export/PMA_ExportSql_test.php @@ -265,6 +265,18 @@ 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( + 'BoolPropertyItem', + $leaf + ); $leaf = array_shift($leaves); $this->assertInstanceOf( @@ -405,7 +417,7 @@ class PMA_ExportSql_Test extends PHPUnit_Framework_TestCase $properties = $properties[0]->getProperties(); $this->assertCount( - 4, + 6, $properties ); @@ -747,6 +759,8 @@ 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['sql_create_view'] = true; $GLOBALS['crlf'] = "\n"; $dbi = $this->getMockBuilder('PMA_DatabaseInterface')