Skip to content

Commit

Permalink
MDL-65033 mod_forum: Modified sort sql for cross db support
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie authored and stronk7 committed Apr 30, 2019
1 parent 26a9430 commit 30513f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion mod/forum/classes/local/vaults/discussion_list.php
Expand Up @@ -217,7 +217,19 @@ public function get_sort_order(?int $sortmethod, $includefavourites = true) : st
}
}

$favouritesort = ($includefavourites ? ", {$this->get_favourite_alias()}.id DESC" : "");
$favouritesort = '';
if ($includefavourites) {
$favalias = $this->get_favourite_alias();
// Since we're joining on the favourite table any discussion that isn't favourited will have
// null in the favourite columns. Nulls behave differently in the sorting for different databases.
// We can ensure consistency between databases by explicitly deprioritising any null favourite field
// using a case statement.
$favouritesort = ", CASE WHEN {$favalias}.id IS NULL THEN 0 ELSE 1 END DESC";
// After the null favourite fields are deprioritised and appear below the favourited discussions we
// need to order the favourited discussions by id so that the most recently favourited discussions
// appear at the top of the list.
$favouritesort .= ", {$favalias}.id DESC";
}

return "{$alias}.pinned DESC $favouritesort , {$keyfield} {$direction}";
}
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Expand Up @@ -24,6 +24,6 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019040402; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2019040403; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2018112800; // Requires this Moodle version
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)

0 comments on commit 30513f9

Please sign in to comment.