diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2019-08-16 06:12:52 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2019-08-16 06:12:52 +0300 |
commit | 23b084c25909648b820f8bc7be15bda53d2701a3 (patch) | |
tree | 352d3bcc4435081081bf0a3d11a1995a4ba5e348 /libraries | |
parent | bbe110b27f22110de88f0310eacfb8045b216b8c (diff) |
Use the router for table relation page
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/classes/Core.php | 1 | ||||
-rw-r--r-- | libraries/classes/Menu.php | 6 | ||||
-rw-r--r-- | libraries/entry_points/table/relation.php | 90 |
3 files changed, 94 insertions, 3 deletions
diff --git a/libraries/classes/Core.php b/libraries/classes/Core.php index 8be34267ef..1772fc12d3 100644 --- a/libraries/classes/Core.php +++ b/libraries/classes/Core.php @@ -38,7 +38,6 @@ class Core 'server_import.php', 'tbl_import.php', 'tbl_export.php', - 'tbl_relation.php', 'tbl_row_action.php', 'transformation_overview.php', 'transformation_wrapper.php', diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index a2f3fd750a..a789aa02b9 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -348,8 +348,10 @@ class Menu $tabs['structure']['icon'] = 'b_props'; $tabs['structure']['link'] = Url::getFromRoute('/table/structure'); $tabs['structure']['text'] = __('Structure'); - $tabs['structure']['active'] = basename($GLOBALS['PMA_PHP_SELF']) === 'tbl_relation.php' || - (isset($_REQUEST['route']) && in_array($_REQUEST['route'], ['/table/structure'])); + $tabs['structure']['active'] = isset($_REQUEST['route']) && in_array($_REQUEST['route'], [ + '/table/relation', + '/table/structure', + ]); $tabs['sql']['icon'] = 'b_sql'; $tabs['sql']['link'] = Url::getFromRoute('/table/sql'); diff --git a/libraries/entry_points/table/relation.php b/libraries/entry_points/table/relation.php new file mode 100644 index 0000000000..3809336a9f --- /dev/null +++ b/libraries/entry_points/table/relation.php @@ -0,0 +1,90 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Display table relations for viewing and editing + * + * includes phpMyAdmin relations and InnoDB relations + * + * @todo fix name handling: currently names with dots (.) are not properly handled + * for internal relations (but foreign keys relations are correct) + * @todo foreign key constraints require both fields being of equal type and size + * @todo check foreign fields to be from same type and size, all other makes no sense + * @todo if above todos are fullfilled we can add all fields meet requirements + * in the select dropdown + * @package PhpMyAdmin + */ +declare(strict_types=1); + +use PhpMyAdmin\Controllers\Table\RelationController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Relation; +use PhpMyAdmin\Table; +use PhpMyAdmin\Util; +use Symfony\Component\DependencyInjection\Definition; + +if (! defined('PHPMYADMIN')) { + exit; +} + +global $containerBuilder; + +/* Define dependencies for the concerned controller */ +$db = $containerBuilder->getParameter('db'); +$table = $containerBuilder->getParameter('table'); + +/** @var DatabaseInterface $dbi */ +$dbi = $containerBuilder->get(DatabaseInterface::class); + +$options_array = [ + 'CASCADE' => 'CASCADE', + 'SET_NULL' => 'SET NULL', + 'NO_ACTION' => 'NO ACTION', + 'RESTRICT' => 'RESTRICT', +]; +/** @var Relation $relation */ +$relation = $containerBuilder->get('relation'); +$cfgRelation = $relation->getRelationsParam(); +$tbl_storage_engine = mb_strtoupper( + $dbi->getTable($db, $table)->getStatusInfo('Engine') +); +$upd_query = new Table($table, $db, $dbi); + +/* Define dependencies for the concerned controller */ +$dependency_definitions = [ + 'options_array' => $options_array, + 'cfgRelation' => $cfgRelation, + 'tbl_storage_engine' => $tbl_storage_engine, + 'existrel' => [], + 'existrel_foreign' => [], + 'upd_query' => $upd_query, +]; +if ($cfgRelation['relwork']) { + $dependency_definitions['existrel'] = $relation->getForeigners( + $db, + $table, + '', + 'internal' + ); +} +if (Util::isForeignKeySupported($tbl_storage_engine)) { + $dependency_definitions['existrel_foreign'] = $relation->getForeigners( + $db, + $table, + '', + 'foreign' + ); +} + +/** @var Definition $definition */ +$definition = $containerBuilder->getDefinition(RelationController::class); +array_map( + static function (string $parameterName, $value) use ($definition) { + $definition->replaceArgument($parameterName, $value); + }, + array_keys($dependency_definitions), + $dependency_definitions +); + +/** @var RelationController $controller */ +$controller = $containerBuilder->get(RelationController::class); +$controller->indexAction(); |