Importing New Threads

latimer

Active member
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?
 
More or less. You can look at how the importer handles it, or how threads/posts are created in the thread and forum controllers.
 
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.
 
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();
    }
 
That's why i (tried to)say, that he should use the datawriter instead of the query.
 
Top Bottom