MDL-66734 core_comment: fix get_comment ordering when timestamps match

Include id in the sorting, to be sure that we always get the correct
record in cases where the comment timestamps are the same.
This commit is contained in:
Jake Dallimore
2019-10-01 09:18:56 +08:00
parent 31f8f75672
commit 3958f4a302
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -564,7 +564,7 @@ class comment {
c.commentarea = :commentarea AND
c.itemid = :itemid AND
$componentwhere
ORDER BY c.timecreated DESC";
ORDER BY c.timecreated DESC, c.id DESC";
$params['contextid'] = $this->contextid;
$params['commentarea'] = $this->commentarea;
$params['itemid'] = $this->itemid;
+3 -2
View File
@@ -96,17 +96,18 @@ class core_comment_externallib_testcase extends externallib_advanced_testcase {
// We need to add the comments manually, the comment API uses the global OUTPUT and this is going to make the WS to fail.
$newcmt = new stdClass;
$timecreated = time();
$newcmt->contextid = $context->id;
$newcmt->commentarea = 'database_entry';
$newcmt->itemid = $recordid;
$newcmt->content = 'New comment';
$newcmt->format = 0;
$newcmt->userid = $user->id;
$newcmt->timecreated = time();
$newcmt->timecreated = $timecreated;
$cmtid1 = $DB->insert_record('comments', $newcmt);
$newcmt->content = 'New comment 2';
$newcmt->timecreated = time() + 1;
$newcmt->timecreated = $timecreated;
$cmtid2 = $DB->insert_record('comments', $newcmt);
$contextlevel = 'module';