From e5fb032ff7ea77e305ed9df270d0a5645bc167f6 Mon Sep 17 00:00:00 2001 From: Aswani Prakash Date: Tue, 3 Jul 2018 13:23:48 +0530 Subject: [PATCH 1/2] Drop view and or replace added to exporting view #14404 Signed-off-by: Aswani Prakash --- export.php | 1 + libraries/classes/Config/Descriptions.php | 1 + .../classes/Config/Forms/User/ExportForm.php | 1 + .../classes/Plugins/Export/ExportSql.php | 25 +++++++++++++++++++ libraries/config.default.php | 7 +++--- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/export.php b/export.php index 3a2bd6eea8..d002b6b46e 100644 --- a/export.php +++ b/export.php @@ -139,6 +139,7 @@ $post_params = [ 'sql_create_trigger', 'sql_view_current_user', 'sql_if_not_exists', + 'sql_or_replace_view', 'sql_auto_increment', 'sql_backquotes', 'sql_truncate', diff --git a/libraries/classes/Config/Descriptions.php b/libraries/classes/Config/Descriptions.php index 9aa6d7af20..c119cf61dd 100644 --- a/libraries/classes/Config/Descriptions.php +++ b/libraries/classes/Config/Descriptions.php @@ -253,6 +253,7 @@ class Descriptions . ' table creation)' ), 'Export_sql_view_current_user' => __('Exclude definition of current user'), + 'Export_sql_or_replace_view_name' => sprintf(__('%s view'), 'OR REPLACE'), 'Export_sql_ignore_name' => __('Use ignore inserts'), 'Export_sql_include_comments_name' => __('Comments'), 'Export_sql_insert_syntax_name' => __('Syntax to use when inserting data'), diff --git a/libraries/classes/Config/Forms/User/ExportForm.php b/libraries/classes/Config/Forms/User/ExportForm.php index 6102e8c4c0..8eb04a3a52 100644 --- a/libraries/classes/Config/Forms/User/ExportForm.php +++ b/libraries/classes/Config/Forms/User/ExportForm.php @@ -65,6 +65,7 @@ class ExportForm extends BaseForm ':group:end', 'Export/sql_create_view' => ':group', 'Export/sql_view_current_user', + 'Export/sql_or_replace_view', ':group:end', 'Export/sql_procedure_function', 'Export/sql_create_trigger', diff --git a/libraries/classes/Plugins/Export/ExportSql.php b/libraries/classes/Plugins/Export/ExportSql.php index 8927df796e..98efc1bc3a 100644 --- a/libraries/classes/Plugins/Export/ExportSql.php +++ b/libraries/classes/Plugins/Export/ExportSql.php @@ -311,11 +311,19 @@ class ExportSql extends ExportPlugin sprintf(__('Add %s statement'), 'CREATE VIEW') ); $subgroup_create_view->setSubgroupHeader($leaf); + $leaf = new BoolPropertyItem( 'view_current_user', __('Exclude definition of current user') ); $subgroup_create_view->addProperty($leaf); + + $leaf = new BoolPropertyItem( + 'or_replace_view', + sprintf(__('%s view'), 'OR REPLACE') + ); + $subgroup_create_view->addProperty($leaf); + $subgroup->addProperty($subgroup_create_view); $leaf = new BoolPropertyItem( @@ -1469,6 +1477,14 @@ class ExportSql extends ExportPlugin $schema_create .= $new_crlf; + if (!empty($sql_drop_table) + && $GLOBALS['dbi']->getTable($db, $table)->isView() + ) { + $schema_create .= 'DROP VIEW IF EXISTS ' + . Util::backquote($table_alias, $sql_backquotes) . ';' + . $crlf; + } + // no need to generate a DROP VIEW here, it was done earlier if (!empty($sql_drop_table) && !$GLOBALS['dbi']->getTable($db, $table)->isView() @@ -1551,6 +1567,15 @@ class ExportSql extends ExportPlugin $create_query ); } + + // whether to replace existing view or not + if ($GLOBALS['sql_or_replace_view']) { + $create_query = preg_replace( + '/^CREATE/', + 'CREATE OR REPLACE', + $create_query + ); + } } // Substitute aliases in `CREATE` query. diff --git a/libraries/config.default.php b/libraries/config.default.php index 9876f9c664..c84ad3c3bc 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -1959,13 +1959,14 @@ $cfg['Export']['sql_drop_table'] = false; $cfg['Export']['sql_if_not_exists'] = false; /** - * - * - * * @global boolean $cfg['Export']['sql_view_current_user'] */ $cfg['Export']['sql_view_current_user'] = false; +/** + * @global boolean $cfg['Export']['sql_or_replace'] + */ +$cfg['Export']['sql_or_replace_view'] = false; /** * From 4d9e5724a4349b0f3dac20c6d996328ff52d4a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 29 Oct 2018 20:23:43 -0300 Subject: [PATCH 2/2] Add ChangeLog entry for #14404 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix tests Signed-off-by: MaurĂ­cio Meneghini Fauth --- ChangeLog | 1 + test/classes/Plugins/Export/ExportSqlTest.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 72a9d46b0d..d2e4ccb80d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog - issue #14330 New features for csv import plugin - issue #14417 Automatically add index while editing an existing row and setting auto increment - issue #13057 Add export option to drop user security definers from views +- issue #14404 Drop view and or replace added to exporting view 4.8.4 (not yet released) - issue #14452 Remove hash param in edit query URL diff --git a/test/classes/Plugins/Export/ExportSqlTest.php b/test/classes/Plugins/Export/ExportSqlTest.php index e80af3034e..ce40948b95 100644 --- a/test/classes/Plugins/Export/ExportSqlTest.php +++ b/test/classes/Plugins/Export/ExportSqlTest.php @@ -283,7 +283,7 @@ class ExportSqlTest extends PmaTestCase ); $this->assertCount( - 1, + 2, $leaf->getProperties() ); @@ -1025,7 +1025,7 @@ class ExportSqlTest extends PmaTestCase ] ) ); - $dbi->expects($this->once()) + $dbi->expects($this->exactly(2)) ->method('getTable') ->will($this->returnValue(new Table('table', 'db', $dbi))); $dbi->expects($this->any())->method('escapeString') @@ -1180,7 +1180,7 @@ class ExportSqlTest extends PmaTestCase ->method('getError') ->will($this->returnValue('error occurred')); - $dbi->expects($this->once()) + $dbi->expects($this->exactly(2)) ->method('getTable') ->will($this->returnValue(new Table('table', 'db', $dbi))); $dbi->expects($this->any())