From da11963b8478da573cdf4c62229db2099630e3a4 Mon Sep 17 00:00:00 2001 From: Carlos Proensa Date: Thu, 24 Aug 2017 02:22:26 +0200 Subject: [PATCH] Fix sorting of due date for undefined values Previously fixed in #16259, the order clause still has error with some databases. Rewrite the sort expression in a protable syntax. Fixes: #23241 --- core/filter_api.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/filter_api.php b/core/filter_api.php index 25d6dce4a4..dd27ffa369 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -1126,13 +1126,15 @@ function filter_get_query_sort_data( array &$p_filter, $p_show_sticky, array $p_ } else { $t_sort_col = '{bug}.' . $c_sort; - # when sorting by due_date, always display undefined dates last + # When sorting by due_date, always display undefined dates last. + # Undefined date is defaulted as "1" in database, so add a special + # sort clause to group and sort by this. if( 'due_date' == $c_sort && 'ASC' == $c_dir ) { - $t_sort_due_date = $t_sort_col . ' = 1'; - $p_query_clauses['select'][] = $t_sort_due_date; - $t_sort_col = $t_sort_due_date . ', ' . $t_sort_col; + $t_null_expr = 'CASE ' . $t_sort_col . ' WHEN 1 THEN 1 ELSE 0 END'; + $p_query_clauses['select'][] = $t_null_expr . ' AS due_date_sort_null'; + $p_query_clauses['order'][] = 'due_date_sort_null ASC'; } - + # main sort clause for due date $p_query_clauses['order'][] = $t_sort_col . ' ' .$c_dir; } }