pmd_relation_upd.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * PMD relation update handler
  5. *
  6. * @package PhpMyAdmin-Designer
  7. */
  8. /**
  9. *
  10. */
  11. require_once './libraries/common.inc.php';
  12. PMA_Response::getInstance()->disable();
  13. require_once 'libraries/pmd_common.php';
  14. extract($_POST, EXTR_SKIP);
  15. extract($_GET, EXTR_SKIP);
  16. $die_save_pos = 0;
  17. require_once 'pmd_save_pos.php';
  18. list($DB1, $T1) = explode(".", $T1);
  19. list($DB2, $T2) = explode(".", $T2);
  20. $tables = $GLOBALS['dbi']->getTablesFull($db, $T1);
  21. $type_T1 = strtoupper($tables[$T1]['ENGINE']);
  22. $tables = $GLOBALS['dbi']->getTablesFull($db, $T2);
  23. $type_T2 = strtoupper($tables[$T2]['ENGINE']);
  24. $try_to_delete_internal_relation = false;
  25. if (PMA_Util::isForeignKeySupported($type_T1)
  26. && PMA_Util::isForeignKeySupported($type_T2)
  27. && $type_T1 == $type_T2
  28. ) {
  29. // InnoDB
  30. $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
  31. if (isset($existrel_foreign[$F2]['constraint'])) {
  32. $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($DB2)
  33. . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY '
  34. . PMA_Util::backquote($existrel_foreign[$F2]['constraint'])
  35. . ';';
  36. $upd_rs = $GLOBALS['dbi']->query($upd_query);
  37. } else {
  38. // there can be an internal relation even if InnoDB
  39. $try_to_delete_internal_relation = true;
  40. }
  41. } else {
  42. $try_to_delete_internal_relation = true;
  43. }
  44. if ($try_to_delete_internal_relation) {
  45. // internal relations
  46. PMA_queryAsControlUser(
  47. 'DELETE FROM '
  48. . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
  49. . $cfg['Server']['relation'] . ' WHERE '
  50. . 'master_db = \'' . PMA_Util::sqlAddSlashes($DB2) . '\''
  51. . ' AND master_table = \'' . PMA_Util::sqlAddSlashes($T2) . '\''
  52. . ' AND master_field = \'' . PMA_Util::sqlAddSlashes($F2) . '\''
  53. . ' AND foreign_db = \'' . PMA_Util::sqlAddSlashes($DB1) . '\''
  54. . ' AND foreign_table = \'' . PMA_Util::sqlAddSlashes($T1) . '\''
  55. . ' AND foreign_field = \'' . PMA_Util::sqlAddSlashes($F1) . '\'',
  56. false,
  57. PMA_DatabaseInterface::QUERY_STORE
  58. );
  59. }
  60. PMA_returnUpd(1, __('Relation deleted'));
  61. ?>