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

Importing New Threads

latimer

Active member
#1
I have a number of discussions from the admin section of my site that I'd like to import into XenForo. Is it as easy as creating a an entry for each thread in xf_thread, inserting the posts into xf_post then remapping the user_id + node_id to their appropriate values then rebuilding the search/thread/forum information in the admin panel? Or is there more to it that I need to take into account?
 

Mike

XenForo developer
Staff member
#2
More or less. You can look at how the importer handles it, or how threads/posts are created in the thread and forum controllers.
 

Brogan

XenForo moderator
Staff member
#3
Manually inserting data into a database is generally not recommended due to dependencies and relationships with other tables and fields.

I haven't studied the DB in detail but there is more to it than that; the xf_forum table would need updating for one, and the xf_user table.
 
R

ragtek

Guest
#4
Manually inserting data into a database is generally not recommended due to dependencies and relationships with other tables and fields.

I haven't studied the DB in detail but there is more to it than that; the xf_forum table would need updating for one, and the xf_user table.
Not really!
If you use the datawriter, xenforo handles all the stuff;)
PHP:
class Ragtek_Helper_DataWriter
{
    /**
     * Helper for XenForo Thread Datawriter to create a thread
     * @param array $user
     * @param <int> $forumId
     * @param <str> $subject
     * @param <str> $message
     * @return <array> Thread Information
     */
    static public function createThread($user, $forumId, $subject, $message)
    {
        $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
        $writer->set('user_id', $user['user_id']);
        $writer->set('username', $user['username']);
        $writer->set('title', $subject);
            $postWriter = $writer->getFirstMessageDw();
            $postWriter->set('message', $message);
        $writer->set('node_id', $forumId);
        $writer->preSave();
        $writer->save();
        return $writer->getMergedData();
    }