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