Fix #14916 - Filling existing fields form while editing a view

Fixes: #14916
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2019-03-25 22:44:54 +01:00
commit cd79a5f822
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 37 additions and 46 deletions

View File

@ -566,7 +566,7 @@ class DatabaseStructureController extends DatabaseController
$empty_table = '';
if (!$this->_db_is_system_schema) {
$empty_table = '&nbsp;';
$empty_table = '';
if (!$table_is_view) {
$empty_table = Template::get('database/structure/empty_table')
->render(

View File

@ -1220,52 +1220,11 @@ class TableStructureController extends TableController
'DistinctValues' => Util::getIcon('b_browse', __('Distinct values')),
);
/**
* Work on the table
*/
$edit_view_url = '';
if ($this->_tbl_is_view && ! $this->_db_is_system_schema) {
$item = $this->dbi->fetchSingleRow(
sprintf(
"SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`,
`SECURITY_TYPE`
FROM `INFORMATION_SCHEMA`.`VIEWS`
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s';",
$GLOBALS['dbi']->escapeString($this->db),
$GLOBALS['dbi']->escapeString($this->table)
)
$edit_view_url = Url::getCommon(
array('db' => $this->db, 'table' => $this->table)
);
$createView = $this->dbi->getTable($this->db, $this->table)
->showCreate();
// get algorithm from $createView of the form
// CREATE ALGORITHM=<ALGORITHM> DE...
$parts = explode(" ", substr($createView, 17));
$item['ALGORITHM'] = $parts[0];
$view = array(
'operation' => 'alter',
'definer' => $item['DEFINER'],
'sql_security' => $item['SECURITY_TYPE'],
'name' => $this->table,
'as' => $item['VIEW_DEFINITION'],
'with' => $item['CHECK_OPTION'],
'algorithm' => $item['ALGORITHM'],
);
$edit_view_url = 'view_create.php'
. Url::getCommon($url_params) . '&amp;'
. implode(
'&amp;',
array_map(
function ($key, $val) {
return 'view[' . urlencode($key) . ']=' . urlencode(
$val
);
},
array_keys($view), $view
)
);
}
/**
@ -1299,7 +1258,7 @@ class TableStructureController extends TableController
'tbl_storage_engine' => $this->_tbl_storage_engine,
'primary' => $primary_index,
'columns_with_unique_index' => $columns_with_unique_index,
'edit_view_url' => isset($edit_view_url) ? $edit_view_url : null,
'edit_view_url' => $edit_view_url,
'columns_list' => $columns_list,
'table_stats' => isset($tablestats) ? $tablestats : null,
'fields' => $fields,

View File

@ -133,6 +133,7 @@
{# Work on the table #}
<div id="structure-action-links">
{% if tbl_is_view and not db_is_system_schema %}
{% set edit_view_url = 'view_create.php' ~ edit_view_url %}
{{ Util_linkOrButton(
edit_view_url,
Util_getIcon('b_edit', 'Edit view'|trans, true)

View File

@ -183,8 +183,39 @@ $view = array(
'column_names' => '',
'as' => $sql_query,
'with' => '',
'algorithm' => '',
);
// Used to prefill the fields when editing a view
if (isset($_GET['db']) && isset($_GET['table'])) {
$item = $GLOBALS['dbi']->fetchSingleRow(
sprintf(
"SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`,
`SECURITY_TYPE`
FROM `INFORMATION_SCHEMA`.`VIEWS`
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s';",
$GLOBALS['dbi']->escapeString($_GET['db']),
$GLOBALS['dbi']->escapeString($_GET['table'])
)
);
$createView = $GLOBALS['dbi']->getTable($_GET['db'], $_GET['table'])
->showCreate();
// CREATE ALGORITHM=<ALGORITHM> DE...
$parts = explode(" ", substr($createView, 17));
$item['ALGORITHM'] = $parts[0];
$view['operation'] = 'alter';
$view['definer'] = $item['DEFINER'];
$view['sql_security'] = $item['SECURITY_TYPE'];
$view['name'] = $_GET['table'];
$view['as'] = $item['VIEW_DEFINITION'];
$view['with'] = $item['CHECK_OPTION'];
$view['algorithm'] = $item['ALGORITHM'];
}
if (Core::isValid($_POST['view'], 'array')) {
$view = array_merge($view, $_POST['view']);
}