Skip to content

Commit

Permalink
Merge pull request #892 from Chanaka/rfe-1403
Browse files Browse the repository at this point in the history
rfe-1403 : Support for export only triggers/stored procedures
  • Loading branch information
lem9 committed Feb 7, 2014
2 parents 723bd66 + 4457f40 commit cd998a4
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 24 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions export.php
Expand Up @@ -109,6 +109,8 @@
'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',
Expand Down
14 changes: 14 additions & 0 deletions libraries/config.default.php
Expand Up @@ -1820,6 +1820,20 @@
*/
$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;

/**
*
*
Expand Down
2 changes: 2 additions & 0 deletions libraries/config/messages.inc.php
Expand Up @@ -171,6 +171,8 @@
$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');
Expand Down
2 changes: 2 additions & 0 deletions libraries/config/setup.forms.php
Expand Up @@ -301,6 +301,8 @@
':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',
Expand Down
2 changes: 2 additions & 0 deletions libraries/config/user_preferences.forms.php
Expand Up @@ -200,6 +200,8 @@
':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',
Expand Down
87 changes: 64 additions & 23 deletions libraries/export.lib.php
Expand Up @@ -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'
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions libraries/plugins/export/ExportSql.class.php
Expand Up @@ -259,6 +259,23 @@ protected function setProperties()
$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'), '<code>CREATE TABLE</code>')
);
$subgroup->addProperty($leaf);

// Add view option
$leaf = new BoolPropertyItem();
$leaf->setName('create_view');
$leaf->setText(
sprintf(__('Add %s statement'), '<code>CREATE VIEW</code>')
);
$subgroup->addProperty($leaf);

// Drizzle doesn't support procedures and functions
if (! PMA_DRIZZLE) {
$leaf = new BoolPropertyItem();
Expand Down
16 changes: 15 additions & 1 deletion test/classes/plugin/export/PMA_ExportSql_test.php
Expand Up @@ -265,6 +265,18 @@ public function testSetProperties()
'<code> / EVENT</code><code> / TRIGGER</code> 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(
Expand Down Expand Up @@ -405,7 +417,7 @@ public function testSetPropertiesWithDrizzle()
$properties = $properties[0]->getProperties();

$this->assertCount(
4,
6,
$properties
);

Expand Down Expand Up @@ -747,6 +759,8 @@ public function testExportDBCreate()
$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')
Expand Down

0 comments on commit cd998a4

Please sign in to comment.