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

Fix: #14926
See: #14916
Signed-off-by: Nitish Bahl <nitishbahl24@gmail.com>
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
Nitish Bahl 2019-02-09 20:36:10 +05:30 committed by William Desportes
parent 537a00730a
commit 2b0a36eb21
5 changed files with 48 additions and 47 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

@ -53,7 +53,17 @@
<td class="insert_table center print_ignore">
<a href="tbl_change.php{{ tbl_url_query|raw }}">{{ titles['Insert']|raw }}</a>
</td>
<td class="center print_ignore">{{ empty_table|raw }}</td>
{% if table_is_view %}
<td class="center print_ignore">
<a href="view_create.php{{- Url_getCommon({
'db': db,
'table': current_table['TABLE_NAME']
}) }}">{{ titles['Edit']|raw }}</a>
</td>
{% endif %}
{% if empty_table is not empty %}
<td class="center print_ignore">{{ empty_table|raw }}</td>
{% endif %}
<td class="center print_ignore">
<a class="ajax drop_table_anchor
{{- table_is_view or current_table['ENGINE'] == null ? ' view' }}"

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']);
}