diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-11 17:25:21 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-22 14:13:37 +0200 |
commit | 8722458d2a2342517e45674129ec5c7d071a4077 (patch) | |
tree | 31535d9b58e9fb24f9ad4c915e0601bdaf1f0ef4 /apps/comments/lib | |
parent | 8f0a9ae51fdc92e7c33f7a48b9d84da6c6b196e1 (diff) | |
download | nextcloud-server-8722458d2a2342517e45674129ec5c7d071a4077.tar.gz nextcloud-server-8722458d2a2342517e45674129ec5c7d071a4077.zip |
ensure that sorting is stable
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r-- | apps/comments/lib/Collaboration/CommentersSorter.php | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php index e89a66f148d..8a24592c30b 100644 --- a/apps/comments/lib/Collaboration/CommentersSorter.php +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -58,12 +58,23 @@ class CommentersSorter implements ISorter { continue; } - usort($byType, function ($a, $b) use ($commenters, $type) { - $r = $this->compare($a, $b, $commenters[$type]); + // at least on PHP 5.6 usort turned out to be not stable. So we add + // the current index to the value and compare it on a draw + $i = 0; + $workArray = array_map(function($element) use (&$i) { + return [$i++, $element]; + }, $byType); + + usort($workArray, function ($a, $b) use ($commenters, $type) { + $r = $this->compare($a[1], $b[1], $commenters[$type]); + if($r === 0) { + $r = $a[0] - $b[0]; + } return $r; }); - $s = ''; + // and remove the index values again + $byType = array_column($workArray, 1); } } |