From 6cb5756e7dbbbd40d2fb24a3974fd13eb5777f80 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 20 Apr 2014 16:04:53 +0200 Subject: [PATCH 1/7] Manage a config proporty to limit the number of items at first level in navigation panel. Signed-off-by: Hugues Peccatte --- doc/config.rst | 8 ++++ libraries/config.default.php | 7 ++++ libraries/config.values.php | 1 + libraries/config/messages.inc.php | 5 +++ libraries/config/setup.forms.php | 1 + libraries/config/user_preferences.forms.php | 1 + libraries/navigation/Nodes/Node.class.php | 42 ++++++++++++++++++++- 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 1a8faf021e..88ae1ed477 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1374,6 +1374,14 @@ Cookie authentication options Navigation panel setup ---------------------- +.. config:option:: $cfg['FirstLevelNavigationItems'] + + :type: integer + :default: 25 + + The number of items that can be displayed on each page of the first level + of navigation tree. + .. config:option:: $cfg['MaxNavigationItems'] :type: integer diff --git a/libraries/config.default.php b/libraries/config.default.php index 1953cea6b6..31cd2151f5 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -847,6 +847,13 @@ $cfg['Error_Handler']['display'] = false; * Navigation panel setup */ +/** + * maximum number of items displayed on first level in navigation panel + * + * @global integer $cfg['FirstLevelNavigationItems'] + */ +$cfg['FirstLevelNavigationItems'] = 25; + /** * maximum number of items displayed in navigation panel * diff --git a/libraries/config.values.php b/libraries/config.values.php index d5b63ad45e..b8012291db 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -211,6 +211,7 @@ $cfg_db['_validators'] = array( 'CharTextareaRows' => 'validatePositiveNumber', 'ExecTimeLimit' => 'validateNonNegativeNumber', 'Export/sql_max_query_size' => 'validatePositiveNumber', + 'FirstLevelNavigationItems' => 'validatePositiveNumber', 'ForeignKeyMaxLimit' => 'validatePositiveNumber', 'Import/csv_enclosed' => array(array('validateByRegex', '/^.?$/')), 'Import/csv_escaped' => array(array('validateByRegex', '/^.$/')), diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 2c2c5c9d4b..07f59b65ba 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -398,6 +398,11 @@ $strConfigMaxDbList_cmt = __('Users cannot set a higher value'); $strConfigMaxDbList_desc = __('Maximum number of databases displayed in database list.'); $strConfigMaxDbList_name = __('Maximum databases'); +$strConfigFirstLevelNavigationItems_desc = __( + 'The number of items that can be displayed on each page on first level of the ' + . 'navigation tree.' +); +$strConfigFirstLevelNavigationItems_name = __('Maximum items on first level'); $strConfigMaxNavigationItems_desc = __( 'The number of items that can be displayed on each page of the navigation tree.' ); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index ddd01711af..1c612378e5 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -170,6 +170,7 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLink', 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', + 'FirstLevelNavigationItems', 'MaxNavigationItems', 'NavigationTreeEnableGrouping', 'NavigationTreeDisableDatabaseExpansion', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 19601c119f..51b481fa76 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -83,6 +83,7 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLink', 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', + 'FirstLevelNavigationItems', 'MaxNavigationItems', 'NavigationTreeEnableGrouping', 'NavigationTreeDisableDatabaseExpansion', diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 5354985de1..2cfe8bc90a 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -360,11 +360,49 @@ class Node */ public function getData($type, $pos, $searchClause = '') { - $query = "SELECT `SCHEMA_NAME` "; + /*$query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; $query .= $this->_getWhereClause($searchClause); $query .= "ORDER BY `SCHEMA_NAME` ASC "; - $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; + $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}";*/ + + $query = "SELECT `SCHEMA_NAME` "; + $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "; + $query .= " ("; + $query .= " select DB_first_level "; + $query .= " from ( "; + $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; + $query .= "DB_first_level "; + $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; + $query .= $this->_getWhereClause($searchClause); + $query .= " ) t "; + $query .= " ORDER BY DB_first_level ASC "; + $query .= " LIMIT $pos, {$GLOBALS['cfg']['FirstLevelNavigationItems']}"; + $query .= " ) t2 "; + $query .= "where 1 = locate(concat(DB_first_level, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}'), "; + $query .= "concat(SCHEMA_NAME, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}')) "; + $query .= "order by SCHEMA_NAME ASC"; + /*echo $query; + + SELECT `SCHEMA_NAME` + FROM `INFORMATION_SCHEMA`.`SCHEMATA`, + ( + select DB_first_level + from ( + SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) DB_first_level + FROM INFORMATION_SCHEMA.SCHEMATA + WHERE TRUE + ) t + ORDER BY DB_first_level ASC + LIMIT 0, 5 + ) t2 + where 1 = locate(concat(DB_first_level, '_'), concat(SCHEMA_NAME, '_')) + order by SCHEMA_NAME ASC + */ + return $GLOBALS['dbi']->fetchResult($query); } From 5ca2afd63221de3e2d47906f212f8e019adfe00c Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Mon, 21 Apr 2014 16:38:59 +0200 Subject: [PATCH 2/7] Remove useless comments. Signed-off-by: Hugues Peccatte --- libraries/navigation/Nodes/Node.class.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 2cfe8bc90a..4170f4ed1b 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -360,12 +360,6 @@ class Node */ public function getData($type, $pos, $searchClause = '') { - /*$query = "SELECT `SCHEMA_NAME` "; - $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - $query .= $this->_getWhereClause($searchClause); - $query .= "ORDER BY `SCHEMA_NAME` ASC "; - $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}";*/ - $query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "; $query .= " ("; @@ -385,23 +379,6 @@ class Node $query .= "concat(SCHEMA_NAME, "; $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}')) "; $query .= "order by SCHEMA_NAME ASC"; - /*echo $query; - - SELECT `SCHEMA_NAME` - FROM `INFORMATION_SCHEMA`.`SCHEMATA`, - ( - select DB_first_level - from ( - SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) DB_first_level - FROM INFORMATION_SCHEMA.SCHEMATA - WHERE TRUE - ) t - ORDER BY DB_first_level ASC - LIMIT 0, 5 - ) t2 - where 1 = locate(concat(DB_first_level, '_'), concat(SCHEMA_NAME, '_')) - order by SCHEMA_NAME ASC - */ return $GLOBALS['dbi']->fetchResult($query); } From 8873df3581ac1779a53f0ee77f46c9afc6398207 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Tue, 22 Apr 2014 21:20:56 +0200 Subject: [PATCH 3/7] Update queries about DB navigation. Signed-off-by: Hugues Peccatte --- libraries/navigation/NavigationTree.class.php | 21 ++++++++++++------- libraries/navigation/Nodes/Node.class.php | 9 ++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index 7958cd3b91..8a558c402d 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -157,15 +157,20 @@ class PMA_NavigationTree /* * @todo describe a scenario where this code is executed */ - $query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d "; - $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - $query .= "WHERE `SCHEMA_NAME` < '%s' "; - $query .= "ORDER BY `SCHEMA_NAME` ASC"; + $query = "SELECT (COUNT(DB_first_level) DIV %d) * %d "; + $query .= "from ( "; + $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= " '{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; + $query .= " DB_first_level "; + $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; + $query .= " WHERE `SCHEMA_NAME` < '%s' "; + $query .= ") t "; + $retval = $GLOBALS['dbi']->fetchValue( sprintf( $query, - (int)$GLOBALS['cfg']['MaxNavigationItems'], - (int)$GLOBALS['cfg']['MaxNavigationItems'], + (int)$GLOBALS['cfg']['FirstLevelNavigationItems'], + (int)$GLOBALS['cfg']['FirstLevelNavigationItems'], PMA_Util::sqlAddSlashes($GLOBALS['db']) ) ); @@ -1145,7 +1150,7 @@ class PMA_NavigationTree array('server' => $GLOBALS['server']), 'navigation.php', 'frame_navigation', - $GLOBALS['cfg']['MaxNavigationItems'], + $GLOBALS['cfg']['FirstLevelNavigationItems'], 'pos', array('dbselector') ); @@ -1177,7 +1182,7 @@ class PMA_NavigationTree $_url_params, 'navigation.php', 'frame_navigation', - $GLOBALS['cfg']['MaxNavigationItems'], + $GLOBALS['cfg']['FirstLevelNavigationItems'], 'pos' . $level . '_value' ); } diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 4170f4ed1b..c6bc4b4868 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -395,9 +395,14 @@ class Node */ public function getPresence($type = '', $searchClause = '') { - $query = "SELECT COUNT(*) "; - $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; + $query = "select COUNT(*) "; + $query .= "from ( "; + $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= " '{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; + $query .= " DB_first_level "; + $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; $query .= $this->_getWhereClause($searchClause); + $query .= ") t "; $retval = (int)$GLOBALS['dbi']->fetchValue($query); return $retval; } From 3319c634cc82db9cf8879ef7edcac604e86e51c0 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Tue, 22 Apr 2014 21:29:33 +0200 Subject: [PATCH 4/7] Update ChangeLog. Signed-off-by: Hugues Peccatte --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 233398d8d1..29daa4c0a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -51,6 +51,7 @@ phpMyAdmin - ChangeLog - bug #4337 "More" in Actions area doesn't collapse to fit available space - rfe #1518 Confirm dialog on accidentally leaving a page - bug #4375 Group two DB, one's name is the prefix of the other one +- bug #4070 Confusing database/table grouping 4.1.14.0 (not yet released) - bug #4365 Creating bookmark with multiple queries not working From ebc2739c89e2dc6f9ef5a6622fb937b73901ba7b Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Tue, 22 Apr 2014 21:36:26 +0200 Subject: [PATCH 5/7] Update documentation. Signed-off-by: Hugues Peccatte --- doc/config.rst | 6 +++--- libraries/config.default.php | 2 +- test/classes/navigation/PMA_Node_test.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 88ae1ed477..213822920e 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1379,7 +1379,7 @@ Navigation panel setup :type: integer :default: 25 - The number of items that can be displayed on each page of the first level + The number of first level databases that can be displayed on each page of navigation tree. .. config:option:: $cfg['MaxNavigationItems'] @@ -1387,8 +1387,8 @@ Navigation panel setup :type: integer :default: 250 - The number of items that can be displayed on each page of the - navigation tree. + The number of items (tables, columns, indexes) that can be displayed on each + page of the navigation tree. .. config:option:: $cfg['NavigationTreeEnableGrouping'] diff --git a/libraries/config.default.php b/libraries/config.default.php index 31cd2151f5..4f0064e740 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -848,7 +848,7 @@ $cfg['Error_Handler']['display'] = false; */ /** - * maximum number of items displayed on first level in navigation panel + * maximum number of first level databases displayed in navigation panel * * @global integer $cfg['FirstLevelNavigationItems'] */ diff --git a/test/classes/navigation/PMA_Node_test.php b/test/classes/navigation/PMA_Node_test.php index 9dd221fffa..89faa0dede 100644 --- a/test/classes/navigation/PMA_Node_test.php +++ b/test/classes/navigation/PMA_Node_test.php @@ -342,7 +342,7 @@ class Node_Test extends PHPUnit_Framework_TestCase if (! isset($GLOBALS['cfg'])) { $GLOBALS['cfg'] = array(); } - $GLOBALS['cfg']['MaxNavigationItems'] = $limit; + $GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit; $expectedSql = "SELECT `SCHEMA_NAME` "; $expectedSql .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; From 9870cb5142eee8fa37f0c1fbe9beab439cdfa03f Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Wed, 23 Apr 2014 21:30:07 +0200 Subject: [PATCH 6/7] =?UTF-8?q?Update=20DB=C2=A0group=20queries=20format.?= =?UTF-8?q?=20Update=20DB=20group=20test.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hugues Peccatte --- libraries/navigation/Nodes/Node.class.php | 26 +++++++++++------------ test/classes/navigation/PMA_Node_test.php | 26 +++++++++++++++++++---- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index c6bc4b4868..70dd75b098 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -362,18 +362,18 @@ class Node { $query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "; - $query .= " ("; - $query .= " select DB_first_level "; - $query .= " from ( "; - $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= "("; + $query .= "select DB_first_level "; + $query .= "from ( "; + $query .= "SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; $query .= "DB_first_level "; - $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; + $query .= "FROM INFORMATION_SCHEMA.SCHEMATA "; $query .= $this->_getWhereClause($searchClause); - $query .= " ) t "; - $query .= " ORDER BY DB_first_level ASC "; - $query .= " LIMIT $pos, {$GLOBALS['cfg']['FirstLevelNavigationItems']}"; - $query .= " ) t2 "; + $query .= ") t "; + $query .= "ORDER BY DB_first_level ASC "; + $query .= "LIMIT $pos, {$GLOBALS['cfg']['FirstLevelNavigationItems']}"; + $query .= ") t2 "; $query .= "where 1 = locate(concat(DB_first_level, "; $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}'), "; $query .= "concat(SCHEMA_NAME, "; @@ -397,10 +397,10 @@ class Node { $query = "select COUNT(*) "; $query .= "from ( "; - $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; - $query .= " '{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; - $query .= " DB_first_level "; - $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; + $query .= "SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; + $query .= "DB_first_level "; + $query .= "FROM INFORMATION_SCHEMA.SCHEMATA "; $query .= $this->_getWhereClause($searchClause); $query .= ") t "; $retval = (int)$GLOBALS['dbi']->fetchValue($query); diff --git a/test/classes/navigation/PMA_Node_test.php b/test/classes/navigation/PMA_Node_test.php index 89faa0dede..c16b9586c1 100644 --- a/test/classes/navigation/PMA_Node_test.php +++ b/test/classes/navigation/PMA_Node_test.php @@ -343,12 +343,25 @@ class Node_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg'] = array(); } $GLOBALS['cfg']['FirstLevelNavigationItems'] = $limit; + $GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_'; $expectedSql = "SELECT `SCHEMA_NAME` "; - $expectedSql .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; + $expectedSql .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "; + $expectedSql .= "("; + $expectedSql .= "select DB_first_level "; + $expectedSql .= "from ( "; + $expectedSql .= "SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $expectedSql .= "'_', 1) "; + $expectedSql .= "DB_first_level "; + $expectedSql .= "FROM INFORMATION_SCHEMA.SCHEMATA "; $expectedSql .= "WHERE TRUE "; - $expectedSql .= "ORDER BY `SCHEMA_NAME` ASC "; + $expectedSql .= ") t "; + $expectedSql .= "ORDER BY DB_first_level ASC "; $expectedSql .= "LIMIT $pos, $limit"; + $expectedSql .= ") t2 "; + $expectedSql .= "where 1 = locate(concat(DB_first_level, '_'), "; + $expectedSql .= "concat(SCHEMA_NAME, '_')) "; + $expectedSql .= "order by SCHEMA_NAME ASC"; // It would have been better to mock _getWhereClause method // but stangely, mocking private methods is not supported in PHPUnit @@ -381,10 +394,15 @@ class Node_Test extends PHPUnit_Framework_TestCase if (! isset($GLOBALS['cfg']['Servers'][0])) { $GLOBALS['cfg']['Servers'][0] = array(); } + $GLOBALS['cfg']['NavigationTreeDbSeparator'] = '_'; - $query = "SELECT COUNT(*) "; - $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; + $query = "select COUNT(*) "; + $query .= "from ( "; + $query .= "SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) "; + $query .= "DB_first_level "; + $query .= "FROM INFORMATION_SCHEMA.SCHEMATA "; $query .= "WHERE TRUE "; + $query .= ") t "; // It would have been better to mock _getWhereClause method // but strangely, mocking private methods is not supported in PHPUnit From aab859a7a830d20f32cf0c5952d6516395c237d1 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Thu, 24 Apr 2014 16:29:39 +0200 Subject: [PATCH 7/7] Fix wrong table page selector. Signed-off-by: Hugues Peccatte --- libraries/navigation/NavigationTree.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index 8a558c402d..865aa22110 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -1182,7 +1182,7 @@ class PMA_NavigationTree $_url_params, 'navigation.php', 'frame_navigation', - $GLOBALS['cfg']['FirstLevelNavigationItems'], + $GLOBALS['cfg']['MaxNavigationItems'], 'pos' . $level . '_value' ); }