tbl_relation.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Display table relations for viewing and editing
  5. *
  6. * includes phpMyAdmin relations and InnoDB relations
  7. *
  8. * @todo fix name handling: currently names with dots (.) are not properly handled
  9. * for internal relations (but foreign keys relations are correct)
  10. * @todo foreign key constraints require both fields being of equal type and size
  11. * @todo check foreign fields to be from same type and size, all other makes no sense
  12. * @todo if above todos are fullfilled we can add all fields meet requirements
  13. * in the select dropdown
  14. * @package PhpMyAdmin
  15. */
  16. use PhpMyAdmin\Controllers\Table\TableRelationController;
  17. use PhpMyAdmin\Di\Container;
  18. use PhpMyAdmin\Relation;
  19. use PhpMyAdmin\Response;
  20. use PhpMyAdmin\Table;
  21. use PhpMyAdmin\Util;
  22. require_once 'libraries/common.inc.php';
  23. $container = Container::getDefaultContainer();
  24. $container->factory('PhpMyAdmin\Controllers\Table\TableRelationController');
  25. $container->alias(
  26. 'TableRelationController',
  27. 'PhpMyAdmin\Controllers\Table\TableRelationController'
  28. );
  29. $container->set('PhpMyAdmin\Response', Response::getInstance());
  30. $container->alias('response', 'PhpMyAdmin\Response');
  31. /* Define dependencies for the concerned controller */
  32. $db = $container->get('db');
  33. $table = $container->get('table');
  34. $dbi = $container->get('dbi');
  35. $options_array = array(
  36. 'CASCADE' => 'CASCADE',
  37. 'SET_NULL' => 'SET NULL',
  38. 'NO_ACTION' => 'NO ACTION',
  39. 'RESTRICT' => 'RESTRICT',
  40. );
  41. $relation = new Relation();
  42. $cfgRelation = $relation->getRelationsParam();
  43. $tbl_storage_engine = mb_strtoupper(
  44. $dbi->getTable($db, $table)->getStatusInfo('Engine')
  45. );
  46. $upd_query = new Table($table, $db, $dbi);
  47. $dependency_definitions = array(
  48. "options_array" => $options_array,
  49. "cfgRelation" => $cfgRelation,
  50. "tbl_storage_engine" => $tbl_storage_engine,
  51. "upd_query" => $upd_query
  52. );
  53. if ($cfgRelation['relwork']) {
  54. $dependency_definitions['existrel'] = $relation->getForeigners(
  55. $db, $table, '', 'internal'
  56. );
  57. }
  58. if (Util::isForeignKeySupported($tbl_storage_engine)) {
  59. $dependency_definitions['existrel_foreign'] = $relation->getForeigners(
  60. $db, $table, '', 'foreign'
  61. );
  62. }
  63. /** @var TableRelationController $controller */
  64. $controller = $container->get('TableRelationController', $dependency_definitions);
  65. $controller->indexAction();