Merge pull request #17572 from pokemaobr/REMOVING_GET_TABLES_FROM_TWIG_TEMPLATE
Removing get tables from twig template and removing relationextension…
This commit is contained in:
commit
233d723d52
@ -146,6 +146,66 @@ final class RelationController extends AbstractController
|
||||
uksort($column_array, 'strnatcasecmp');
|
||||
}
|
||||
|
||||
$foreignKeyRow = '';
|
||||
$existrelForeign = array_key_exists('foreign_keys_data', $relationsForeign)
|
||||
? $relationsForeign['foreign_keys_data']
|
||||
: [];
|
||||
$i = 0;
|
||||
|
||||
foreach ($existrelForeign as $key => $oneKey) {
|
||||
$foreignDb = $oneKey['ref_db_name'] ?? $GLOBALS['db'];
|
||||
$foreignTable = false;
|
||||
if ($foreignDb) {
|
||||
$foreignTable = $oneKey['ref_table_name'] ?? false;
|
||||
$tables = $this->relation->getTables($foreignDb, $storageEngine);
|
||||
} else {
|
||||
$tables = $this->relation->getTables($GLOBALS['db'], $storageEngine);
|
||||
}
|
||||
|
||||
$uniqueColumns = [];
|
||||
if ($foreignDb && $foreignTable) {
|
||||
$tableObject = Table::get(
|
||||
$foreignTable,
|
||||
$foreignDb
|
||||
);
|
||||
$uniqueColumns = $tableObject->getUniqueColumns(false, false);
|
||||
}
|
||||
|
||||
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
|
||||
'i' => $i,
|
||||
'one_key' => $oneKey,
|
||||
'column_array' => $column_array,
|
||||
'options_array' => $options,
|
||||
'tbl_storage_engine' => $storageEngine,
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table'],
|
||||
'url_params' => $GLOBALS['urlParams'],
|
||||
'databases' => $GLOBALS['dblist']->databases,
|
||||
'foreign_db' => $foreignDb,
|
||||
'foreign_table' => $foreignTable,
|
||||
'unique_columns' => $uniqueColumns,
|
||||
'tables' => $tables,
|
||||
]);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$tables = $this->relation->getTables($GLOBALS['db'], $storageEngine);
|
||||
$foreignKeyRow .= $this->template->render('table/relation/foreign_key_row', [
|
||||
'i' => $i,
|
||||
'one_key' => [],
|
||||
'column_array' => $column_array,
|
||||
'options_array' => $options,
|
||||
'tbl_storage_engine' => $storageEngine,
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $GLOBALS['table'],
|
||||
'url_params' => $GLOBALS['urlParams'],
|
||||
'databases' => $GLOBALS['dblist']->databases,
|
||||
'foreign_db' => false,
|
||||
'foreign_table' => false,
|
||||
'unique_columns' => [],
|
||||
'tables' => $tables,
|
||||
]);
|
||||
|
||||
// common form
|
||||
$engine = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table'])->getStorageEngine();
|
||||
$this->render('table/relation/common_form', [
|
||||
@ -155,9 +215,7 @@ final class RelationController extends AbstractController
|
||||
'relation_parameters' => $relationParameters,
|
||||
'tbl_storage_engine' => $storageEngine,
|
||||
'existrel' => $relations,
|
||||
'existrel_foreign' => array_key_exists('foreign_keys_data', $relationsForeign)
|
||||
? $relationsForeign['foreign_keys_data']
|
||||
: [],
|
||||
'existrel_foreign' => $existrelForeign,
|
||||
'options_array' => $options,
|
||||
'column_array' => $column_array,
|
||||
'column_hash_array' => $column_hash_array,
|
||||
@ -168,6 +226,7 @@ final class RelationController extends AbstractController
|
||||
'default_sliders_state' => $GLOBALS['cfg']['InitialSlidersState'],
|
||||
'route' => $route,
|
||||
'display_field' => $this->relation->getDisplayField($GLOBALS['db'], $GLOBALS['table']),
|
||||
'foreign_key_row' => $foreignKeyRow,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ use PhpMyAdmin\Twig\Extensions\Node\TransNode;
|
||||
use PhpMyAdmin\Twig\FlashMessagesExtension;
|
||||
use PhpMyAdmin\Twig\I18nExtension;
|
||||
use PhpMyAdmin\Twig\MessageExtension;
|
||||
use PhpMyAdmin\Twig\RelationExtension;
|
||||
use PhpMyAdmin\Twig\SanitizeExtension;
|
||||
use PhpMyAdmin\Twig\TableExtension;
|
||||
use PhpMyAdmin\Twig\TrackerExtension;
|
||||
@ -97,7 +96,6 @@ class Template
|
||||
$twig->addExtension(new FlashMessagesExtension());
|
||||
$twig->addExtension(new I18nExtension());
|
||||
$twig->addExtension(new MessageExtension());
|
||||
$twig->addExtension(new RelationExtension());
|
||||
$twig->addExtension(new SanitizeExtension());
|
||||
$twig->addExtension(new TableExtension());
|
||||
$twig->addExtension(new TrackerExtension());
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Twig;
|
||||
|
||||
use PhpMyAdmin\ConfigStorage\Relation;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class RelationExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
$relation = new Relation($GLOBALS['dbi']);
|
||||
|
||||
return [
|
||||
new TwigFunction(
|
||||
'get_tables',
|
||||
[$relation, 'getTables']
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -37,56 +37,7 @@
|
||||
<th>{% trans 'Table' %}</th>
|
||||
<th>{% trans 'Column' %}</th>
|
||||
</tr></thead>
|
||||
{% set i = 0 %}
|
||||
{% if existrel_foreign is not empty %}
|
||||
{% for key, one_key in existrel_foreign %}
|
||||
{# Foreign database dropdown #}
|
||||
{% set foreign_db = one_key['ref_db_name'] is defined
|
||||
and one_key['ref_db_name'] is not null
|
||||
? one_key['ref_db_name'] : db %}
|
||||
{% set foreign_table = false %}
|
||||
{% if foreign_db %}
|
||||
{% set foreign_table = one_key['ref_table_name'] is defined
|
||||
and one_key['ref_table_name'] is not null
|
||||
? one_key['ref_table_name'] : false %}
|
||||
{% endif %}
|
||||
{% set unique_columns = [] %}
|
||||
{% if foreign_db and foreign_table %}
|
||||
{% set table_obj = table_get(foreign_table, foreign_db) %}
|
||||
{% set unique_columns = table_obj.getUniqueColumns(false, false) %}
|
||||
{% endif %}
|
||||
{% include 'table/relation/foreign_key_row.twig' with {
|
||||
'i': i,
|
||||
'one_key': one_key,
|
||||
'column_array': column_array,
|
||||
'options_array': options_array,
|
||||
'tbl_storage_engine': tbl_storage_engine,
|
||||
'db': db,
|
||||
'table': table,
|
||||
'url_params': url_params,
|
||||
'databases': databases,
|
||||
'foreign_db': foreign_db,
|
||||
'foreign_table': foreign_table,
|
||||
'unique_columns': unique_columns
|
||||
} only %}
|
||||
{% set i = i + 1 %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% include 'table/relation/foreign_key_row.twig' with {
|
||||
'i': i,
|
||||
'one_key': [],
|
||||
'column_array': column_array,
|
||||
'options_array': options_array,
|
||||
'tbl_storage_engine': tbl_storage_engine,
|
||||
'db': db,
|
||||
'table': table,
|
||||
'url_params': url_params,
|
||||
'databases': databases,
|
||||
'foreign_db': foreign_db,
|
||||
'foreign_table': foreign_table,
|
||||
'unique_columns': unique_columns
|
||||
} only %}
|
||||
{% set i = i + 1 %}
|
||||
{{ foreign_key_row|raw }}
|
||||
<tr>
|
||||
<th colspan="6">
|
||||
<a class="formelement clearfloat add_foreign_key" href="">
|
||||
|
||||
@ -85,12 +85,6 @@
|
||||
{% trans '+ Add column' %}
|
||||
</a>
|
||||
</td>
|
||||
{% set tables = [] %}
|
||||
{% if foreign_db %}
|
||||
{% set tables = get_tables(foreign_db, tbl_storage_engine) %}
|
||||
{% else %}
|
||||
{% set tables = get_tables(db, tbl_storage_engine) %}
|
||||
{% endif %}
|
||||
<td>
|
||||
<span class="formelement clearfloat">
|
||||
{% include 'table/relation/relational_dropdown.twig' with {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user