2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * PMD relation update handler
6 * @package PhpMyAdmin-Designer
12 require_once './libraries/common.inc.php';
14 PMA_Response
::getInstance()->disable();
16 require_once 'libraries/pmd_common.php';
17 extract($_POST, EXTR_SKIP
);
18 extract($_GET, EXTR_SKIP
);
20 require_once 'pmd_save_pos.php';
21 list($DB1, $T1) = explode(".", $T1);
22 list($DB2, $T2) = explode(".", $T2);
24 $tables = $GLOBALS['dbi']->getTablesFull($db, $T1);
25 $type_T1 = strtoupper($tables[$T1]['ENGINE']);
26 $tables = $GLOBALS['dbi']->getTablesFull($db, $T2);
27 $type_T2 = strtoupper($tables[$T2]['ENGINE']);
29 $try_to_delete_internal_relation = false;
31 if (PMA_Util
::isForeignKeySupported($type_T1)
32 && PMA_Util
::isForeignKeySupported($type_T2)
33 && $type_T1 == $type_T2
36 $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign');
38 if (isset($existrel_foreign[$F2]['constraint'])) {
39 $upd_query = 'ALTER TABLE ' . PMA_Util
::backquote($DB2)
40 . '.' . PMA_Util
::backquote($T2) . ' DROP FOREIGN KEY '
41 . PMA_Util
::backquote($existrel_foreign[$F2]['constraint'])
43 $upd_rs = $GLOBALS['dbi']->query($upd_query);
45 // there can be an internal relation even if InnoDB
46 $try_to_delete_internal_relation = true;
49 $try_to_delete_internal_relation = true;
51 if ($try_to_delete_internal_relation) {
53 PMA_queryAsControlUser(
55 . PMA_Util
::backquote($GLOBALS['cfgRelation']['db']) . '.'
56 . $cfg['Server']['relation'].' WHERE '
57 . 'master_db = \'' . PMA_Util
::sqlAddSlashes($DB2) . '\''
58 . ' AND master_table = \'' . PMA_Util
::sqlAddSlashes($T2) . '\''
59 . ' AND master_field = \'' . PMA_Util
::sqlAddSlashes($F2) . '\''
60 . ' AND foreign_db = \'' . PMA_Util
::sqlAddSlashes($DB1) . '\''
61 . ' AND foreign_table = \'' . PMA_Util
::sqlAddSlashes($T1) . '\''
62 . ' AND foreign_field = \'' . PMA_Util
::sqlAddSlashes($F1) . '\'',
64 PMA_DatabaseInterface
::QUERY_STORE
67 PMD_return_upd(1, __('Relation deleted'));