Skip to content
Snippets Groups Projects
Commit e5925c25 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1008410 by droplet: forum list header sorting broken.

parent 721b9a1b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -215,7 +215,7 @@ function forum_schema() { ...@@ -215,7 +215,7 @@ function forum_schema() {
), ),
), ),
'indexes' => array( 'indexes' => array(
'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'), 'forum_topics' => array('nid', 'tid', 'sticky', 'last_comment_timestamp'),
), ),
'foreign keys' => array( 'foreign keys' => array(
'tracked_node' => array( 'tracked_node' => array(
......
...@@ -879,7 +879,6 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { ...@@ -879,7 +879,6 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
->addTag('node_access') ->addTag('node_access')
->orderBy('f.sticky', 'DESC') ->orderBy('f.sticky', 'DESC')
->orderByHeader($forum_topic_list_header) ->orderByHeader($forum_topic_list_header)
->orderBy('f.last_comment_timestamp', 'DESC')
->limit($forum_per_page); ->limit($forum_per_page);
$count_query = db_select('forum_index', 'f'); $count_query = db_select('forum_index', 'f');
...@@ -894,7 +893,29 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { ...@@ -894,7 +893,29 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
$nids[] = $record->nid; $nids[] = $record->nid;
} }
if ($nids) { if ($nids) {
$result = db_query("SELECT n.title, n.nid, n.type, n.sticky, n.created, n.uid, n.comment AS comment_mode, ncs.*, f.tid AS forum_tid, u.name, CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u2.name END AS last_comment_name FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {users} u2 ON ncs.last_comment_uid = u2.uid WHERE n.nid IN (:nids)", array(':nids' => $nids)); $query = db_select('node', 'n')->extend('TableSort');
$query->fields('n', array('title', 'nid', 'type', 'sticky', 'created', 'uid'));
$query->addField('n', 'comment', 'comment_mode');
$query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
$query->fields('ncs', array('cid', 'last_comment_uid', 'last_comment_timestamp', 'comment_count'));
$query->join('forum_index', 'f', 'f.nid = ncs.nid');
$query->addField('f', 'tid', 'forum_tid');
$query->join('users', 'u', 'n.uid = u.uid');
$query->addField('u', 'name');
$query->join('users', 'u2', 'ncs.last_comment_uid = u2.uid');
$query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u2.name END', 'last_comment_name');
$query
->orderBy('f.sticky', 'DESC')
->orderByHeader($forum_topic_list_header)
->condition('n.nid', $nids);
$result = $query->execute();
} }
else { else {
$result = array(); $result = array();
...@@ -1193,16 +1214,16 @@ function _forum_user_last_visit($nid) { ...@@ -1193,16 +1214,16 @@ function _forum_user_last_visit($nid) {
function _forum_get_topic_order($sortby) { function _forum_get_topic_order($sortby) {
switch ($sortby) { switch ($sortby) {
case 1: case 1:
return array('field' => 'ncs.last_comment_timestamp', 'sort' => 'desc'); return array('field' => 'f.last_comment_timestamp', 'sort' => 'desc');
break; break;
case 2: case 2:
return array('field' => 'ncs.last_comment_timestamp', 'sort' => 'asc'); return array('field' => 'f.last_comment_timestamp', 'sort' => 'asc');
break; break;
case 3: case 3:
return array('field' => 'ncs.comment_count', 'sort' => 'desc'); return array('field' => 'f.comment_count', 'sort' => 'desc');
break; break;
case 4: case 4:
return array('field' => 'ncs.comment_count', 'sort' => 'asc'); return array('field' => 'f.comment_count', 'sort' => 'asc');
break; break;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment