From b8c0945af20ac475badd0e27ffb3661412959abd Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 30 Jan 2024 14:57:51 +0100 Subject: [PATCH] Implement nat sort for table list in nav Signed-off-by: Kamil Tekiela --- .../classes/Navigation/Nodes/NodeDatabase.php | 60 +++++++------------ psalm-baseline.xml | 5 ++ 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/libraries/classes/Navigation/Nodes/NodeDatabase.php b/libraries/classes/Navigation/Nodes/NodeDatabase.php index ed31ee008a..e6a9e9aa82 100644 --- a/libraries/classes/Navigation/Nodes/NodeDatabase.php +++ b/libraries/classes/Navigation/Nodes/NodeDatabase.php @@ -12,9 +12,10 @@ use PhpMyAdmin\Url; use PhpMyAdmin\Util; use function __; +use function array_slice; use function in_array; -use function intval; use function substr; +use function usort; /** * Represents a database node in the navigation tree @@ -439,7 +440,6 @@ class NodeDatabase extends Node } $query .= 'ORDER BY `TABLE_NAME` ASC '; - $query .= 'LIMIT ' . $pos . ', ' . $maxItems; $retval = $dbi->fetchResult($query); } else { $query = ' SHOW FULL TABLES FROM '; @@ -453,21 +453,15 @@ class NodeDatabase extends Node $handle = $dbi->tryQuery($query); if ($handle !== false) { - $count = 0; - if ($handle->seek($pos)) { - while ($arr = $handle->fetchRow()) { - if ($count >= $maxItems) { - break; - } - - $retval[] = $arr[0]; - $count++; - } - } + $retval = $handle->fetchAllColumn(); } } - return $retval; + if ($GLOBALS['cfg']['NaturalOrder']) { + usort($retval, 'strnatcasecmp'); + } + + return array_slice($retval, $pos, $maxItems); } /** @@ -526,7 +520,6 @@ class NodeDatabase extends Node } $query .= 'ORDER BY `ROUTINE_NAME` ASC '; - $query .= 'LIMIT ' . intval($pos) . ', ' . $maxItems; $retval = $dbi->fetchResult($query); } else { $escdDb = $dbi->escapeString($db); @@ -539,21 +532,17 @@ class NodeDatabase extends Node $handle = $dbi->tryQuery($query); if ($handle !== false) { - $count = 0; - if ($handle->seek($pos)) { - while ($arr = $handle->fetchAssoc()) { - if ($count >= $maxItems) { - break; - } - - $retval[] = $arr['Name']; - $count++; - } + while ($arr = $handle->fetchAssoc()) { + $retval[] = $arr['Name']; } } } - return $retval; + if ($GLOBALS['cfg']['NaturalOrder']) { + usort($retval, 'strnatcasecmp'); + } + + return array_slice($retval, $pos, $maxItems); } /** @@ -610,7 +599,6 @@ class NodeDatabase extends Node } $query .= 'ORDER BY `EVENT_NAME` ASC '; - $query .= 'LIMIT ' . intval($pos) . ', ' . $maxItems; $retval = $dbi->fetchResult($query); } else { $escdDb = Util::backquote($db); @@ -623,21 +611,17 @@ class NodeDatabase extends Node $handle = $dbi->tryQuery($query); if ($handle !== false) { - $count = 0; - if ($handle->seek($pos)) { - while ($arr = $handle->fetchAssoc()) { - if ($count >= $maxItems) { - break; - } - - $retval[] = $arr['Name']; - $count++; - } + while ($arr = $handle->fetchAssoc()) { + $retval[] = $arr['Name']; } } } - return $retval; + if ($GLOBALS['cfg']['NaturalOrder']) { + usort($retval, 'strnatcasecmp'); + } + + return array_slice($retval, $pos, $maxItems); } /** diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fde56a20c9..cc3367fc87 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -8724,6 +8724,11 @@ + + usort($retval, 'strnatcasecmp') + usort($retval, 'strnatcasecmp') + usort($retval, 'strnatcasecmp') + $retval $retval