MDL-65033 mod_forum: Modified sort sql for cross db support

This commit is contained in:
Ryan Wyllie 2019-04-30 16:36:35 +08:00 committed by Eloy Lafuente (stronk7)
parent 26a94308ee
commit 30513f9740
2 changed files with 14 additions and 2 deletions

View File

@ -217,7 +217,19 @@ class discussion_list extends db_table_vault {
}
}
$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}";
}

View File

@ -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)