123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <?php
- /* vim: set expandtab sw=4 ts=4 sts=4: */
- /**
- * Set of functions used for cleaning up phpMyAdmin tables
- *
- * @package PhpMyAdmin
- */
- namespace PhpMyAdmin;
- use PhpMyAdmin\Relation;
- use PhpMyAdmin\Util;
- /**
- * PhpMyAdmin\RelationCleanup class
- *
- * @package PhpMyAdmin
- */
- class RelationCleanup
- {
- /**
- * Cleanup column related relation stuff
- *
- * @param string $db database name
- * @param string $table table name
- * @param string $column column name
- *
- * @return void
- */
- public static function column($db, $table, $column)
- {
- $relation = new Relation();
- $cfgRelation = $relation->getRelationsParam();
- if ($cfgRelation['commwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['column_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' AND column_name = \'' . $GLOBALS['dbi']->escapeString($column)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['displaywork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' AND display_field = \'' . $GLOBALS['dbi']->escapeString($column)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['relwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db)
- . '\''
- . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' AND master_field = \'' . $GLOBALS['dbi']->escapeString($column)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db)
- . '\''
- . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' AND foreign_field = \'' . $GLOBALS['dbi']->escapeString($column)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- }
- /**
- * Cleanup table related relation stuff
- *
- * @param string $db database name
- * @param string $table table name
- *
- * @return void
- */
- public static function table($db, $table)
- {
- $relation = new Relation();
- $cfgRelation = $relation->getRelationsParam();
- if ($cfgRelation['commwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['column_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['displaywork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['pdfwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['relwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE master_db = \'' . $GLOBALS['dbi']->escapeString($db)
- . '\''
- . ' AND master_table = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db)
- . '\''
- . ' AND foreign_table = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['uiprefswork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_uiprefs'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['navwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['navigationhiding'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\''
- . ' AND (table_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' OR (item_name = \'' . $GLOBALS['dbi']->escapeString($table)
- . '\''
- . ' AND item_type = \'table\'))';
- $relation->queryAsControlUser($remove_query);
- }
- }
- /**
- * Cleanup database related relation stuff
- *
- * @param string $db database name
- *
- * @return void
- */
- public static function database($db)
- {
- $relation = new Relation();
- $cfgRelation = $relation->getRelationsParam();
- if ($cfgRelation['commwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['column_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['bookmarkwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['bookmark'])
- . ' WHERE dbase = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['displaywork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_info'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['pdfwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['pdf_pages'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_coords'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['relwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE master_db = \''
- . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation'])
- . ' WHERE foreign_db = \'' . $GLOBALS['dbi']->escapeString($db)
- . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['uiprefswork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_uiprefs'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['navwork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['navigationhiding'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['savedsearcheswork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['savedsearches'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['centralcolumnswork']) {
- $remove_query = 'DELETE FROM '
- . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['central_columns'])
- . ' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($db) . '\'';
- $relation->queryAsControlUser($remove_query);
- }
- }
- /**
- * Cleanup user related relation stuff
- *
- * @param string $username username
- *
- * @return void
- */
- public static function user($username)
- {
- $relation = new Relation();
- $cfgRelation = $relation->getRelationsParam();
- if ($cfgRelation['bookmarkwork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['bookmark'])
- . " WHERE `user` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['historywork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['history'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['recentwork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['recent'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['favoritework']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['favorite'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['uiprefswork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['table_uiprefs'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['userconfigwork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['userconfig'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['menuswork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['users'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['navwork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['navigationhiding'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['savedsearcheswork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['savedsearches'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- if ($cfgRelation['designersettingswork']) {
- $remove_query = "DELETE FROM "
- . Util::backquote($cfgRelation['db'])
- . "." . Util::backquote($cfgRelation['designer_settings'])
- . " WHERE `username` = '" . $GLOBALS['dbi']->escapeString($username)
- . "'";
- $relation->queryAsControlUser($remove_query);
- }
- }
- }
|