pmd_relation_upd.php 2.3 KB

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