Feature Request #3187076
[phpmyadmin-regexreplace.git] / libraries / relation_cleanup.lib.php
blob476d46c68b009326652c2787904e7fce494ca7a8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used for cleaning up phpMyAdmin tables
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Cleanu column related relation stuff
15 * @uses PMA_getRelationsParam()
16 * @uses PMA_backquote()
17 * @uses PMA_sqlAddslashes()
18 * @uses PMA_query_as_controluser()
19 * @param string $db
20 * @param string $table
21 * @param string $column
23 function PMA_relationsCleanupColumn($db, $table, $column)
25 $cfgRelation = PMA_getRelationsParam();
27 if ($cfgRelation['commwork']) {
28 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
29 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
30 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
31 . ' AND column_name = \'' . PMA_sqlAddslashes($column) . '\'';
32 PMA_query_as_controluser($remove_query);
35 if ($cfgRelation['displaywork']) {
36 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
37 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
38 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
39 . ' AND display_field = \'' . PMA_sqlAddslashes($column) . '\'';
40 PMA_query_as_controluser($remove_query);
43 if ($cfgRelation['relwork']) {
44 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
45 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
46 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\''
47 . ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\'';
48 PMA_query_as_controluser($remove_query);
50 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
51 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
52 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\''
53 . ' AND foreign_field = \'' . PMA_sqlAddslashes($column) . '\'';
54 PMA_query_as_controluser($remove_query);
58 /**
59 * Cleanup table related relation stuff
61 * @uses PMA_getRelationsParam()
62 * @uses PMA_backquote()
63 * @uses PMA_sqlAddslashes()
64 * @uses PMA_query_as_controluser()
65 * @param string $db
66 * @param string $table
68 function PMA_relationsCleanupTable($db, $table)
70 $cfgRelation = PMA_getRelationsParam();
72 if ($cfgRelation['commwork']) {
73 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
74 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
75 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
76 PMA_query_as_controluser($remove_query);
79 if ($cfgRelation['displaywork']) {
80 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
81 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
82 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
83 PMA_query_as_controluser($remove_query);
86 if ($cfgRelation['pdfwork']) {
87 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
88 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
89 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
90 PMA_query_as_controluser($remove_query);
93 if ($cfgRelation['designerwork']) {
94 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['designer_coords'])
95 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
96 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
97 PMA_query_as_controluser($remove_query);
100 if ($cfgRelation['relwork']) {
101 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
102 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
103 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\'';
104 PMA_query_as_controluser($remove_query);
106 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
107 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\''
108 . ' AND foreign_table = \'' . PMA_sqlAddslashes($table) . '\'';
109 PMA_query_as_controluser($remove_query);
114 * Cleanup database related relation stuff
116 * @uses PMA_getRelationsParam()
117 * @uses PMA_backquote()
118 * @uses PMA_sqlAddslashes()
119 * @uses PMA_query_as_controluser()
120 * @param string $db
122 function PMA_relationsCleanupDatabase($db)
124 $cfgRelation = PMA_getRelationsParam();
126 if ($cfgRelation['commwork']) {
127 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
128 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
129 PMA_query_as_controluser($remove_query);
132 if ($cfgRelation['bookmarkwork']) {
133 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['bookmark'])
134 . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'';
135 PMA_query_as_controluser($remove_query);
138 if ($cfgRelation['displaywork']) {
139 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info'])
140 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
141 PMA_query_as_controluser($remove_query);
144 if ($cfgRelation['pdfwork']) {
145 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
146 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
147 PMA_query_as_controluser($remove_query);
149 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
150 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
151 PMA_query_as_controluser($remove_query);
154 if ($cfgRelation['designerwork']) {
155 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['designer_coords'])
156 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
157 PMA_query_as_controluser($remove_query);
160 if ($cfgRelation['relwork']) {
161 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
162 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\'';
163 PMA_query_as_controluser($remove_query);
165 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation'])
166 . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($db) . '\'';
167 PMA_query_as_controluser($remove_query);