1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Moving 'topics' via SQL command messes up indexing

Discussion in 'XenForo Development Discussions' started by Mt.Rev, Jan 5, 2012.

  1. Mt.Rev

    Mt.Rev Member


    I had been moving topics to different forums categories and I noticed the "last post" info doesn't update on it's own like how it normally would if I did it from the actual forum.
    Also, if I don't 'rebuild' the post content from the ACP, everything seems to be totally out of place. URLs doesn't bring you to the right post and members' profile page "Postings" would also be incorrect.

    I already rebuild the topics and everything is back to normal, but it took about 3-4 hours to complete and was very resource intensive. And I do keep planning on using SQL queries to move other topics, but I was hoping somneone could show me how I could rebuild that single topic that being moved also using SQL queries (as how the built-in tool would normally work for moving topics).

    I hope i'm explaining myself correctly.

    Thanks in advance!
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Why are you routinely moving threads using SQL queries?
  3. Mt.Rev

    Mt.Rev Member

    Hi Brogan,

    I use keywords to find misplaced topics and move them to the correct section of the forum. This saves hours or even days of work. This is why I'm seeking for the SQL command to do how the forum's built-in tools would normal execute it.
  4. Brogan

    Brogan XenForo Moderator Staff Member

    What is the query you are using to move threads?
  5. Mt.Rev

    Mt.Rev Member

    UPDATE xf_thread SET node_id =1 WHERE node_id !=5 && node_id !=6 && (title LIKE '%ABC%' OR title LIKE '%XYZ%');
    I was hoping someone who was familiar with XF would show me the SQL query that would rebuilds only the affected topics after the above query is ran.
  6. Mt.Rev

    Mt.Rev Member

    I don't know if this is appropriate, but I can donate $25 to anyone who can help me with this with PayPal or AlertPay.
  7. Mt.Rev

    Mt.Rev Member

    Is there a way to only 'Rebuild' posts where "last_post_date" less then 24 hours?
  8. digitalpoint

    digitalpoint Well-Known Member

    You really would be better off spinning them through the thread datawriter... that way you don't need to worry about backend stuff that happens (for example indexing).

    A direct query like you are doing may be easier in the short-term, in the long term it's just going to cause problems (like you see with search indexes)... Some other things I can think of that might be managed internally when moving a thread to a different node... Like maybe something happens with thread subscriptions if a thread is moved to somewhere that the subscribed user can't access it anymore (a node they don't have permission to).

    Let the datawriters handle the dirty work... that's what they are there for.
    $writer XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
  9. Mt.Rev

    Mt.Rev Member

    To be honest, I'm not even sure what i'm looking at. :unsure:

    How would I go about this?
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    What digitalpoint is suggesting is that you take and write a cron job that'll preform the queries to find them IDs to move and then run proper functions to move the thread, so anything that happens behind the scenes happens behind the scenes.
  11. digitalpoint

    digitalpoint Well-Known Member

    Wouldn't even need a cron job... can just do it right then and there (as you are moving stuff).

Share This Page