3 * Set of functions used for cleaning up phpMyAdmin tables
6 declare(strict_types
=1);
11 * PhpMyAdmin\RelationCleanup class
18 /** @var DatabaseInterface */
22 * @param DatabaseInterface $dbi DatabaseInterface object
23 * @param Relation $relation Relation object
25 public function __construct($dbi, Relation
$relation)
28 $this->relation
= $relation;
32 * Cleanup column related relation stuff
34 * @param string $db database name
35 * @param string $table table name
36 * @param string $column column name
40 public function column($db, $table, $column)
42 $cfgRelation = $this->relation
->getRelationsParam();
44 if ($cfgRelation['commwork']) {
45 $remove_query = 'DELETE FROM '
46 . Util
::backquote($cfgRelation['db'])
47 . '.' . Util
::backquote($cfgRelation['column_info'])
48 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
49 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
51 . ' AND column_name = \'' . $this->dbi
->escapeString($column)
53 $this->relation
->queryAsControlUser($remove_query);
56 if ($cfgRelation['displaywork']) {
57 $remove_query = 'DELETE FROM '
58 . Util
::backquote($cfgRelation['db'])
59 . '.' . Util
::backquote($cfgRelation['table_info'])
60 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
61 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
63 . ' AND display_field = \'' . $this->dbi
->escapeString($column)
65 $this->relation
->queryAsControlUser($remove_query);
68 if (! $cfgRelation['relwork']) {
72 $remove_query = 'DELETE FROM '
73 . Util
::backquote($cfgRelation['db'])
74 . '.' . Util
::backquote($cfgRelation['relation'])
75 . ' WHERE master_db = \'' . $this->dbi
->escapeString($db)
77 . ' AND master_table = \'' . $this->dbi
->escapeString($table)
79 . ' AND master_field = \'' . $this->dbi
->escapeString($column)
81 $this->relation
->queryAsControlUser($remove_query);
83 $remove_query = 'DELETE FROM '
84 . Util
::backquote($cfgRelation['db'])
85 . '.' . Util
::backquote($cfgRelation['relation'])
86 . ' WHERE foreign_db = \'' . $this->dbi
->escapeString($db)
88 . ' AND foreign_table = \'' . $this->dbi
->escapeString($table)
90 . ' AND foreign_field = \'' . $this->dbi
->escapeString($column)
92 $this->relation
->queryAsControlUser($remove_query);
96 * Cleanup table related relation stuff
98 * @param string $db database name
99 * @param string $table table name
103 public function table($db, $table)
105 $cfgRelation = $this->relation
->getRelationsParam();
107 if ($cfgRelation['commwork']) {
108 $remove_query = 'DELETE FROM '
109 . Util
::backquote($cfgRelation['db'])
110 . '.' . Util
::backquote($cfgRelation['column_info'])
111 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
112 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
114 $this->relation
->queryAsControlUser($remove_query);
117 if ($cfgRelation['displaywork']) {
118 $remove_query = 'DELETE FROM '
119 . Util
::backquote($cfgRelation['db'])
120 . '.' . Util
::backquote($cfgRelation['table_info'])
121 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
122 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
124 $this->relation
->queryAsControlUser($remove_query);
127 if ($cfgRelation['pdfwork']) {
128 $remove_query = 'DELETE FROM '
129 . Util
::backquote($cfgRelation['db'])
130 . '.' . Util
::backquote($cfgRelation['table_coords'])
131 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
132 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
134 $this->relation
->queryAsControlUser($remove_query);
137 if ($cfgRelation['relwork']) {
138 $remove_query = 'DELETE FROM '
139 . Util
::backquote($cfgRelation['db'])
140 . '.' . Util
::backquote($cfgRelation['relation'])
141 . ' WHERE master_db = \'' . $this->dbi
->escapeString($db)
143 . ' AND master_table = \'' . $this->dbi
->escapeString($table)
145 $this->relation
->queryAsControlUser($remove_query);
147 $remove_query = 'DELETE FROM '
148 . Util
::backquote($cfgRelation['db'])
149 . '.' . Util
::backquote($cfgRelation['relation'])
150 . ' WHERE foreign_db = \'' . $this->dbi
->escapeString($db)
152 . ' AND foreign_table = \'' . $this->dbi
->escapeString($table)
154 $this->relation
->queryAsControlUser($remove_query);
157 if ($cfgRelation['uiprefswork']) {
158 $remove_query = 'DELETE FROM '
159 . Util
::backquote($cfgRelation['db'])
160 . '.' . Util
::backquote($cfgRelation['table_uiprefs'])
161 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
162 . ' AND table_name = \'' . $this->dbi
->escapeString($table)
164 $this->relation
->queryAsControlUser($remove_query);
167 if (! $cfgRelation['navwork']) {
171 $remove_query = 'DELETE FROM '
172 . Util
::backquote($cfgRelation['db'])
173 . '.' . Util
::backquote($cfgRelation['navigationhiding'])
174 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\''
175 . ' AND (table_name = \'' . $this->dbi
->escapeString($table)
177 . ' OR (item_name = \'' . $this->dbi
->escapeString($table)
179 . ' AND item_type = \'table\'))';
180 $this->relation
->queryAsControlUser($remove_query);
184 * Cleanup database related relation stuff
186 * @param string $db database name
190 public function database($db)
192 $cfgRelation = $this->relation
->getRelationsParam();
194 if ($cfgRelation['commwork']) {
195 $remove_query = 'DELETE FROM '
196 . Util
::backquote($cfgRelation['db'])
197 . '.' . Util
::backquote($cfgRelation['column_info'])
198 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
199 $this->relation
->queryAsControlUser($remove_query);
202 if ($cfgRelation['bookmarkwork']) {
203 $remove_query = 'DELETE FROM '
204 . Util
::backquote($cfgRelation['db'])
205 . '.' . Util
::backquote($cfgRelation['bookmark'])
206 . ' WHERE dbase = \'' . $this->dbi
->escapeString($db) . '\'';
207 $this->relation
->queryAsControlUser($remove_query);
210 if ($cfgRelation['displaywork']) {
211 $remove_query = 'DELETE FROM '
212 . Util
::backquote($cfgRelation['db'])
213 . '.' . Util
::backquote($cfgRelation['table_info'])
214 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
215 $this->relation
->queryAsControlUser($remove_query);
218 if ($cfgRelation['pdfwork']) {
219 $remove_query = 'DELETE FROM '
220 . Util
::backquote($cfgRelation['db'])
221 . '.' . Util
::backquote($cfgRelation['pdf_pages'])
222 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
223 $this->relation
->queryAsControlUser($remove_query);
225 $remove_query = 'DELETE FROM '
226 . Util
::backquote($cfgRelation['db'])
227 . '.' . Util
::backquote($cfgRelation['table_coords'])
228 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
229 $this->relation
->queryAsControlUser($remove_query);
232 if ($cfgRelation['relwork']) {
233 $remove_query = 'DELETE FROM '
234 . Util
::backquote($cfgRelation['db'])
235 . '.' . Util
::backquote($cfgRelation['relation'])
236 . ' WHERE master_db = \''
237 . $this->dbi
->escapeString($db) . '\'';
238 $this->relation
->queryAsControlUser($remove_query);
240 $remove_query = 'DELETE FROM '
241 . Util
::backquote($cfgRelation['db'])
242 . '.' . Util
::backquote($cfgRelation['relation'])
243 . ' WHERE foreign_db = \'' . $this->dbi
->escapeString($db)
245 $this->relation
->queryAsControlUser($remove_query);
248 if ($cfgRelation['uiprefswork']) {
249 $remove_query = 'DELETE FROM '
250 . Util
::backquote($cfgRelation['db'])
251 . '.' . Util
::backquote($cfgRelation['table_uiprefs'])
252 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
253 $this->relation
->queryAsControlUser($remove_query);
256 if ($cfgRelation['navwork']) {
257 $remove_query = 'DELETE FROM '
258 . Util
::backquote($cfgRelation['db'])
259 . '.' . Util
::backquote($cfgRelation['navigationhiding'])
260 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
261 $this->relation
->queryAsControlUser($remove_query);
264 if ($cfgRelation['savedsearcheswork']) {
265 $remove_query = 'DELETE FROM '
266 . Util
::backquote($cfgRelation['db'])
267 . '.' . Util
::backquote($cfgRelation['savedsearches'])
268 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
269 $this->relation
->queryAsControlUser($remove_query);
272 if (! $cfgRelation['centralcolumnswork']) {
276 $remove_query = 'DELETE FROM '
277 . Util
::backquote($cfgRelation['db'])
278 . '.' . Util
::backquote($cfgRelation['central_columns'])
279 . ' WHERE db_name = \'' . $this->dbi
->escapeString($db) . '\'';
280 $this->relation
->queryAsControlUser($remove_query);
284 * Cleanup user related relation stuff
286 * @param string $username username
290 public function user($username)
292 $cfgRelation = $this->relation
->getRelationsParam();
294 if ($cfgRelation['bookmarkwork']) {
295 $remove_query = 'DELETE FROM '
296 . Util
::backquote($cfgRelation['db'])
297 . '.' . Util
::backquote($cfgRelation['bookmark'])
298 . " WHERE `user` = '" . $this->dbi
->escapeString($username)
300 $this->relation
->queryAsControlUser($remove_query);
303 if ($cfgRelation['historywork']) {
304 $remove_query = 'DELETE FROM '
305 . Util
::backquote($cfgRelation['db'])
306 . '.' . Util
::backquote($cfgRelation['history'])
307 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
309 $this->relation
->queryAsControlUser($remove_query);
312 if ($cfgRelation['recentwork']) {
313 $remove_query = 'DELETE FROM '
314 . Util
::backquote($cfgRelation['db'])
315 . '.' . Util
::backquote($cfgRelation['recent'])
316 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
318 $this->relation
->queryAsControlUser($remove_query);
321 if ($cfgRelation['favoritework']) {
322 $remove_query = 'DELETE FROM '
323 . Util
::backquote($cfgRelation['db'])
324 . '.' . Util
::backquote($cfgRelation['favorite'])
325 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
327 $this->relation
->queryAsControlUser($remove_query);
330 if ($cfgRelation['uiprefswork']) {
331 $remove_query = 'DELETE FROM '
332 . Util
::backquote($cfgRelation['db'])
333 . '.' . Util
::backquote($cfgRelation['table_uiprefs'])
334 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
336 $this->relation
->queryAsControlUser($remove_query);
339 if ($cfgRelation['userconfigwork']) {
340 $remove_query = 'DELETE FROM '
341 . Util
::backquote($cfgRelation['db'])
342 . '.' . Util
::backquote($cfgRelation['userconfig'])
343 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
345 $this->relation
->queryAsControlUser($remove_query);
348 if ($cfgRelation['menuswork']) {
349 $remove_query = 'DELETE FROM '
350 . Util
::backquote($cfgRelation['db'])
351 . '.' . Util
::backquote($cfgRelation['users'])
352 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
354 $this->relation
->queryAsControlUser($remove_query);
357 if ($cfgRelation['navwork']) {
358 $remove_query = 'DELETE FROM '
359 . Util
::backquote($cfgRelation['db'])
360 . '.' . Util
::backquote($cfgRelation['navigationhiding'])
361 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
363 $this->relation
->queryAsControlUser($remove_query);
366 if ($cfgRelation['savedsearcheswork']) {
367 $remove_query = 'DELETE FROM '
368 . Util
::backquote($cfgRelation['db'])
369 . '.' . Util
::backquote($cfgRelation['savedsearches'])
370 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
372 $this->relation
->queryAsControlUser($remove_query);
375 if (! $cfgRelation['designersettingswork']) {
379 $remove_query = 'DELETE FROM '
380 . Util
::backquote($cfgRelation['db'])
381 . '.' . Util
::backquote($cfgRelation['designer_settings'])
382 . " WHERE `username` = '" . $this->dbi
->escapeString($username)
384 $this->relation
->queryAsControlUser($remove_query);