Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / classes / RelationCleanup.php
blobd2195808512254a6498550823b0a5a9660293298
1 <?php
2 /**
3 * Set of functions used for cleaning up phpMyAdmin tables
4 */
6 declare(strict_types=1);
8 namespace PhpMyAdmin;
10 /**
11 * PhpMyAdmin\RelationCleanup class
13 class RelationCleanup
15 /** @var Relation */
16 public $relation;
18 /** @var DatabaseInterface */
19 public $dbi;
21 /**
22 * @param DatabaseInterface $dbi DatabaseInterface object
23 * @param Relation $relation Relation object
25 public function __construct($dbi, Relation $relation)
27 $this->dbi = $dbi;
28 $this->relation = $relation;
31 /**
32 * Cleanup column related relation stuff
34 * @param string $db database name
35 * @param string $table table name
36 * @param string $column column name
38 * @return void
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)
50 . '\''
51 . ' AND column_name = \'' . $this->dbi->escapeString($column)
52 . '\'';
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)
62 . '\''
63 . ' AND display_field = \'' . $this->dbi->escapeString($column)
64 . '\'';
65 $this->relation->queryAsControlUser($remove_query);
68 if (! $cfgRelation['relwork']) {
69 return;
72 $remove_query = 'DELETE FROM '
73 . Util::backquote($cfgRelation['db'])
74 . '.' . Util::backquote($cfgRelation['relation'])
75 . ' WHERE master_db = \'' . $this->dbi->escapeString($db)
76 . '\''
77 . ' AND master_table = \'' . $this->dbi->escapeString($table)
78 . '\''
79 . ' AND master_field = \'' . $this->dbi->escapeString($column)
80 . '\'';
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)
87 . '\''
88 . ' AND foreign_table = \'' . $this->dbi->escapeString($table)
89 . '\''
90 . ' AND foreign_field = \'' . $this->dbi->escapeString($column)
91 . '\'';
92 $this->relation->queryAsControlUser($remove_query);
95 /**
96 * Cleanup table related relation stuff
98 * @param string $db database name
99 * @param string $table table name
101 * @return void
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)
113 . '\'';
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)
123 . '\'';
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)
133 . '\'';
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)
142 . '\''
143 . ' AND master_table = \'' . $this->dbi->escapeString($table)
144 . '\'';
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)
151 . '\''
152 . ' AND foreign_table = \'' . $this->dbi->escapeString($table)
153 . '\'';
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)
163 . '\'';
164 $this->relation->queryAsControlUser($remove_query);
167 if (! $cfgRelation['navwork']) {
168 return;
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)
176 . '\''
177 . ' OR (item_name = \'' . $this->dbi->escapeString($table)
178 . '\''
179 . ' AND item_type = \'table\'))';
180 $this->relation->queryAsControlUser($remove_query);
184 * Cleanup database related relation stuff
186 * @param string $db database name
188 * @return void
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)
244 . '\'';
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']) {
273 return;
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
288 * @return void
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)
299 . "'";
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)
308 . "'";
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)
317 . "'";
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)
326 . "'";
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)
335 . "'";
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)
344 . "'";
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)
353 . "'";
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)
362 . "'";
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)
371 . "'";
372 $this->relation->queryAsControlUser($remove_query);
375 if (! $cfgRelation['designersettingswork']) {
376 return;
379 $remove_query = 'DELETE FROM '
380 . Util::backquote($cfgRelation['db'])
381 . '.' . Util::backquote($cfgRelation['designer_settings'])
382 . " WHERE `username` = '" . $this->dbi->escapeString($username)
383 . "'";
384 $this->relation->queryAsControlUser($remove_query);