Merge #16349 - Fix #12961 - Indexes shown at both tbl_structure and tbl_relation

Pull-request: #16349
Fixes: #12961

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2020-09-20 23:18:00 +02:00
commit 7901363931
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 20 additions and 128 deletions

View File

@ -172,7 +172,6 @@ final class RelationController extends AbstractController
// common form
$engine = $this->dbi->getTable($this->db, $this->table)->getStorageEngine();
$foreignKeySupported = Util::isForeignKeySupported($storageEngine);
$this->render('table/relation/common_form', [
'is_foreign_key_supported' => Util::isForeignKeySupported($engine),
'db' => $this->db,
@ -191,9 +190,6 @@ final class RelationController extends AbstractController
'databases' => $GLOBALS['dblist']->databases,
'dbi' => $this->dbi,
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
'foreignKeySupported' => $foreignKeySupported,
'indexes' => $foreignKeySupported ? Index::getFromTable($this->table, $this->db) : null,
'indexes_duplicates' => $foreignKeySupported ? Index::findDuplicates($this->table, $this->db) : null,
'route' => $route,
]);
}

View File

@ -216,109 +216,4 @@
</fieldset>
</form>
{% if foreignKeySupported %}
<div id="index_div" class="w-100 ajax">
<fieldset class="index_info">
<legend id="index_header">
{% trans 'Indexes' %}
{{ show_mysql_docu('optimizing-database-structure') }}
</legend>
{% if indexes is not empty %}
{{ indexes_duplicates|raw }}
<div class="responsivetable jsresponsive">
<table id="table_index">
<thead>
<tr>
<th colspan="2" class="print_ignore">{% trans 'Action' %}</th>
<th>{% trans 'Keyname' %}</th>
<th>{% trans 'Type' %}</th>
<th>{% trans 'Unique' %}</th>
<th>{% trans 'Packed' %}</th>
<th>{% trans 'Column' %}</th>
<th>{% trans 'Cardinality' %}</th>
<th>{% trans 'Collation' %}</th>
<th>{% trans 'Null' %}</th>
<th>{% trans 'Comment' %}</th>
</tr>
</thead>
{% for index in indexes %}
<tbody class="row_span">
{% set columns_count = index.getColumnCount() %}
<tr class="noclick">
<td rowspan="{{ columns_count }}" class="edit_index print_ignore ajax">
<a class="ajax" href="{{ url('/table/indexes') }}" data-post="{{ get_common(url_params|merge({'index': index.getName()}), '') }}">
{{ get_icon('b_edit', 'Edit'|trans) }}
</a>
</td>
<td rowspan="{{ columns_count }}" class="print_ignore">
{% if index.getName() == 'PRIMARY' %}
{% set index_params = {
'sql_query': 'ALTER TABLE ' ~ backquote(table) ~ ' DROP PRIMARY KEY;',
'message_to_show': 'The primary key has been dropped.'|trans
} %}
{% else %}
{% set index_params = {
'sql_query': 'ALTER TABLE ' ~ backquote(table) ~ ' DROP INDEX ' ~ backquote(index.getName()) ~ ';',
'message_to_show': 'Index %s has been dropped.'|trans|format(index.getName())
} %}
{% endif %}
<input type="hidden" class="drop_primary_key_index_msg" value="{{ index_params.sql_query|js_format(false) }}">
{{ link_or_button(
url('/sql', url_params|merge(index_params)),
get_icon('b_drop', 'Drop'|trans),
{'class': 'drop_primary_key_index_anchor ajax'}
) }}
</td>
<th rowspan="{{ columns_count }}">{{ index.getName() }}</th>
<td rowspan="{{ columns_count }}">{{ index.getType()|default(index.getChoice()) }}</td>
<td rowspan="{{ columns_count }}">{{ index.isUnique() ? 'Yes'|trans : 'No'|trans }}</td>
<td rowspan="{{ columns_count }}">{{ index.isPacked()|raw }}</td>
{% for column in index.getColumns() %}
{% if column.getSeqInIndex() > 1 %}
<tr class="noclick">
{% endif %}
<td>
{{ column.getName() }}
{% if column.getSubPart() is not empty %}
({{ column.getSubPart() }})
{% endif %}
</td>
<td>{{ column.getCardinality() }}</td>
<td>{{ column.getCollation() }}</td>
<td>{{ column.getNull(true) }}</td>
{% if column.getSeqInIndex() == 1 %}
<td rowspan="{{ columns_count }}">{{ index.getComments() }}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
{% endfor %}
</table>
</div>
{% else %}
<div class="no_indexes_defined">{{ 'No index defined!'|trans|notice }}</div>
{% endif %}
</fieldset>
<fieldset class="tblFooters print_ignore text-left">
<form action="{{ url('/table/indexes') }}" method="post">
{{ get_hidden_inputs(db, table) }}
<input type="hidden" name="create_index" value="1">
{% apply format('<input class="mx-2" type="number" name="added_fields" value="1" min="1" required>')|raw %}
{% trans %}Create an index on %s columns{% endtrans %}
{% endapply %}
<input class="btn btn-primary add_index ajax" type="submit" value="{% trans 'Go' %}">
</form>
</fieldset>
</div>
{% endif %}
{% endblock %}

View File

@ -60,28 +60,9 @@ class RelationControllerTest extends AbstractTestCase
}
};
$indexes = [
[
'Schema' => 'Schema1',
'Key_name' => 'Key_name1',
'Column_name' => 'Column_name1',
],
[
'Schema' => 'Schema2',
'Key_name' => 'Key_name2',
'Column_name' => 'Column_name2',
],
[
'Schema' => 'Schema3',
'Key_name' => 'Key_name3',
'Column_name' => 'Column_name3',
],
];
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($indexes));
$GLOBALS['dbi'] = $dbi;

View File

@ -51,6 +51,24 @@ class StructureControllerTest extends AbstractTestCase
$GLOBALS['cfg']['Server']['user'] = 'pma_user';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
$indexes = [
[
'Schema' => 'Schema1',
'Key_name' => 'Key_name1',
'Column_name' => 'Column_name1',
],
[
'Schema' => 'Schema2',
'Key_name' => 'Key_name2',
'Column_name' => 'Column_name2',
],
[
'Schema' => 'Schema3',
'Key_name' => 'Key_name3',
'Column_name' => 'Column_name3',
],
];
$table = $this->getMockBuilder(Table::class)
->disableOriginalConstructor()
->getMock();
@ -60,6 +78,8 @@ class StructureControllerTest extends AbstractTestCase
->getMock();
$dbi->expects($this->any())->method('getTable')
->will($this->returnValue($table));
$dbi->expects($this->any())->method('getTableIndexes')
->will($this->returnValue($indexes));
$GLOBALS['dbi'] = $dbi;