chamilo-lms icon indicating copy to clipboard operation
chamilo-lms copied to clipboard

Forum: Thread ordering changes after edit

Open jderriks opened this issue 9 years ago • 10 comments

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

jderriks avatar Sep 01 '17 09:09 jderriks

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.

jmontoyaa avatar Sep 13 '17 12:09 jmontoyaa

Testing here and works fine too.

jloguercio avatar Oct 04 '17 21:10 jloguercio

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'.

jderriks avatar Nov 20 '17 12:11 jderriks

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.

jderriks avatar Nov 24 '17 07:11 jderriks

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.

jderriks avatar Nov 26 '17 13:11 jderriks

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

jderriks avatar Nov 26 '17 14:11 jderriks

@jmontoyaa I'm assigning to you for review. I think you're the latest one to have checked the forum code after José.

ywarnier avatar Dec 05 '17 05:12 ywarnier

I just added that change.

jmontoyaa avatar Dec 05 '17 12:12 jmontoyaa

@jderriks, whenever you get a chance to test this on https://11.chamilo.org and approve the change, let us know :-)

ywarnier avatar Dec 05 '17 14:12 ywarnier

Works on 11.chamilo.org, change approved.

jderriks avatar Dec 07 '17 15:12 jderriks