Moreover, my code here asserts that the two methods do indeed produce the same order.
public function listBoards(int $id_board): array
{
$request = Db::$db->query(
'
SELECT id_board, b.name, child_level, c.name AS cat_name, id_cat
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c USING (id_cat)
ORDER BY board_order',
);
$boards = [];
while ($row = Db::$db->fetch_assoc($request)) {
if (!isset($boards[$row['id_cat']])) {
$boards[$row['id_cat']] = [
'name' => strip_tags($row['cat_name']),
'boards' => [],
];
}
$boards[$row['id_cat']]['boards'][$row['id_board']] = [
'name' => strip_tags($row['name']),
'child_level' => $row['child_level'],
'selected' => $row['id_board'] == $id_board,
];
}
Db::$db->free_result($request);
$a = $boards;
// Find the boards/categories they can see.
$boardListOptions = [
'not_redirection' => true,
'selected_board' => $id_board,
];
if (!empty(Config::$modSettings['recycle_enable']) && !empty(Config::$modSettings['recycle_board'])) {
$boardListOptions['excluded_boards'] = [(int) Config::$modSettings['recycle_board']];
}
$boards = \SMF\Actions\MessageIndex::getBoardList($boardListOptions);
// Make the board safe for display.
foreach ($boards as $id_cat => $cat) {
$boards[$id_cat]['name'] = Utils::htmlspecialcharsDecode(strip_tags($cat['name']));
foreach ($cat['boards'] as $id_board => $board) {
$boards[$id_cat]['boards'][$id_board]['name'] = Utils::htmlspecialcharsDecode(strip_tags($board['name']));
}
}
$b = $boards;
var_dump(array_keys($a) === array_keys($b)); // categories
foreach ($a as $k => $cat) {
if (array_keys($cat['boards']) !== array_keys($b[$k]['boards'])) {
echo "Mismatch in category $k\n";
}
}
return $boards;
}
The original commit fcb140d tried to fix this by offloading sorting to PHP. However,
board_orderis reliably updated every time a board is changed:SMF/Sources/Board.php
Lines 1554 to 1585 in fc87e75
Moreover, my code here asserts that the two methods do indeed produce the same order.