Allow removing DEFINER clause from exported SQL
Signed-off-by: Erol Guven <erol.guven@appian.com>
This commit is contained in:
parent
b565ec3564
commit
b20111d63b
@ -2729,6 +2729,15 @@ Export and import settings
|
||||
|
||||
.. seealso:: :ref:`faq6_27`
|
||||
|
||||
.. config:option:: $cfg['Export']['remove_definer_from_definitions']
|
||||
|
||||
:type: boolean
|
||||
:default: false
|
||||
|
||||
Remove DEFINER clause from the event, view and routine definitions.
|
||||
|
||||
.. versionadded:: 5.2.0
|
||||
|
||||
.. config:option:: $cfg['Import']
|
||||
|
||||
:type: array
|
||||
|
||||
@ -703,6 +703,7 @@ class Descriptions
|
||||
'Export_quick_export_onserver_name' => __('Save on server'),
|
||||
'Export_quick_export_onserver_overwrite_name' => __('Overwrite existing file(s)'),
|
||||
'Export_remember_file_template_name' => __('Remember filename template'),
|
||||
'Export_remove_definer_from_definitions_name' => __('Remove DEFINER clause from definitions'),
|
||||
'Export_sql_auto_increment_name' => __('Add AUTO_INCREMENT value'),
|
||||
'Export_sql_backquotes_name' => __('Enclose table and column names with backquotes'),
|
||||
'Export_sql_compatibility_name' => __('SQL compatibility mode'),
|
||||
|
||||
@ -469,6 +469,9 @@ final class Export
|
||||
*/
|
||||
public $yaml_structure_or_data;
|
||||
|
||||
/** @var bool */
|
||||
public $remove_definer_from_definitions;
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed> $export
|
||||
*/
|
||||
@ -582,6 +585,7 @@ final class Export
|
||||
$this->xml_export_views = $this->setXmlExportViews($export);
|
||||
$this->xml_export_contents = $this->setXmlExportContents($export);
|
||||
$this->yaml_structure_or_data = $this->setYamlStructureOrData($export);
|
||||
$this->remove_definer_from_definitions = $this->setRemoveDefinerClause($export);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2008,4 +2012,16 @@ final class Export
|
||||
|
||||
return $export['yaml_structure_or_data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string, mixed> $export
|
||||
*/
|
||||
private function setRemoveDefinerClause(array $export): bool
|
||||
{
|
||||
if (! isset($export['remove_definer_from_definitions'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $export['remove_definer_from_definitions'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,7 +538,7 @@ class ExportSql extends ExportPlugin
|
||||
array $routines,
|
||||
$delimiter
|
||||
) {
|
||||
global $crlf, $dbi;
|
||||
global $crlf, $cfg, $dbi;
|
||||
|
||||
$text = $this->exportComment()
|
||||
. $this->exportComment($name)
|
||||
@ -561,6 +561,13 @@ class ExportSql extends ExportPlugin
|
||||
'',
|
||||
$flag
|
||||
);
|
||||
if (! empty($createQuery) && $cfg['Export']['remove_definer_from_definitions']) {
|
||||
// Remove definer clause from routine definitions
|
||||
$parser = new Parser($createQuery);
|
||||
$statement = $parser->statements[0];
|
||||
$statement->options->remove('DEFINER');
|
||||
$createQuery = $statement->build();
|
||||
}
|
||||
// One warning per database
|
||||
if ($flag) {
|
||||
$usedAlias = true;
|
||||
@ -987,7 +994,7 @@ class ExportSql extends ExportPlugin
|
||||
*/
|
||||
public function exportEvents($db): bool
|
||||
{
|
||||
global $crlf, $dbi;
|
||||
global $crlf, $cfg, $dbi;
|
||||
|
||||
$text = '';
|
||||
$delimiter = '$$';
|
||||
@ -1013,8 +1020,15 @@ class ExportSql extends ExportPlugin
|
||||
. $delimiter . $crlf;
|
||||
}
|
||||
|
||||
$text .= $dbi->getDefinition($db, 'EVENT', $eventName)
|
||||
. $delimiter . $crlf . $crlf;
|
||||
$eventDef = $dbi->getDefinition($db, 'EVENT', $eventName);
|
||||
if (! empty($eventDef) && $cfg['Export']['remove_definer_from_definitions']) {
|
||||
// remove definer clause from the event definition
|
||||
$parser = new Parser($eventDef);
|
||||
$statement = $parser->statements[0];
|
||||
$statement->options->remove('DEFINER');
|
||||
$eventDef = $statement->build();
|
||||
}
|
||||
$text .= $eventDef . $delimiter . $crlf . $crlf;
|
||||
}
|
||||
|
||||
$text .= 'DELIMITER ;' . $crlf;
|
||||
@ -1414,7 +1428,7 @@ class ExportSql extends ExportPlugin
|
||||
) {
|
||||
global $sql_drop_table, $sql_backquotes, $sql_constraints,
|
||||
$sql_constraints_query, $sql_indexes, $sql_indexes_query,
|
||||
$sql_auto_increments, $sql_drop_foreign_keys, $dbi;
|
||||
$sql_auto_increments, $sql_drop_foreign_keys, $dbi, $cfg;
|
||||
|
||||
$dbAlias = $db;
|
||||
$tableAlias = $table;
|
||||
@ -1566,7 +1580,7 @@ class ExportSql extends ExportPlugin
|
||||
$statement = $parser->statements[0];
|
||||
|
||||
// exclude definition of current user
|
||||
if (isset($GLOBALS['sql_view_current_user'])) {
|
||||
if ($cfg['Export']['remove_definer_from_definitions'] || isset($GLOBALS['sql_view_current_user'])) {
|
||||
$statement->options->remove('DEFINER');
|
||||
}
|
||||
|
||||
|
||||
@ -1856,6 +1856,11 @@ $cfg['Export']['json_pretty_print'] = false;
|
||||
*/
|
||||
$cfg['Export']['json_unicode'] = true;
|
||||
|
||||
/**
|
||||
* @global string $cfg['Export']['remove_definer_from_definitions']
|
||||
*/
|
||||
$cfg['Export']['remove_definer_from_definitions'] = false;
|
||||
|
||||
/**
|
||||
* @global string $cfg['Export']['sql_structure_or_data']
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user