Skip to content

Commit

Permalink
Merge #15416 - Fix #14815 - Allow simplifying exported view syntax to…
Browse files Browse the repository at this point in the history
… only "CREATE VIEW"

Merge #15416
Fixes: #14815

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed May 1, 2020
2 parents 1481534 + 7e685bf commit a09a63f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions libraries/classes/Controllers/ExportController.php
Expand Up @@ -169,6 +169,7 @@ public function index(): void
'sql_create_view',
'sql_create_trigger',
'sql_view_current_user',
'sql_simple_view_export',
'sql_if_not_exists',
'sql_or_replace_view',
'sql_auto_increment',
Expand Down
30 changes: 25 additions & 5 deletions libraries/classes/Plugins/Export/ExportSql.php
Expand Up @@ -20,6 +20,7 @@
use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
use PhpMyAdmin\SqlParser\Components\CreateDefinition;
use PhpMyAdmin\SqlParser\Components\OptionsArray;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
Expand Down Expand Up @@ -330,6 +331,13 @@ protected function setProperties()
);
$subgroup_create_view->setSubgroupHeader($leaf);

$leaf = new BoolPropertyItem(
"simple_view_export",
/* l10n: Allow simplifying exported view syntax to only "CREATE VIEW" */
__('Use simple view export')
);
$subgroup_create_view->addProperty($leaf);

$leaf = new BoolPropertyItem(
'view_current_user',
__('Exclude definition of current user')
Expand Down Expand Up @@ -1569,21 +1577,33 @@ public function getTableDef(
* statement.
*/
if ($view) {
//TODO: use parser
$create_query = preg_replace(
'/' . preg_quote(Util::backquote($db), '/') . '\./',
'',
$create_query
);
$parser = new Parser($create_query);
/**
* `CREATE TABLE` statement.
*
* @var CreateStatement
*/
$statement = $parser->statements[0];

// exclude definition of current user
if (isset($GLOBALS['sql_view_current_user'])) {
$create_query = preg_replace(
'/(^|\s)DEFINER=([\S]+)/',
'',
$create_query
);
$statement->options->remove('DEFINER');
}

if (isset($GLOBALS['sql_simple_view_export'])) {
$statement->options->remove('SQL SECURITY');
$statement->options->remove('INVOKER');
$statement->options->remove('ALGORITHM');
$statement->options->remove('DEFINER');
}
$create_query = $statement->build();

// whether to replace existing view or not
if (isset($GLOBALS['sql_or_replace_view'])) {
$create_query = preg_replace(
Expand Down

0 comments on commit a09a63f

Please sign in to comment.