Skip to content

Commit

Permalink
Fix sorting of due date for undefined values
Browse files Browse the repository at this point in the history
Previously fixed in #16259, the order clause still has error with some
databases.
Rewrite the sort expression in a protable syntax.

Fixes: #23241
  • Loading branch information
cproensa authored and dregad committed Oct 7, 2017
1 parent c7819ff commit da11963
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/filter_api.php
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit da11963

Please sign in to comment.