Forum: Thread ordering changes after edit
see PR the cause was that DB 'sticky' field is default 0 but an edit changes it to NULL. That's a real bug.
Current behavior / Resultado actual / Résultat actuel
If you have a number of threads and you edit the body of the first post it "drops down" in the list. Why?
Expected behavior / Resultado esperado / Résultat attendu
The Thread ordering should be based on name or time of creation but not random after edit.
Steps to reproduce / Pasos para reproducir / Étapes pour reproduire
Edit the title of a thread by adding a dot or something. The ordering will be shuffled.
Chamilo Version / Versión de Chamilo / Version de Chamilo
1.11.x
It works for me.
I have this test course:
https://11.chamilo.org/main/forum/viewforum.php?cidReq=JULIOCOURSE&id_session=0&gidReq=0&gradebook=0&origin=&gidReq=0&forum=149
After editing "thread c" it's always at the top.
Testing here and works fine too.
Changing the BODY of a message sends it completely down the list. That can be reproduced and is not correct. The date/place should kept the same. Like changing the title does.
The original issue says 'changing the title' but should be 'changing the body'.
https://11.chamilo.org/main/forum/viewforum.php?cidReq=TESTHVA&id_session=0&gidReq=0&gradebook=0&origin=&forum=48& (look at the dates)
Changing a message in a forum changes the order of the messages.
Found the bug in the code: cause is the c_forum_thread table, field "thread_sticky". This thread_sticky is defined as default NULL in the database but when you create a forum thread it will be 0 instead of NULL.
But when you EDIT a forum post (body or title of a post) the thread_sticky becomes NULL and the post ends up at the bottom due to ordering on thread_sticky. Editing all posts one time sill solve the problem until a new post with sticky=0 appears.
Solution should be to make 0 the default value and don;t let EDITpost change it to NULL.
diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index f4411a0..ed37722 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -3722,7 +3722,7 @@ function store_edit_post($forumInfo, $values) // Simple edit $params = [ 'thread_title' => $values['post_title'], - 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : null, + 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : 0, ]; $where = ['c_id = ? AND thread_id = ?' => [$course_id, $values['thread_id']]]; Database::update($threadTable, $params, $where);
@jmontoyaa I'm assigning to you for review. I think you're the latest one to have checked the forum code after José.
I just added that change.
@jderriks, whenever you get a chance to test this on https://11.chamilo.org and approve the change, let us know :-)
Works on 11.chamilo.org, change approved.