Implement natural sort for items in the navigation section

Fixes #18949
This commit is contained in:
Maurício Meneghini Fauth 2024-02-01 17:15:22 -03:00 committed by GitHub
commit be6685c344
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 38 deletions

View File

@ -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);
}
/**

View File

@ -8724,6 +8724,11 @@
</PropertyNotSetInConstructor>
</file>
<file src="libraries/classes/Navigation/Nodes/NodeDatabase.php">
<InvalidArgument occurrences="3">
<code>usort($retval, 'strnatcasecmp')</code>
<code>usort($retval, 'strnatcasecmp')</code>
<code>usort($retval, 'strnatcasecmp')</code>
</InvalidArgument>
<InvalidReturnStatement occurrences="4">
<code>$retval</code>
<code>$retval</code>