Skip to content

Commit 233d723

Browse files
Merge pull request #17572 from pokemaobr/REMOVING_GET_TABLES_FROM_TWIG_TEMPLATE
Removing get tables from twig template and removing relationextension…
2 parents 18309a6 + 556804c commit 233d723

5 files changed

Lines changed: 63 additions & 90 deletions

File tree

libraries/classes/Controllers/Table/RelationController.php

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,66 @@ public function __invoke(): void
146146
uksort($column_array, 'strnatcasecmp');
147147
}
148148

149+
$foreignKeyRow = '';
150+
$existrelForeign = array_key_exists('foreign_keys_data', $relationsForeign)
151+
? $relationsForeign['foreign_keys_data']
152+
: [];
153+
$i = 0;
154+
155+
foreach ($existrelForeign as $key => $oneKey) {
156+
$foreignDb = $oneKey['ref_db_name'] ?? $GLOBALS['db'];
157+
$foreignTable = false;
158+
if ($foreignDb) {
159+
$foreignTable = $oneKey['ref_table_name'] ?? false;
160+
$tables = $this->relation->getTables($foreignDb, $storageEngine);
161+
} else {
162+
$tables = $this->relation->getTables($GLOBALS['db'], $storageEngine);
163+
}
164+
165+
$uniqueColumns = [];
166+
if ($foreignDb && $foreignTable) {
167+
$tableObject = Table::get(
168+
$foreignTable,
169+
$foreignDb
170+
);
171+
$uniqueColumns = $tableObject->getUniqueColumns(false, false);
172+
}
173+
174+
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
175+
'i' => $i,
176+
'one_key' => $oneKey,
177+
'column_array' => $column_array,
178+
'options_array' => $options,
179+
'tbl_storage_engine' => $storageEngine,
180+
'db' => $GLOBALS['db'],
181+
'table' => $GLOBALS['table'],
182+
'url_params' => $GLOBALS['urlParams'],
183+
'databases' => $GLOBALS['dblist']->databases,
184+
'foreign_db' => $foreignDb,
185+
'foreign_table' => $foreignTable,
186+
'unique_columns' => $uniqueColumns,
187+
'tables' => $tables,
188+
]);
189+
$i++;
190+
}
191+
192+
$tables = $this->relation->getTables($GLOBALS['db'], $storageEngine);
193+
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
194+
'i' => $i,
195+
'one_key' => [],
196+
'column_array' => $column_array,
197+
'options_array' => $options,
198+
'tbl_storage_engine' => $storageEngine,
199+
'db' => $GLOBALS['db'],
200+
'table' => $GLOBALS['table'],
201+
'url_params' => $GLOBALS['urlParams'],
202+
'databases' => $GLOBALS['dblist']->databases,
203+
'foreign_db' => false,
204+
'foreign_table' => false,
205+
'unique_columns' => [],
206+
'tables' => $tables,
207+
]);
208+
149209
// common form
150210
$engine = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table'])->getStorageEngine();
151211
$this->render('table/relation/common_form', [
@@ -155,9 +215,7 @@ public function __invoke(): void
155215
'relation_parameters' => $relationParameters,
156216
'tbl_storage_engine' => $storageEngine,
157217
'existrel' => $relations,
158-
'existrel_foreign' => array_key_exists('foreign_keys_data', $relationsForeign)
159-
? $relationsForeign['foreign_keys_data']
160-
: [],
218+
'existrel_foreign' => $existrelForeign,
161219
'options_array' => $options,
162220
'column_array' => $column_array,
163221
'column_hash_array' => $column_hash_array,
@@ -168,6 +226,7 @@ public function __invoke(): void
168226
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
169227
'route' => $route,
170228
'display_field' => $this->relation->getDisplayField($GLOBALS['db'], $GLOBALS['table']),
229+
'foreign_key_row' => $foreignKeyRow,
171230
]);
172231
}
173232

libraries/classes/Template.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpMyAdmin\Twig\FlashMessagesExtension;
1111
use PhpMyAdmin\Twig\I18nExtension;
1212
use PhpMyAdmin\Twig\MessageExtension;
13-
use PhpMyAdmin\Twig\RelationExtension;
1413
use PhpMyAdmin\Twig\SanitizeExtension;
1514
use PhpMyAdmin\Twig\TableExtension;
1615
use PhpMyAdmin\Twig\TrackerExtension;
@@ -97,7 +96,6 @@ public static function getTwigEnvironment(?string $cacheDir): Environment
9796
$twig->addExtension(new FlashMessagesExtension());
9897
$twig->addExtension(new I18nExtension());
9998
$twig->addExtension(new MessageExtension());
100-
$twig->addExtension(new RelationExtension());
10199
$twig->addExtension(new SanitizeExtension());
102100
$twig->addExtension(new TableExtension());
103101
$twig->addExtension(new TrackerExtension());

libraries/classes/Twig/RelationExtension.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

templates/table/relation/common_form.twig

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,56 +37,7 @@
3737
<th>{% trans 'Table' %}</th>
3838
<th>{% trans 'Column' %}</th>
3939
</tr></thead>
40-
{% set i = 0 %}
41-
{% if existrel_foreign is not empty %}
42-
{% for key, one_key in existrel_foreign %}
43-
{# Foreign database dropdown #}
44-
{% set foreign_db = one_key['ref_db_name'] is defined
45-
and one_key['ref_db_name'] is not null
46-
? one_key['ref_db_name'] : db %}
47-
{% set foreign_table = false %}
48-
{% if foreign_db %}
49-
{% set foreign_table = one_key['ref_table_name'] is defined
50-
and one_key['ref_table_name'] is not null
51-
? one_key['ref_table_name'] : false %}
52-
{% endif %}
53-
{% set unique_columns = [] %}
54-
{% if foreign_db and foreign_table %}
55-
{% set table_obj = table_get(foreign_table, foreign_db) %}
56-
{% set unique_columns = table_obj.getUniqueColumns(false, false) %}
57-
{% endif %}
58-
{% include 'table/relation/foreign_key_row.twig' with {
59-
'i': i,
60-
'one_key': one_key,
61-
'column_array': column_array,
62-
'options_array': options_array,
63-
'tbl_storage_engine': tbl_storage_engine,
64-
'db': db,
65-
'table': table,
66-
'url_params': url_params,
67-
'databases': databases,
68-
'foreign_db': foreign_db,
69-
'foreign_table': foreign_table,
70-
'unique_columns': unique_columns
71-
} only %}
72-
{% set i = i + 1 %}
73-
{% endfor %}
74-
{% endif %}
75-
{% include 'table/relation/foreign_key_row.twig' with {
76-
'i': i,
77-
'one_key': [],
78-
'column_array': column_array,
79-
'options_array': options_array,
80-
'tbl_storage_engine': tbl_storage_engine,
81-
'db': db,
82-
'table': table,
83-
'url_params': url_params,
84-
'databases': databases,
85-
'foreign_db': foreign_db,
86-
'foreign_table': foreign_table,
87-
'unique_columns': unique_columns
88-
} only %}
89-
{% set i = i + 1 %}
40+
{{ foreign_key_row|raw }}
9041
<tr>
9142
<th colspan="6">
9243
<a class="formelement clearfloat add_foreign_key" href="">

templates/table/relation/foreign_key_row.twig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@
8585
{% trans '+ Add column' %}
8686
</a>
8787
</td>
88-
{% set tables = [] %}
89-
{% if foreign_db %}
90-
{% set tables = get_tables(foreign_db, tbl_storage_engine) %}
91-
{% else %}
92-
{% set tables = get_tables(db, tbl_storage_engine) %}
93-
{% endif %}
9488
<td>
9589
<span class="formelement clearfloat">
9690
{% include 'table/relation/relational_dropdown.twig' with {

0 commit comments

Comments
 (0)