]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 302326: Column sort links in bug lists should use field IDs instead of names...
authorlpsolit%gmail.com <>
Wed, 21 Dec 2005 06:02:05 +0000 (06:02 +0000)
committerlpsolit%gmail.com <>
Wed, 21 Dec 2005 06:02:05 +0000 (06:02 +0000)
buglist.cgi
template/en/default/list/table.html.tmpl

index 461f7f8bfb507be542021343bc9660697c99f3ff..0c70a8854612e6020cdb7f9f85a5ee9a0680e54b 100755 (executable)
@@ -482,6 +482,8 @@ if (!$params->param('query_format')) {
 #       "DESC" is added to the end of the field to sort in descending order, 
 #       and the redundant short_desc column is removed when the client
 #       requests "all" columns.
+# Note: For column names using aliasing (SQL "<field> AS <alias>"), the column
+#       ID needs to be identical to the field ID for list ordering to work.
 
 my $columns = {};
 sub DefineColumn {
@@ -721,7 +723,7 @@ if ($order) {
                 $fragment = trim($fragment);
                 # Accept an order fragment matching a column name, with
                 # asc|desc optionally following (to specify the direction)
-                if (grep($fragment =~ /^\Q$_\E(\s+(asc|desc))?$/, @columnnames)) {
+                if (grep($fragment =~ /^\Q$_\E(\s+(asc|desc))?$/, @columnnames, keys(%$columns))) {
                     next if $fragment =~ /\brelevance\b/ && !$fulltext;
                     push(@order, $fragment);
                 }
@@ -748,21 +750,29 @@ else {
     $order = "bugs.bug_status, bugs.priority, map_assigned_to.login_name, bugs.bug_id";
 }
 
+# Make sure ORDER BY columns are included in the field list.
 foreach my $fragment (split(/,/, $order)) {
     $fragment = trim($fragment);
     if (!grep($fragment =~ /^\Q$_\E(\s+(asc|desc))?$/, @selectnames)) {
         # Add order columns to selectnames
         # The fragment has already been validated
         $fragment =~ s/\s+(asc|desc)$//;
-        # This fixes an issue where columns being used in the ORDER BY statement
-        # can have the SQL that generates the value changed to become invalid -
-        # mainly affects time tracking.
+
+        # While newer fragments contain IDs for aliased columns, older
+        # LASTORDER cookies (or bookmarks) may contain full names.
+        # Convert them to an ID here.
         if ($fragment =~ / AS (\w+)/) {
-            $fragment = $columns->{$1}->{'name'};
+            $fragment = $columns->{$1}->{'id'};
         }
-        else {
-            $fragment =~ tr/a-zA-Z\.0-9\-_//cd;
+
+        $fragment =~ tr/a-zA-Z\.0-9\-_//cd;
+
+        # If the order fragment is an ID, we need its corresponding name
+        # to be in the field list.
+        if (exists($columns->{$fragment})) {
+            $fragment = $columns->{$fragment}->{'name'};
         }
+
         push @selectnames, $fragment;
     }
 }
index d3fe3231b05983d0b8bbe61a994a1aaac1f6a8fa..7ef53058a04ff046cfdcc509bf4943742723fb4b 100644 (file)
     [% IF sorted_by_relevance %]
       [%- abbrev.$id.title || field_descs.$id || column.title -%]
     [% ELSE %]
+      [% IF column.name.match('\s+AS\s+') %]
+        [%# For aliased columns, use their ID for sorting. %]
+        [% column.sortalias = id %]
+      [% ELSE %]
+        [%# Other columns may sort on their name directly. %]
+        [% column.sortalias = column.name %]
+      [% END %]
       <a href="buglist.cgi?[% urlquerypart FILTER html %]&amp;order=
-        [% column.name FILTER url_quote FILTER html %]
+        [% column.sortalias FILTER url_quote FILTER html %]
         [% ",$qorder" FILTER html IF order %]
         [%-#%]&amp;query_based_on=
         [% defaultsavename OR searchname FILTER html %]">