Hi:

 

   I have found that in forums when you move a post to a new thread, if
it is the last post of the thread, the thread database didn't get
updated.

 

  Because of this forums gets inaccessible. It also didn't update the
threads messages counters.

  Here is a patch for the problem:

 

 

diff a/main/forum/forumfunction.inc.php
b/main/forum/forumfunction.inc.php

--- a/main/forum/forumfunction.inc.php

+++ b/main/forum/forumfunction.inc.php

@@ -3119,13 +3119,48 @@ function store_move_post($values) {

                $result=Database::query($sql);

                //echo $sql.'<br />';

        } else {

-               // moving to the chosen thread

-               $sql="UPDATE $table_posts SET
thread_id='".Database::escape_string($_POST['thread'])."',
post_parent_id='0' WHERE
post_id='".Database::escape_string($values['post_id'])."'";

-               $result=Database::query($sql);

+        // If this post is the last post of the thread we must update
the thread_last_post with a new post_id

+

+        // Search for the original thread_id

+        $sql = "SELECT thread_id FROM ".$table_posts." WHERE post_id =
'".$values['post_id']."' ";

+

+        $result=api_sql_query($sql, __LINE__, __FILE__);

+        $row=Database::fetch_array($result);

+        $original_thread_id = $row['thread_id'];

+

+        // Search for the thread_last_post

+        $sql = "SELECT thread_last_post FROM ".$table_threads." WHERE
thread_id = '".$original_thread_id."' ";

+

+        $result=api_sql_query($sql, __LINE__, __FILE__);

+        $row=Database::fetch_array($result);

+        $thread_is_last_post = $row['thread_last_post'];

+

+        // If is this thread, update the thread_last_post with the last
one.

+        if ($thread_is_last_post == $values['post_id'])

+        {

+            $sql = "SELECT post_id FROM ".$table_posts." WHERE
thread_id = '".$original_thread_id."' AND post_id <>
'".$values['post_id']."' ORDER BY post_date DESC LIMIT 1";

+            $result=api_sql_query($sql, __LINE__, __FILE__);

+            $row=Database::fetch_array($result);

+            $thread_new_last_post = $row['post_id'];

+

+            $sql = "UPDATE ".$table_threads." SET thread_last_post =
'".$thread_new_last_post."' WHERE thread_id = '".$original_thread_id."'
";

+            $result=api_sql_query($sql, __LINE__, __FILE__);

+        }

+

+        $sql="UPDATE $table_threads SET thread_replies=thread_replies-1
WHERE thread_id='".$original_thread_id."'";

+        $result=api_sql_query($sql, __LINE__, __FILE__);

+

+        // moving to the chosen thread

+        $sql="UPDATE $table_posts SET
thread_id='".Database::escape_string($_POST['thread'])."',
post_parent_id='0' WHERE
post_id='".Database::escape_string($values['post_id'])."'";

+        $result=api_sql_query($sql, __LINE__, __FILE__);

+

+        // resetting the parent_id of the thread to 0 for all those who
had this moved post as parent

+        $sql="UPDATE $table_posts SET post_parent_id='0' WHERE
post_parent_id='".Database::escape_string($values['post_id'])."'";

+        $result=api_sql_query($sql, __LINE__, __FILE__);

+

+        $sql="UPDATE $table_threads SET thread_replies=thread_replies+1
WHERE thread_id='".$_POST['thread']."'";

+        $result=api_sql_query($sql, __LINE__, __FILE__);

 

-               // resetting the parent_id of the thread to 0 for all
those who had this moved post as parent

-               $sql="UPDATE $table_posts SET post_parent_id='0' WHERE
post_parent_id='".Database::escape_string($values['post_id'])."'";

-               $result=Database::query($sql);

        }

 

        return get_lang('ThreadMoved');

 

 

 

Thanks for all.

 

 

 

_______________________________________________
Dev mailing list
Dev@lists.chamilo.org
http://lists.chamilo.org/listinfo/dev

Reply via email to