From 2ea46aa1131065125b45f2b3818a86d952a491a5 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 22:32:56 +0200 Subject: [PATCH 01/11] Ref #16906 - Return an error message if the pma storage db could not be selected Signed-off-by: William Desportes --- libraries/classes/Relation.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index f0d052f90d..f478897dbc 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2088,7 +2088,10 @@ class Relation if ($create) { if ($createQueries == null) { // first create $createQueries = $this->getDefaultPmaTableNames(); - $this->dbi->selectDb($db); + if (! $this->dbi->selectDb($db)) { + $GLOBALS['message'] = $this->dbi->getError(); + return; + } } $this->dbi->tryQuery($createQueries[$table]); From 9c0dcc20433497563e4a6623e5cf951a5bc36978 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 23:09:16 +0200 Subject: [PATCH 02/11] Fix #16906 - Use the control connection to create the storage database and tables Signed-off-by: William Desportes --- libraries/classes/Relation.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index f478897dbc..6a8dfdd3ec 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2023,10 +2023,11 @@ class Relation public function createPmaDatabase(string $configurationStorageDbName): bool { $this->dbi->tryQuery( - 'CREATE DATABASE IF NOT EXISTS ' . Util::backquote($configurationStorageDbName) + 'CREATE DATABASE IF NOT EXISTS ' . Util::backquote($configurationStorageDbName), + DatabaseInterface::CONNECT_CONTROL ); - $error = $this->dbi->getError(); + $error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); if (! $error) { return true; } @@ -2088,14 +2089,14 @@ class Relation if ($create) { if ($createQueries == null) { // first create $createQueries = $this->getDefaultPmaTableNames(); - if (! $this->dbi->selectDb($db)) { - $GLOBALS['message'] = $this->dbi->getError(); + if (! $this->dbi->selectDb($db, DatabaseInterface::CONNECT_CONTROL)) { + $GLOBALS['message'] = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); return; } } - $this->dbi->tryQuery($createQueries[$table]); + $this->dbi->tryQuery($createQueries[$table], DatabaseInterface::CONNECT_CONTROL); - $error = $this->dbi->getError(); + $error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); if ($error) { $GLOBALS['message'] = $error; From bb2c869e4cf3974b5fb4c88dd9b135f578b0c042 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 23:10:50 +0200 Subject: [PATCH 03/11] Ref #16906 - Clear the relation cache after the control db was created Signed-off-by: William Desportes --- libraries/classes/Relation.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index 6a8dfdd3ec..8345028437 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2029,6 +2029,10 @@ class Relation $error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); if (! $error) { + // Re-build the cache to show the list of tables created or not + // This is the case when the DB could be created but no tables just after + // So just purge the cache and show the new configuration storage state + $_SESSION['relation'][$GLOBALS['server']] = $this->checkRelationsParam(); return true; } From b527b13e2d0cbc949f07fffcd4878d805e4de9ba Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 23:23:22 +0200 Subject: [PATCH 04/11] Old typo fix Signed-off-by: William Desportes --- libraries/classes/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index 8345028437..55a00bc3c1 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -1762,7 +1762,7 @@ class Relation 'table_name' ); } else { - // if the table is moved out of the database we can no loger keep the + // if the table is moved out of the database we can no longer keep the // record for table coordinate $remove_query = 'DELETE FROM ' . Util::backquote($GLOBALS['cfgRelation']['db']) . '.' From c01e681c33150a6b1c50b0da044f144337bffe1c Mon Sep 17 00:00:00 2001 From: William Desportes Date: Fri, 27 Aug 2021 23:59:54 +0200 Subject: [PATCH 05/11] Prevent overriding user setting while auto fixing pma storage Once the table was created it was overriding the setting. It should respect that the user said the table will be named pma__userconfig_table and not pma__userconfig (the default value). If the database had the default tables in it, the detection would silently mark them as the right tables totally ignoring the user defined settings for the table names. Signed-off-by: William Desportes --- libraries/classes/Relation.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index 55a00bc3c1..f5f101ad0c 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2108,11 +2108,17 @@ class Relation } $foundOne = true; - $GLOBALS['cfg']['Server'][$feature] = $table; + if (empty($GLOBALS['cfg']['Server'][$feature])) { + // Do not override a user defined value, only fill if empty + $GLOBALS['cfg']['Server'][$feature] = $table; + } } } else { $foundOne = true; - $GLOBALS['cfg']['Server'][$feature] = $table; + if (empty($GLOBALS['cfg']['Server'][$feature])) { + // Do not override a user defined value, only fill if empty + $GLOBALS['cfg']['Server'][$feature] = $table; + } } } From 576decd1f4d4821af5382805e749ee5eb60da316 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Aug 2021 01:46:45 +0200 Subject: [PATCH 06/11] Fix coding standard issues Signed-off-by: William Desportes --- libraries/classes/Relation.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index f5f101ad0c..4ca22cb198 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -2033,6 +2033,7 @@ class Relation // This is the case when the DB could be created but no tables just after // So just purge the cache and show the new configuration storage state $_SESSION['relation'][$GLOBALS['server']] = $this->checkRelationsParam(); + return true; } @@ -2095,6 +2096,7 @@ class Relation $createQueries = $this->getDefaultPmaTableNames(); if (! $this->dbi->selectDb($db, DatabaseInterface::CONNECT_CONTROL)) { $GLOBALS['message'] = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); + return; } } @@ -2302,6 +2304,7 @@ class Relation global $cfg; $cfgStorageDbName = $cfg['Server']['pmadb'] ?? ''; + // Use "phpmyadmin" as a default database name to check to keep the behavior consistent return empty($cfgStorageDbName) ? 'phpmyadmin' : $cfgStorageDbName; } From c775db6b4d3dac88f588e23495661f8b167e41c0 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Aug 2021 02:16:12 +0200 Subject: [PATCH 07/11] Ref #16906 - Add tests for Relation::getDefaultPmaTableNames Signed-off-by: William Desportes --- test/classes/RelationTest.php | 397 ++++++++++++++++++++++++++++++++++ 1 file changed, 397 insertions(+) diff --git a/test/classes/RelationTest.php b/test/classes/RelationTest.php index fd7e768025..95b79f9d63 100644 --- a/test/classes/RelationTest.php +++ b/test/classes/RelationTest.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Tests; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Relation; +use function implode; /** * @group medium @@ -879,4 +880,400 @@ class RelationTest extends AbstractTestCase $this->assertAllQueriesConsumed(); $this->assertAllErrorCodesConsumed(); } + + public function testGetDefaultPmaTableNames(): void + { + $this->relation = new Relation(null); + + $this->assertSame( + [ + 'pma__bookmark' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__bookmark`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__bookmark` (', + ' `id` int(10) unsigned NOT NULL auto_increment,', + ' `dbase` varchar(255) NOT NULL default \'\',', + ' `user` varchar(255) NOT NULL default \'\',', + ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `query` text NOT NULL,', + ' PRIMARY KEY (`id`)', + ')', + ' COMMENT=\'Bookmarks\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__column_info' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__column_info`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__column_info` (', + ' `id` int(5) unsigned NOT NULL auto_increment,', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `column_name` varchar(64) NOT NULL default \'\',', + ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `transformation` varchar(255) NOT NULL default \'\',', + ' `transformation_options` varchar(255) NOT NULL default \'\',', + ' `input_transformation` varchar(255) NOT NULL default \'\',', + ' `input_transformation_options` varchar(255) NOT NULL default \'\',', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)', + ')', + ' COMMENT=\'Column information for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__history' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__history`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__history` (', + ' `id` bigint(20) unsigned NOT NULL auto_increment,', + ' `username` varchar(64) NOT NULL default \'\',', + ' `db` varchar(64) NOT NULL default \'\',', + ' `table` varchar(64) NOT NULL default \'\',', + ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,', + ' `sqlquery` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' KEY `username` (`username`,`db`,`table`,`timevalue`)', + ')', + ' COMMENT=\'SQL history for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__pdf_pages' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__pdf_pages`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `page_nr` int(10) unsigned NOT NULL auto_increment,', + ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',', + ' PRIMARY KEY (`page_nr`),', + ' KEY `db_name` (`db_name`)', + ')', + ' COMMENT=\'PDF relation pages for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__recent' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__recent`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__recent` (', + ' `username` varchar(64) NOT NULL,', + ' `tables` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Recently accessed tables\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__favorite' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__favorite`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__favorite` (', + ' `username` varchar(64) NOT NULL,', + ' `tables` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Favorite tables\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_uiprefs' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_uiprefs`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (', + ' `username` varchar(64) NOT NULL,', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' `prefs` text NOT NULL,', + ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', + ' PRIMARY KEY (`username`,`db_name`,`table_name`)', + ')', + ' COMMENT=\'Tables\'\' UI preferences\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__relation' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__relation`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__relation` (', + ' `master_db` varchar(64) NOT NULL default \'\',', + ' `master_table` varchar(64) NOT NULL default \'\',', + ' `master_field` varchar(64) NOT NULL default \'\',', + ' `foreign_db` varchar(64) NOT NULL default \'\',', + ' `foreign_table` varchar(64) NOT NULL default \'\',', + ' `foreign_field` varchar(64) NOT NULL default \'\',', + ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),', + ' KEY `foreign_field` (`foreign_db`,`foreign_table`)', + ')', + ' COMMENT=\'Relation table\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_coords' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_coords`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_coords` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `pdf_page_number` int(11) NOT NULL default \'0\',', + ' `x` float unsigned NOT NULL default \'0\',', + ' `y` float unsigned NOT NULL default \'0\',', + ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)', + ')', + ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_info' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_info`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_info` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `display_field` varchar(64) NOT NULL default \'\',', + ' PRIMARY KEY (`db_name`,`table_name`)', + ')', + ' COMMENT=\'Table information for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__tracking' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__tracking`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__tracking` (', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' `version` int(10) unsigned NOT NULL,', + ' `date_created` datetime NOT NULL,', + ' `date_updated` datetime NOT NULL,', + ' `schema_snapshot` text NOT NULL,', + ' `schema_sql` text,', + ' `data_sql` longtext,', + ' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' + . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\',' + . '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\',' + . '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',' + . '\'DROP VIEW\') default NULL,', + ' `tracking_active` int(1) unsigned NOT NULL default \'1\',', + ' PRIMARY KEY (`db_name`,`table_name`,`version`)', + ')', + ' COMMENT=\'Database changes tracking for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__userconfig' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__userconfig`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__userconfig` (', + ' `username` varchar(64) NOT NULL,', + ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', + ' `config_data` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'User preferences storage for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__users' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__users`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__users` (', + ' `username` varchar(64) NOT NULL,', + ' `usergroup` varchar(64) NOT NULL,', + ' PRIMARY KEY (`username`,`usergroup`)', + ')', + ' COMMENT=\'Users and their assignments to user groups\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__usergroups' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__usergroups`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__usergroups` (', + ' `usergroup` varchar(64) NOT NULL,', + ' `tab` varchar(64) NOT NULL,', + ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',', + ' PRIMARY KEY (`usergroup`,`tab`,`allowed`)', + ')', + ' COMMENT=\'User groups with configured menu items\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__navigationhiding' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__navigationhiding`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (', + ' `username` varchar(64) NOT NULL,', + ' `item_name` varchar(64) NOT NULL,', + ' `item_type` varchar(64) NOT NULL,', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)', + ')', + ' COMMENT=\'Hidden items of navigation tree\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__savedsearches' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__savedsearches`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (', + ' `id` int(5) unsigned NOT NULL auto_increment,', + ' `username` varchar(64) NOT NULL default \'\',', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `search_name` varchar(64) NOT NULL default \'\',', + ' `search_data` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)', + ')', + ' COMMENT=\'Saved searches\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__central_columns' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__central_columns`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__central_columns` (', + ' `db_name` varchar(64) NOT NULL,', + ' `col_name` varchar(64) NOT NULL,', + ' `col_type` varchar(64) NOT NULL,', + ' `col_length` text,', + ' `col_collation` varchar(64) NOT NULL,', + ' `col_isNull` boolean NOT NULL,', + ' `col_extra` varchar(255) default \'\',', + ' `col_default` text,', + ' PRIMARY KEY (`db_name`,`col_name`)', + ')', + ' COMMENT=\'Central list of columns\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__designer_settings' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__designer_settings`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (', + ' `username` varchar(64) NOT NULL,', + ' `settings_data` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Settings related to Designer\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__export_templates' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__export_templates`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__export_templates` (', + ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', + ' `username` varchar(64) NOT NULL,', + ' `export_type` varchar(10) NOT NULL,', + ' `template_name` varchar(64) NOT NULL,', + ' `template_data` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', + ')', + ' COMMENT=\'Saved export templates\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + ], + $this->relation->getDefaultPmaTableNames() + ); + } } From b0ec0fd11209d28b3d54139701c0a84c4b5ae796 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Aug 2021 03:55:02 +0200 Subject: [PATCH 08/11] Fix #16906 - Replace table names with the configuration ones while creating the storage tables Signed-off-by: William Desportes --- libraries/classes/Relation.php | 37 +- test/classes/DatabaseInterfaceTest.php | 27 +- test/classes/RelationTest.php | 1112 +++++++++++++++--------- 3 files changed, 780 insertions(+), 396 deletions(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index 4ca22cb198..cfc516b60d 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -1990,9 +1990,9 @@ class Relation /** * Returns default PMA table names and their create queries. * - * @return array table name, create query + * @return array table name, create query */ - public function getDefaultPmaTableNames() + public function getDefaultPmaTableNames(array $tableNameReplacements): array { $pma_tables = []; $create_tables_file = (string) file_get_contents( @@ -2011,7 +2011,14 @@ class Relation continue; } - $pma_tables[$table[1]] = $query . ';'; + $tableName = (string) $table[1]; + + // Replace the table name with another one + if (isset($tableNameReplacements[$tableName])) { + $query = str_replace($tableName, $tableNameReplacements[$tableName], $query); + } + + $pma_tables[$tableName] = $query . ';'; } return $pma_tables; @@ -2087,13 +2094,33 @@ class Relation $existingTables = $this->dbi->getTables($db, DatabaseInterface::CONNECT_CONTROL); + /** @var array $tableNameReplacements */ + $tableNameReplacements = []; + + // Build a map of replacements between default table names and name built by the user + foreach ($tablesToFeatures as $table => $feature) { + // Empty, we can not do anything about it + if (empty($GLOBALS['cfg']['Server'][$feature])) { + continue; + } + // Default table name, nothing to do + if ($GLOBALS['cfg']['Server'][$feature] === $table) { + continue; + } + // Set the replacement to transform the default table name into a custom name + $tableNameReplacements[$table] = $GLOBALS['cfg']['Server'][$feature]; + } + $createQueries = null; $foundOne = false; foreach ($tablesToFeatures as $table => $feature) { - if (! in_array($table, $existingTables)) { + // Check if the table already exists + // use the possible replaced name first and fallback on the table name + // if no replacement exists + if (! in_array($tableNameReplacements[$table] ?? $table, $existingTables)) { if ($create) { if ($createQueries == null) { // first create - $createQueries = $this->getDefaultPmaTableNames(); + $createQueries = $this->getDefaultPmaTableNames($tableNameReplacements); if (! $this->dbi->selectDb($db, DatabaseInterface::CONNECT_CONTROL)) { $GLOBALS['message'] = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL); diff --git a/test/classes/DatabaseInterfaceTest.php b/test/classes/DatabaseInterfaceTest.php index ec7f604c0f..c7e20192f7 100644 --- a/test/classes/DatabaseInterfaceTest.php +++ b/test/classes/DatabaseInterfaceTest.php @@ -776,11 +776,32 @@ class DatabaseInterfaceTest extends AbstractTestCase $this->dbi->initRelationParamsCache(); - $this->assertArrayNotHasKey( + $this->assertArrayHasKey( 'relation', $_SESSION, - 'The cache is NOT expected to be filled because no default phpMyAdmin storage tables' - . ' with a default name where found (pma__userconfig vs pma__userconfig_custom)' + 'The cache is expected to be filled because the custom override' + . 'was undertood (pma__userconfig vs pma__userconfig_custom)' + ); + + $this->assertAllQueriesConsumed(); + + $this->dummyDbi->addResult( + 'SHOW TABLES FROM `PMA-storage`', + [ + [ + 'pma__userconfig_custom', + 'pma__usergroups', + ], + ], + ['Tables_in_PMA-storage'] + ); + + $this->dummyDbi->addResult( + 'SELECT NULL FROM pma__userconfig_custom LIMIT 0', + [ + ['NULL'], + ], + ['NULL'] ); $relationData = (new Relation($this->dbi))->checkRelationsParam(); diff --git a/test/classes/RelationTest.php b/test/classes/RelationTest.php index 95b79f9d63..180b259867 100644 --- a/test/classes/RelationTest.php +++ b/test/classes/RelationTest.php @@ -724,6 +724,308 @@ class RelationTest extends AbstractTestCase $this->assertAllQueriesConsumed(); } + public function testFixPmaTablesNormalFixTablesWithCustomOverride(): void + { + parent::setGlobalDbi(); + parent::loadDefaultConfig(); + + $GLOBALS['db'] = ''; + $GLOBALS['server'] = 1; + $GLOBALS['cfg']['Server']['user'] = ''; + $GLOBALS['cfg']['Server']['pmadb'] = 'db_pma'; + $GLOBALS['cfg']['Server']['bookmarktable'] = ''; + $GLOBALS['cfg']['Server']['relation'] = 'custom_relation_pma'; + $GLOBALS['cfg']['Server']['table_info'] = ''; + $GLOBALS['cfg']['Server']['table_coords'] = ''; + $GLOBALS['cfg']['Server']['column_info'] = ''; + $GLOBALS['cfg']['Server']['pdf_pages'] = ''; + $GLOBALS['cfg']['Server']['history'] = ''; + $GLOBALS['cfg']['Server']['recent'] = ''; + $GLOBALS['cfg']['Server']['favorite'] = ''; + $GLOBALS['cfg']['Server']['table_uiprefs'] = ''; + $GLOBALS['cfg']['Server']['tracking'] = ''; + $GLOBALS['cfg']['Server']['userconfig'] = ''; + $GLOBALS['cfg']['Server']['users'] = ''; + $GLOBALS['cfg']['Server']['usergroups'] = ''; + $GLOBALS['cfg']['Server']['navigationhiding'] = ''; + $GLOBALS['cfg']['Server']['savedsearches'] = ''; + $GLOBALS['cfg']['Server']['central_columns'] = ''; + $GLOBALS['cfg']['Server']['designer_settings'] = ''; + $GLOBALS['cfg']['Server']['export_templates'] = ''; + + $this->relation = new Relation($this->dbi); + + $this->dummyDbi->removeDefaultResults(); + $this->dummyDbi->addResult( + 'SHOW TABLES FROM `db_pma`;', + [ + ['pma__userconfig'], + // This is important as it tricks default existing table detection + // If the check does not consider the custom name it will skip the table + ['pma__relation'], + ], + ['Tables_in_db_pma'] + ); + + $this->dummyDbi->addResult( + 'SHOW TABLES FROM `db_pma`', + [ + ['pma__userconfig'], + // This is important as it tricks default existing table detection + // If the check does not consider the custom name it will skip the table + ['pma__relation'], + ], + ['Tables_in_db_pma'] + ); + + $this->dummyDbi->addResult( + 'SELECT NULL FROM pma__userconfig LIMIT 0', + [['NULL']] + ); + + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__bookmark` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( ' + . '`id` int(10) unsigned NOT NULL auto_increment,' + . ' `dbase` varchar(255) NOT NULL default \'\',' + . ' `user` varchar(255) NOT NULL default \'\',' + . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' + . ' `query` text NOT NULL, PRIMARY KEY (`id`) )' + . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `custom_relation_pma` ' + . '-- CREATE TABLE IF NOT EXISTS `custom_relation_pma` ( ' + . '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\',' + . ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\',' + . ' `foreign_table` varchar(64) NOT NULL default \'\',' + . ' `foreign_field` varchar(64) NOT NULL default \'\',' + . ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),' + . ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__table_info`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( ' + . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' + . ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )' + . ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__table_coords`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( ' + . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' + . ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\',' + . ' `y` float unsigned NOT NULL default \'0\',' + . ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )' + . ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__pdf_pages`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( ' + . '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,' + . ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),' + . ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__column_info`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( ' + . '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\',' + . ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\',' + . ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' + . ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' + . ' `transformation` varchar(255) NOT NULL default \'\',' + . ' `transformation_options` varchar(255) NOT NULL default \'\',' + . ' `input_transformation` varchar(255) NOT NULL default \'\',' + . ' `input_transformation_options` varchar(255) NOT NULL default \'\',' + . ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )' + . ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__history` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__history` ( ' + . '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' + . ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\',' + . ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,' + . ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )' + . ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__recent` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( ' + . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' + . ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__favorite` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( ' + . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' + . ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__table_uiprefs`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( ' + . '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' + . ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,' + . ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' + . ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__tracking` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( ' + . '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,' + . ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,' + . ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,' + . ' `schema_sql` text, `data_sql` longtext, `tracking`' + . ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' + . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',' + . '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\',' + . '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\',' + . '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')' + . ' default NULL, `tracking_active` int(1) unsigned NOT NULL' + . ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )' + . ' COMMENT=\'Database changes tracking for phpMyAdmin\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__users` ' + . '-- CREATE TABLE IF NOT EXISTS `pma__users` ( ' + . '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,' + . ' PRIMARY KEY (`username`,`usergroup`) )' + . ' COMMENT=\'Users and their assignments to user groups\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__usergroups`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( ' + . '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,' + . ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',' + . ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )' + . ' COMMENT=\'User groups with configured menu items\'' + . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__navigationhiding`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( ' + . '`username` varchar(64) NOT NULL, `item_name` varchar(64)' + . ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' + . ' `table_name` varchar(64) NOT NULL,' + . ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )' + . ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__savedsearches`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( ' + . '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' + . ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\',' + . ' `search_data` text NOT NULL, PRIMARY KEY (`id`),' + . ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )' + . ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__central_columns`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( ' + . '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,' + . ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,' + . ' `col_extra` varchar(255) default \'\', `col_default` text,' + . ' PRIMARY KEY (`db_name`,`col_name`) )' + . ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__designer_settings`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( ' + . '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,' + . ' PRIMARY KEY (`username`) )' + . ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + $this->dummyDbi->addResult( + '-- -------------------------------------------------------- -- --' + . ' Table structure for table `pma__export_templates`' + . ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( ' + . '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,' + . ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,' + . ' `template_data` text NOT NULL, PRIMARY KEY (`id`),' + . ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )' + . ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + [] + ); + + $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']); + $this->assertArrayHasKey('relation', $_SESSION, 'The cache is expected to be filled'); + $this->assertSame([], $_SESSION['relation']); + + $this->relation->fixPmaTables('db_pma', true); + $this->assertArrayNotHasKey('message', $GLOBALS); + $this->assertArrayHasKey('relation', $_SESSION, 'The cache is expected to be filled'); + $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']); + + $this->assertSame([ + 'PMA_VERSION' => $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'], + 'relwork' => false, + 'displaywork' => false, + 'bookmarkwork' => false, + 'pdfwork' => false, + 'commwork' => false, + 'mimework' => false, + 'historywork' => false, + 'recentwork' => false, + 'favoritework' => false, + 'uiprefswork' => false, + 'trackingwork' => false, + 'userconfigwork' => true,// The only one than has a table and passes check + 'menuswork' => false, + 'navwork' => false, + 'savedsearcheswork' => false, + 'centralcolumnswork' => false, + 'designersettingswork' => false, + 'exporttemplateswork' => false, + 'allworks' => false, + 'user' => '', + 'db' => 'db_pma', + 'userconfig' => 'pma__userconfig', + ], $_SESSION['relation'][$GLOBALS['server']]); + + $this->assertAllQueriesConsumed(); + } + public function testFixPmaTablesNormalFixTablesFails(): void { parent::setGlobalDbi(); @@ -809,6 +1111,11 @@ class RelationTest extends AbstractTestCase [] ); + $this->dummyDbi->addResult( + 'SHOW TABLES FROM `phpmyadmin`', + [] + ); + $this->assertArrayNotHasKey('errno', $GLOBALS); $this->assertTrue( @@ -885,395 +1192,424 @@ class RelationTest extends AbstractTestCase { $this->relation = new Relation(null); + $data = [ + 'pma__bookmark' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__bookmark`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__bookmark` (', + ' `id` int(10) unsigned NOT NULL auto_increment,', + ' `dbase` varchar(255) NOT NULL default \'\',', + ' `user` varchar(255) NOT NULL default \'\',', + ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `query` text NOT NULL,', + ' PRIMARY KEY (`id`)', + ')', + ' COMMENT=\'Bookmarks\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__column_info' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__column_info`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__column_info` (', + ' `id` int(5) unsigned NOT NULL auto_increment,', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `column_name` varchar(64) NOT NULL default \'\',', + ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', + ' `transformation` varchar(255) NOT NULL default \'\',', + ' `transformation_options` varchar(255) NOT NULL default \'\',', + ' `input_transformation` varchar(255) NOT NULL default \'\',', + ' `input_transformation_options` varchar(255) NOT NULL default \'\',', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)', + ')', + ' COMMENT=\'Column information for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__history' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__history`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__history` (', + ' `id` bigint(20) unsigned NOT NULL auto_increment,', + ' `username` varchar(64) NOT NULL default \'\',', + ' `db` varchar(64) NOT NULL default \'\',', + ' `table` varchar(64) NOT NULL default \'\',', + ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,', + ' `sqlquery` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' KEY `username` (`username`,`db`,`table`,`timevalue`)', + ')', + ' COMMENT=\'SQL history for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__pdf_pages' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__pdf_pages`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `page_nr` int(10) unsigned NOT NULL auto_increment,', + ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',', + ' PRIMARY KEY (`page_nr`),', + ' KEY `db_name` (`db_name`)', + ')', + ' COMMENT=\'PDF relation pages for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__recent' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__recent`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__recent` (', + ' `username` varchar(64) NOT NULL,', + ' `tables` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Recently accessed tables\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__favorite' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__favorite`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__favorite` (', + ' `username` varchar(64) NOT NULL,', + ' `tables` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Favorite tables\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_uiprefs' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_uiprefs`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (', + ' `username` varchar(64) NOT NULL,', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' `prefs` text NOT NULL,', + ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', + ' PRIMARY KEY (`username`,`db_name`,`table_name`)', + ')', + ' COMMENT=\'Tables\'\' UI preferences\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__relation' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__relation`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__relation` (', + ' `master_db` varchar(64) NOT NULL default \'\',', + ' `master_table` varchar(64) NOT NULL default \'\',', + ' `master_field` varchar(64) NOT NULL default \'\',', + ' `foreign_db` varchar(64) NOT NULL default \'\',', + ' `foreign_table` varchar(64) NOT NULL default \'\',', + ' `foreign_field` varchar(64) NOT NULL default \'\',', + ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),', + ' KEY `foreign_field` (`foreign_db`,`foreign_table`)', + ')', + ' COMMENT=\'Relation table\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_coords' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_coords`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_coords` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `pdf_page_number` int(11) NOT NULL default \'0\',', + ' `x` float unsigned NOT NULL default \'0\',', + ' `y` float unsigned NOT NULL default \'0\',', + ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)', + ')', + ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__table_info' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__table_info`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__table_info` (', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `table_name` varchar(64) NOT NULL default \'\',', + ' `display_field` varchar(64) NOT NULL default \'\',', + ' PRIMARY KEY (`db_name`,`table_name`)', + ')', + ' COMMENT=\'Table information for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__tracking' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__tracking`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__tracking` (', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' `version` int(10) unsigned NOT NULL,', + ' `date_created` datetime NOT NULL,', + ' `date_updated` datetime NOT NULL,', + ' `schema_snapshot` text NOT NULL,', + ' `schema_sql` text,', + ' `data_sql` longtext,', + ' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' + . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\',' + . '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\',' + . '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',' + . '\'DROP VIEW\') default NULL,', + ' `tracking_active` int(1) unsigned NOT NULL default \'1\',', + ' PRIMARY KEY (`db_name`,`table_name`,`version`)', + ')', + ' COMMENT=\'Database changes tracking for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__userconfig' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__userconfig`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__userconfig` (', + ' `username` varchar(64) NOT NULL,', + ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', + ' `config_data` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'User preferences storage for phpMyAdmin\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__users' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__users`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__users` (', + ' `username` varchar(64) NOT NULL,', + ' `usergroup` varchar(64) NOT NULL,', + ' PRIMARY KEY (`username`,`usergroup`)', + ')', + ' COMMENT=\'Users and their assignments to user groups\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__usergroups' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__usergroups`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__usergroups` (', + ' `usergroup` varchar(64) NOT NULL,', + ' `tab` varchar(64) NOT NULL,', + ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',', + ' PRIMARY KEY (`usergroup`,`tab`,`allowed`)', + ')', + ' COMMENT=\'User groups with configured menu items\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__navigationhiding' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__navigationhiding`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (', + ' `username` varchar(64) NOT NULL,', + ' `item_name` varchar(64) NOT NULL,', + ' `item_type` varchar(64) NOT NULL,', + ' `db_name` varchar(64) NOT NULL,', + ' `table_name` varchar(64) NOT NULL,', + ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)', + ')', + ' COMMENT=\'Hidden items of navigation tree\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__savedsearches' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__savedsearches`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (', + ' `id` int(5) unsigned NOT NULL auto_increment,', + ' `username` varchar(64) NOT NULL default \'\',', + ' `db_name` varchar(64) NOT NULL default \'\',', + ' `search_name` varchar(64) NOT NULL default \'\',', + ' `search_data` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)', + ')', + ' COMMENT=\'Saved searches\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__central_columns' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__central_columns`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__central_columns` (', + ' `db_name` varchar(64) NOT NULL,', + ' `col_name` varchar(64) NOT NULL,', + ' `col_type` varchar(64) NOT NULL,', + ' `col_length` text,', + ' `col_collation` varchar(64) NOT NULL,', + ' `col_isNull` boolean NOT NULL,', + ' `col_extra` varchar(255) default \'\',', + ' `col_default` text,', + ' PRIMARY KEY (`db_name`,`col_name`)', + ')', + ' COMMENT=\'Central list of columns\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__designer_settings' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__designer_settings`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (', + ' `username` varchar(64) NOT NULL,', + ' `settings_data` text NOT NULL,', + ' PRIMARY KEY (`username`)', + ')', + ' COMMENT=\'Settings related to Designer\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + 'pma__export_templates' => implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `pma__export_templates`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `pma__export_templates` (', + ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', + ' `username` varchar(64) NOT NULL,', + ' `export_type` varchar(10) NOT NULL,', + ' `template_name` varchar(64) NOT NULL,', + ' `template_data` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', + ')', + ' COMMENT=\'Saved export templates\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]), + ]; + $this->assertSame( - [ - 'pma__bookmark' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__bookmark`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__bookmark` (', - ' `id` int(10) unsigned NOT NULL auto_increment,', - ' `dbase` varchar(255) NOT NULL default \'\',', - ' `user` varchar(255) NOT NULL default \'\',', - ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', - ' `query` text NOT NULL,', - ' PRIMARY KEY (`id`)', - ')', - ' COMMENT=\'Bookmarks\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__column_info' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__column_info`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__column_info` (', - ' `id` int(5) unsigned NOT NULL auto_increment,', - ' `db_name` varchar(64) NOT NULL default \'\',', - ' `table_name` varchar(64) NOT NULL default \'\',', - ' `column_name` varchar(64) NOT NULL default \'\',', - ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', - ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', - ' `transformation` varchar(255) NOT NULL default \'\',', - ' `transformation_options` varchar(255) NOT NULL default \'\',', - ' `input_transformation` varchar(255) NOT NULL default \'\',', - ' `input_transformation_options` varchar(255) NOT NULL default \'\',', - ' PRIMARY KEY (`id`),', - ' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)', - ')', - ' COMMENT=\'Column information for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__history' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__history`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__history` (', - ' `id` bigint(20) unsigned NOT NULL auto_increment,', - ' `username` varchar(64) NOT NULL default \'\',', - ' `db` varchar(64) NOT NULL default \'\',', - ' `table` varchar(64) NOT NULL default \'\',', - ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,', - ' `sqlquery` text NOT NULL,', - ' PRIMARY KEY (`id`),', - ' KEY `username` (`username`,`db`,`table`,`timevalue`)', - ')', - ' COMMENT=\'SQL history for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__pdf_pages' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__pdf_pages`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (', - ' `db_name` varchar(64) NOT NULL default \'\',', - ' `page_nr` int(10) unsigned NOT NULL auto_increment,', - ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',', - ' PRIMARY KEY (`page_nr`),', - ' KEY `db_name` (`db_name`)', - ')', - ' COMMENT=\'PDF relation pages for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__recent' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__recent`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__recent` (', - ' `username` varchar(64) NOT NULL,', - ' `tables` text NOT NULL,', - ' PRIMARY KEY (`username`)', - ')', - ' COMMENT=\'Recently accessed tables\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__favorite' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__favorite`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__favorite` (', - ' `username` varchar(64) NOT NULL,', - ' `tables` text NOT NULL,', - ' PRIMARY KEY (`username`)', - ')', - ' COMMENT=\'Favorite tables\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__table_uiprefs' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__table_uiprefs`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (', - ' `username` varchar(64) NOT NULL,', - ' `db_name` varchar(64) NOT NULL,', - ' `table_name` varchar(64) NOT NULL,', - ' `prefs` text NOT NULL,', - ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', - ' PRIMARY KEY (`username`,`db_name`,`table_name`)', - ')', - ' COMMENT=\'Tables\'\' UI preferences\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__relation' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__relation`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__relation` (', - ' `master_db` varchar(64) NOT NULL default \'\',', - ' `master_table` varchar(64) NOT NULL default \'\',', - ' `master_field` varchar(64) NOT NULL default \'\',', - ' `foreign_db` varchar(64) NOT NULL default \'\',', - ' `foreign_table` varchar(64) NOT NULL default \'\',', - ' `foreign_field` varchar(64) NOT NULL default \'\',', - ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),', - ' KEY `foreign_field` (`foreign_db`,`foreign_table`)', - ')', - ' COMMENT=\'Relation table\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__table_coords' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__table_coords`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__table_coords` (', - ' `db_name` varchar(64) NOT NULL default \'\',', - ' `table_name` varchar(64) NOT NULL default \'\',', - ' `pdf_page_number` int(11) NOT NULL default \'0\',', - ' `x` float unsigned NOT NULL default \'0\',', - ' `y` float unsigned NOT NULL default \'0\',', - ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)', - ')', - ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__table_info' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__table_info`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__table_info` (', - ' `db_name` varchar(64) NOT NULL default \'\',', - ' `table_name` varchar(64) NOT NULL default \'\',', - ' `display_field` varchar(64) NOT NULL default \'\',', - ' PRIMARY KEY (`db_name`,`table_name`)', - ')', - ' COMMENT=\'Table information for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__tracking' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__tracking`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__tracking` (', - ' `db_name` varchar(64) NOT NULL,', - ' `table_name` varchar(64) NOT NULL,', - ' `version` int(10) unsigned NOT NULL,', - ' `date_created` datetime NOT NULL,', - ' `date_updated` datetime NOT NULL,', - ' `schema_snapshot` text NOT NULL,', - ' `schema_sql` text,', - ' `data_sql` longtext,', - ' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' - . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\',' - . '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\',' - . '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',' - . '\'DROP VIEW\') default NULL,', - ' `tracking_active` int(1) unsigned NOT NULL default \'1\',', - ' PRIMARY KEY (`db_name`,`table_name`,`version`)', - ')', - ' COMMENT=\'Database changes tracking for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__userconfig' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__userconfig`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__userconfig` (', - ' `username` varchar(64) NOT NULL,', - ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', - ' `config_data` text NOT NULL,', - ' PRIMARY KEY (`username`)', - ')', - ' COMMENT=\'User preferences storage for phpMyAdmin\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__users' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__users`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__users` (', - ' `username` varchar(64) NOT NULL,', - ' `usergroup` varchar(64) NOT NULL,', - ' PRIMARY KEY (`username`,`usergroup`)', - ')', - ' COMMENT=\'Users and their assignments to user groups\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__usergroups' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__usergroups`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__usergroups` (', - ' `usergroup` varchar(64) NOT NULL,', - ' `tab` varchar(64) NOT NULL,', - ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',', - ' PRIMARY KEY (`usergroup`,`tab`,`allowed`)', - ')', - ' COMMENT=\'User groups with configured menu items\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__navigationhiding' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__navigationhiding`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (', - ' `username` varchar(64) NOT NULL,', - ' `item_name` varchar(64) NOT NULL,', - ' `item_type` varchar(64) NOT NULL,', - ' `db_name` varchar(64) NOT NULL,', - ' `table_name` varchar(64) NOT NULL,', - ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)', - ')', - ' COMMENT=\'Hidden items of navigation tree\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__savedsearches' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__savedsearches`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (', - ' `id` int(5) unsigned NOT NULL auto_increment,', - ' `username` varchar(64) NOT NULL default \'\',', - ' `db_name` varchar(64) NOT NULL default \'\',', - ' `search_name` varchar(64) NOT NULL default \'\',', - ' `search_data` text NOT NULL,', - ' PRIMARY KEY (`id`),', - ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)', - ')', - ' COMMENT=\'Saved searches\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__central_columns' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__central_columns`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__central_columns` (', - ' `db_name` varchar(64) NOT NULL,', - ' `col_name` varchar(64) NOT NULL,', - ' `col_type` varchar(64) NOT NULL,', - ' `col_length` text,', - ' `col_collation` varchar(64) NOT NULL,', - ' `col_isNull` boolean NOT NULL,', - ' `col_extra` varchar(255) default \'\',', - ' `col_default` text,', - ' PRIMARY KEY (`db_name`,`col_name`)', - ')', - ' COMMENT=\'Central list of columns\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__designer_settings' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__designer_settings`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (', - ' `username` varchar(64) NOT NULL,', - ' `settings_data` text NOT NULL,', - ' PRIMARY KEY (`username`)', - ')', - ' COMMENT=\'Settings related to Designer\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - 'pma__export_templates' => implode("\n", [ - '', - '', - '-- --------------------------------------------------------', - '', - '--', - '-- Table structure for table `pma__export_templates`', - '--', - '', - 'CREATE TABLE IF NOT EXISTS `pma__export_templates` (', - ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', - ' `username` varchar(64) NOT NULL,', - ' `export_type` varchar(10) NOT NULL,', - ' `template_name` varchar(64) NOT NULL,', - ' `template_data` text NOT NULL,', - ' PRIMARY KEY (`id`),', - ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', - ')', - ' COMMENT=\'Saved export templates\'', - ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', - ]), - ], - $this->relation->getDefaultPmaTableNames() + $data, + $this->relation->getDefaultPmaTableNames([]) + ); + + $data['pma__export_templates'] = implode("\n", [ + '', + '', + '-- --------------------------------------------------------', + '', + '--', + '-- Table structure for table `db_exporttemplates_pma`', + '--', + '', + 'CREATE TABLE IF NOT EXISTS `db_exporttemplates_pma` (', + ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', + ' `username` varchar(64) NOT NULL,', + ' `export_type` varchar(10) NOT NULL,', + ' `template_name` varchar(64) NOT NULL,', + ' `template_data` text NOT NULL,', + ' PRIMARY KEY (`id`),', + ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', + ')', + ' COMMENT=\'Saved export templates\'', + ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', + ]); + + $this->assertSame( + $data, + $this->relation->getDefaultPmaTableNames(['pma__export_templates' => 'db_exporttemplates_pma']) ); } } From dc5cf4766b52f1d04528cb53c204678263fcfbc4 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Aug 2021 04:06:18 +0200 Subject: [PATCH 09/11] Fix #16906 - Escape the table name that is checked with backquotes on canAccessStorageTable function Signed-off-by: William Desportes --- libraries/classes/Relation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Relation.php b/libraries/classes/Relation.php index cfc516b60d..d0dfd0ff92 100644 --- a/libraries/classes/Relation.php +++ b/libraries/classes/Relation.php @@ -729,7 +729,7 @@ class Relation public function canAccessStorageTable(string $tableDbName): bool { $result = $this->queryAsControlUser( - 'SELECT NULL FROM ' . $tableDbName . ' LIMIT 0', + 'SELECT NULL FROM ' . Util::backquote($tableDbName) . ' LIMIT 0', false, DatabaseInterface::QUERY_STORE ); From 2b177839bf8ed044222e25ec51bbefb908dc57dd Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Aug 2021 04:08:11 +0200 Subject: [PATCH 10/11] Fix tests after dc5cf4766b Signed-off-by: William Desportes --- test/classes/DatabaseInterfaceTest.php | 8 ++++---- test/classes/RelationTest.php | 6 +++--- test/classes/TwoFactorTest.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/classes/DatabaseInterfaceTest.php b/test/classes/DatabaseInterfaceTest.php index c7e20192f7..1adcab5fa5 100644 --- a/test/classes/DatabaseInterfaceTest.php +++ b/test/classes/DatabaseInterfaceTest.php @@ -543,7 +543,7 @@ class DatabaseInterfaceTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', [ ['NULL'], ], @@ -654,7 +654,7 @@ class DatabaseInterfaceTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', false ); @@ -767,7 +767,7 @@ class DatabaseInterfaceTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig_custom LIMIT 0', + 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0', [ ['NULL'], ], @@ -797,7 +797,7 @@ class DatabaseInterfaceTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig_custom LIMIT 0', + 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0', [ ['NULL'], ], diff --git a/test/classes/RelationTest.php b/test/classes/RelationTest.php index 180b259867..b8a7760afb 100644 --- a/test/classes/RelationTest.php +++ b/test/classes/RelationTest.php @@ -388,7 +388,7 @@ class RelationTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', [['NULL']] ); @@ -477,7 +477,7 @@ class RelationTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', [['NULL']] ); @@ -779,7 +779,7 @@ class RelationTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', [['NULL']] ); diff --git a/test/classes/TwoFactorTest.php b/test/classes/TwoFactorTest.php index 55f4a0e526..f5f497d083 100644 --- a/test/classes/TwoFactorTest.php +++ b/test/classes/TwoFactorTest.php @@ -78,7 +78,7 @@ class TwoFactorTest extends AbstractTestCase ); $this->dummyDbi->addResult( - 'SELECT NULL FROM pma__userconfig LIMIT 0', + 'SELECT NULL FROM `pma__userconfig` LIMIT 0', [ ['NULL'], ], From f7a328842d8d3d473e5b904c4b6b316ba3bf8cef Mon Sep 17 00:00:00 2001 From: William Desportes Date: Tue, 31 Aug 2021 00:08:00 +0200 Subject: [PATCH 11/11] Fix #16906 - Fix the caching effect on the feature list Before this fix you needed to click twice on create tables to see a full list of green checks. As part of the values where fetched by a global and the feature list values by this $cfgRelation passed as a parameter. This was visible when the pmadb existed but had no tables in it. Signed-off-by: William Desportes --- libraries/classes/Controllers/CheckRelationsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/classes/Controllers/CheckRelationsController.php b/libraries/classes/Controllers/CheckRelationsController.php index 2232107587..60fa8e9069 100644 --- a/libraries/classes/Controllers/CheckRelationsController.php +++ b/libraries/classes/Controllers/CheckRelationsController.php @@ -47,12 +47,14 @@ class CheckRelationsController extends AbstractController $this->relation->fixPmaTables($db); } - $cfgRelation = $this->relation->getRelationsParam(); // If request for creating missing PMA tables. if (isset($params['fix_pmadb'])) { + $cfgRelation = $this->relation->getRelationsParam(); $this->relation->fixPmaTables($cfgRelation['db']); } + // Do not use any previous $cfgRelation value as it could have changed after a successfull fixPmaTables() + $cfgRelation = $this->relation->getRelationsParam(); $this->response->addHTML($this->relation->getRelationsParamDiagnostic($cfgRelation)); } }