Skip to:
Content
Pages
Categories
Search
Top
Bottom

v2: Simple Press importer, and first thoughts


  • Mark Barnes
    Member

    @mark-barnes

    I’ve been playing with bbPress v2 for a little while now, primarily to see how easy it would be to write an importer from Simple Press. I’m sure that bbPress is going to need importers if the adoption rate is to be significant. Here are some initial thoughts:

    (1) It’s easier than I thought – largely because of the v1 import file.

    (2) We need a bbPress equivalent of wp_insert_pages, so we can call a single function, instead of creating pages, then adding lots of metadata – it’s not always clear what metadata is required, either.

    (3) In addition, it would be even better to ship with a generic import file that plugins could either modify, or plug into.

    For what it’s worth, here’s my very basic Simple Press importer. There’s no UI, error-checking is poor, and it doesn’t migrate stickies or notifications yet. You also have to update the counts from the Tools menu afterwards. And sometimes it dies through a timeout or OOM, but if it does, it should pick up where it left off. It’s a proof of concept, not a finished product, and is intended to encourage other developers, rather than for end-users. But it does work – at least for me. I may or may not develop it further, so if anyone else wants to, feel free!

    <?php
    /*
    Plugin Name: Simple Press to bbPress
    Plugin URI: http://www.4-14.org.uk/
    Description: Import Simple Press forums to bbPress
    Author: Mark Barnes
    Version: 0.1
    Author URI: http://www.4-14.org.uk/
    */

    if (isset($_GET['bbpressimport']))
    add_action ('init', 'mbbb_init');

    function mbbb_init () {
    global $wpdb;
    define('WP_IMPORTING', true);
    //Delete existing posts
    if (isset($_GET['delete'])) {
    $post_ids = $wpdb->get_results("SELECT ID from {$wpdb->posts} WHERE post_type IN ('forum', 'reply', 'topic')");
    if ($post_ids)
    foreach ($post_ids as $post_id)
    wp_delete_post ($post_id->ID, true);
    }
    // Import forums
    $forum_map = array();
    $sp_forums = $wpdb->get_results("SELECT forum_desc, forum_name, forum_slug, forum_seq, forum_id FROM {$wpdb->prefix}sfforums ORDER BY forum_seq");
    if ($sp_forums) {
    foreach ($sp_forums as $sp_forum) {
    $post_id = $wpdb->get_var ("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value='forum_{$sp_forum->forum_id}' AND meta_key='_mbbb_sp_id'");
    if (!$post_id) {
    $inserted_forum = wp_insert_post( array(
    'post_author' => get_current_user_id(),
    'post_content' => $sp_forum->forum_desc,
    'post_title' => $sp_forum->forum_name,
    'post_excerpt' => '',
    'post_status' => 'publish',
    'comment_status' => 'closed',
    'ping_status' => 'closed',
    'post_name' => $sp_forum->forum_slug,
    'post_parent' => 0,
    'post_type' => bbp_get_forum_post_type(),
    'menu_order' => $sp_forum->forum_seq
    ) );
    if ($inserted_forum) {
    echo "Added {$sp_forum->forum_name}<br/>n";
    update_post_meta( $inserted_forum, '_mbbb_sp_id', "forum_{$sp_forum->forum_id}" );
    } else
    echo "Failed to add {$sp_forum->forum_name}<br/>n";
    } else
    $inserted_forum = $post_id;
    $forum_map[$sp_forum->forum_id] = $inserted_forum;
    }
    }
    // Import topics
    $topic_count = 0;
    $sp_topics = $wpdb->get_results ("SELECT forum_id, user_id, topic_name, topic_slug, topic_date, topic_id FROM {$wpdb->prefix}sftopics ORDER BY topic_date ASC");
    if ($sp_topics) {
    foreach ($sp_topics as $sp_topic) {
    $post_id = $wpdb->get_var ("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value='topic_{$sp_topic->topic_id}' AND meta_key='_mbbb_sp_id'");
    $sp_posts = $wpdb->get_results ("SELECT topic_id, user_id, post_date, post_content, poster_ip, post_id from {$wpdb->prefix}sfposts WHERE topic_id = '{$sp_topic->topic_id}' ORDER BY post_date ASC");
    if (isset($forum_map[$sp_topic->forum_id]) && $sp_posts) {
    if (!$post_id) {
    $inserted_topic = wp_insert_post( array(
    'post_parent' => $forum_map[$sp_topic->forum_id],
    'post_author' => $sp_posts[0]->user_id,
    'post_content' => $sp_posts[0]->post_content,
    'post_title' => $sp_topic->topic_name,
    'post_name' => $sp_topic->topic_slug,
    'post_status' => 'publish',
    'post_date_gmt' => $sp_topic->topic_date,
    'post_date' => get_date_from_gmt( $sp_topic->topic_date ),
    'post_type' => bbp_get_topic_post_type(),
    ) );
    if ($inserted_topic) {
    echo "Added {$sp_topic->topic_name}<br/>n";
    update_post_meta( $inserted_topic, '_bbp_forum_id', $forum_map[$sp_topic->forum_id] );
    update_post_meta( $inserted_topic, '_bbp_topic_id', $inserted_topic );
    update_post_meta( $inserted_topic, '_mbbb_sp_id', "topic_{$sp_topic->topic_id}" );
    } else
    echo "Failed to add {$sp_forum->topic_name}<br/>n";
    } else
    $inserted_topic = $post_id;
    }
    //Import posts
    $post_count = 0;
    if ($sp_posts) {
    foreach ($sp_posts as $sp_post) {
    $post_id = $wpdb->get_var ("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value='post_{$sp_post->post_id}' AND meta_key='_mbbb_sp_id'");
    if (!$post_id) {
    if ($post_count != 0) {
    $inserted_post = wp_insert_post( array(
    'post_parent' => $inserted_topic,
    'post_author' => $sp_post->user_id,
    'post_date_gmt' => $sp_post->post_date,
    'post_date' => get_date_from_gmt( $sp_post->post_date ),
    'post_title' => 'Reply To: '.$sp_topic->topic_name,
    'post_status' => 'publish',
    'post_type' => bbp_get_reply_post_type(),
    'post_content' => $sp_post->post_content
    ) );
    if ($inserted_post) {
    update_post_meta( $inserted_post, '_bbp_author_ip', $sp_post->poster_ip );
    update_post_meta( $inserted_post, '_bbp_forum_id', $forum_map[$sp_topic->forum_id] );
    update_post_meta( $inserted_post, '_bbp_topic_id', $inserted_topic );
    update_post_meta( $inserted_post, '_mbbb_sp_id', "post_{$sp_post->post_id}" );
    bbp_update_reply_walker( $inserted_post );
    }
    }
    else
    update_post_meta( $inserted_topic, '_bbp_author_ip', $sp_post->poster_ip );
    } else
    $inserted_post = $post_id;
    $post_count ++;
    }
    }
    update_post_meta( $inserted_topic, '_bbp_last_reply_id', $inserted_post );
    update_post_meta( $inserted_topic, '_bbp_last_active_id', $inserted_post ? $inserted_post : $inserted_topic );
    update_post_meta( $inserted_topic, '_bbp_last_active_time', $inserted_post ? $sp_post->post_date : $sp_topic->topic_date );
    update_post_meta( $inserted_topic, '_bbp_reply_count', $post_count -1 );
    update_post_meta( $inserted_topic, '_bbp_hidden_reply_count', 0 );
    bbp_update_topic_walker( $inserted_topic );
    $topic_count ++;
    }
    }
    global $wp_rewrite;
    $wp_rewrite->flush_rules(false);
    }

Viewing 25 replies - 1 through 25 (of 36 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    Wow neat. :)

    The _insert_ style functions will happen before 2.0 gets released.

    Any chance you can host this in a file somewhere rather than having a large code block?


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Wow neat. :)

    The _insert_ style functions will happen before 2.0 gets released.

    Any chance you can host this in a file somewhere rather than having a large code block?


    Mark Barnes
    Member

    @mark-barnes

    I didn’t want to encourage non-programmers to use it, which is why I didn’t post a file. If I get time to tidy it up, I’ll do so (although I’ve lost edit rights to that first post now).


    Mark Barnes
    Member

    @mark-barnes

    I didn’t want to encourage non-programmers to use it, which is why I didn’t post a file. If I get time to tidy it up, I’ll do so (although I’ve lost edit rights to that first post now).


    Mark Barnes
    Member

    @mark-barnes

    In case anyone is interested in seeing the results, here’s a temporary glimpse:

    bbPress:

    http://www.sermonbrowser.com/forums/forum/sermon-browser-support/

    SimplePress:

    http://www.sermonbrowser.com/forum/sermon-browser-support/

    I was fortunate in that my custom theme was a child theme of TwentyTen. All I needed to do was convert my child theme to a plugin, so I could use bbPress’s child theme instead.

    Next up is to get rid of the sidebar of bbPress pages, but I’m not sure that’s possible yet, without hacking core bbPress files.


    Mark Barnes
    Member

    @mark-barnes

    In case anyone is interested in seeing the results, here’s a temporary glimpse:

    bbPress:

    http://www.sermonbrowser.com/forums/forum/sermon-browser-support/

    SimplePress:

    http://www.sermonbrowser.com/forum/sermon-browser-support/

    I was fortunate in that my custom theme was a child theme of TwentyTen. All I needed to do was convert my child theme to a plugin, so I could use bbPress’s child theme instead.

    Next up is to get rid of the sidebar of bbPress pages, but I’m not sure that’s possible yet, without hacking core bbPress files.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Neat. I definitely like the bbPress forums better. :)


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Neat. I definitely like the bbPress forums better. :)

    Hello, I’m very interested in that plugin. I have been waiting for something similar for months because my skills with bbpress and simple-press are not good enougth, but it seems a miracle someone build it.

    How it is supposed can it be used?

    I have wrote a file called import.php in the my-plugins folder, activated the plugin and tried to fire it with myforum.com?bbpressimport=1, but it does nothing.

    I’ve also modified the statistics.php and added directly the function mbbb_init() and then loaded directly on index.php, but it also does nothing.

    My bbpress is not integrated, but sits on the same database (different table prefixes)

    Could you help with that?

    Thank you in advance

    Hello, I’m very interested in that plugin. I have been waiting for something similar for months because my skills with bbpress and simple-press are not good enougth, but it seems a miracle someone build it.

    How it is supposed can it be used?

    I have wrote a file called import.php in the my-plugins folder, activated the plugin and tried to fire it with myforum.com?bbpressimport=1, but it does nothing.

    I’ve also modified the statistics.php and added directly the function mbbb_init() and then loaded directly on index.php, but it also does nothing.

    My bbpress is not integrated, but sits on the same database (different table prefixes)

    Could you help with that?

    Thank you in advance


    SeizedPropaganda
    Member

    @seizedpropaganda

    Hey, just thought I would resurrect this thread because I am actually about to attempt the same thing and I was wondering if anyone has come across a better/easier solution than this one?

    I will post my experiences with using this importer script if nobody else can make any suggestions.


    SeizedPropaganda
    Member

    @seizedpropaganda

    Hey, just thought I would resurrect this thread because I am actually about to attempt the same thing and I was wondering if anyone has come across a better/easier solution than this one?

    I will post my experiences with using this importer script if nobody else can make any suggestions.

    Hey–

    I am using this little plugin and it actually IS working, except that all of the posts in the forum are now being attributed to me (or whatever account tries the conversion). Any suggestions on how to keep the original poster attached?

    Hey–

    I am using this little plugin and it actually IS working, except that all of the posts in the forum are now being attributed to me (or whatever account tries the conversion). Any suggestions on how to keep the original poster attached?

    hi @Mark Barnes i tried your codes, saved to file and upload it on plugin folder then activated it..

    after activation i am looking for the import button or something like that … i can’t find it… can you please help me where to find it?

    thank you

    hi @Mark Barnes i tried your codes, saved to file and upload it on plugin folder then activated it..

    after activation i am looking for the import button or something like that … i can’t find it… can you please help me where to find it?

    thank you

    Hi

    Thanks for sharing

    but i have one problem

    All post from guests now display as admins post.

    How i can fix it?

    Hi

    Thanks for sharing

    but i have one problem

    All post from guests now display as admins post.

    How i can fix it?


    Gautam Gupta
    Moderator

    @gautamgupta

    It looks like this importer doesn’t support anonymous replies. You’d have to add the appropriate conditions yourself and re-import. :)


    Gautam Gupta
    Moderator

    @gautamgupta

    It looks like this importer doesn’t support anonymous replies. You’d have to add the appropriate conditions yourself and re-import. :)

    Please tell me what to write here

    Now the author of topic is always admin.

    //Topic Author - Guest (What code here?)

    if(!($sp_topic->user_id))

    {

    echo("  Guest start topic: {$sp_posts[0]->guest_name}n");

    // update_post_meta( $inserted_topic, '_bbp_anonymous_name', "{$sp_posts[0]->guest_name}" );

    // update_post_meta( $inserted_topic, '_bbp_anonymous_email', "{$sp_posts[0]->guest_email}" );

    // ??????

    }

    I am a newbie in php – use at your own risk!!!

    <?php

    /*

    Plugin Name: Simple Press to bbPress

    Plugin URI: http://www.4-14.org.uk/

    Description: Import Simple Press forums to bbPress

    Author: Mark Barnes

    Version: 0.1

    Author URI: http://www.4-14.org.uk/

    using: http://site.com?bbpressimport=1&delete=1

    */

    if (isset($_GET))

    add_action (‘init’, ‘mbbb_init’);

    function mbbb_init () {

    global $wpdb;

    define(‘WP_IMPORTING’, true);

    //Delete existing posts

    if (isset($_GET)) {

    $post_ids = $wpdb->get_results(“SELECT ID from {$wpdb->posts} WHERE post_type IN (‘forum’, ‘reply’, ‘topic’)”);

    if ($post_ids)

    foreach ($post_ids as $post_id)

    wp_delete_post ($post_id->ID, true);

    }

    // Import forums

    $forum_map = array();

    $sp_forums = $wpdb->get_results(“SELECT forum_desc, forum_name, forum_slug, forum_seq, forum_id FROM {$wpdb->prefix}sfforums ORDER BY forum_seq”);

    if ($sp_forums) {

    foreach ($sp_forums as $sp_forum) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’forum_{$sp_forum->forum_id}’ AND meta_key=’_mbbb_sp_id'”);

    if (!$post_id) {

    $inserted_forum = wp_insert_post( array(

    ‘post_author’ => get_current_user_id(),

    ‘post_content’ => $sp_forum->forum_desc,

    ‘post_title’ => $sp_forum->forum_name,

    ‘post_excerpt’ => ”,

    ‘post_status’ => ‘publish’,

    ‘comment_status’ => ‘closed’,

    ‘ping_status’ => ‘closed’,

    ‘post_name’ => $sp_forum->forum_slug,

    ‘post_parent’ => 0,

    ‘post_type’ => bbp_get_forum_post_type(),

    ‘menu_order’ => $sp_forum->forum_seq

    ) );

    if ($inserted_forum) {

    echo “Added {$sp_forum->forum_name}n”;

    update_post_meta( $inserted_forum, ‘_mbbb_sp_id’, “forum_{$sp_forum->forum_id}” );

    } else

    echo “Failed to add {$sp_forum->forum_name}n”;

    } else

    $inserted_forum = $post_id;

    $forum_map[$sp_forum->forum_id] = $inserted_forum;

    }

    }

    // Import topics

    $topic_count = 0;

    $sp_topics = $wpdb->get_results (“SELECT forum_id, user_id, topic_name, topic_slug, topic_date, topic_id FROM {$wpdb->prefix}sftopics ORDER BY topic_date ASC”);

    if ($sp_topics) {

    foreach ($sp_topics as $sp_topic) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’topic_{$sp_topic->topic_id}’ AND meta_key=’_mbbb_sp_id'”);

    $sp_posts = $wpdb->get_results (“SELECT topic_id, user_id, post_date, guest_name, guest_email, post_content, poster_ip, post_id from {$wpdb->prefix}sfposts WHERE topic_id = ‘{$sp_topic->topic_id}’ ORDER BY post_date ASC”);

    if (isset($forum_map[$sp_topic->forum_id]) && $sp_posts) {

    if (!$post_id) {

    if(! empty($sp_posts[0]->guest_name))

    {

    echo(“Topic: {$sp_topic->topic_name}n”);

    echo(“Guest name: {$sp_posts[0]->guest_name}n”);

    $inserted_topic = wp_insert_post( array(

    ‘post_parent’ => $forum_map[$sp_topic->forum_id],

    ‘post_content’ => $sp_posts[0]->post_content,

    ‘post_title’ => $sp_topic->topic_name,

    ‘post_name’ => $sp_topic->topic_slug,

    ‘post_status’ => ‘publish’,

    ‘post_date_gmt’ => $sp_topic->topic_date,

    ‘post_date’ => get_date_from_gmt( $sp_topic->topic_date ),

    ‘post_type’ => bbp_get_topic_post_type(),

    ) );

    if ($inserted_topic) {

    update_post_meta( $inserted_topic, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_topic, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_topic, ‘_mbbb_sp_id’, “topic_{$sp_topic->topic_id}” );

    update_post_meta( $inserted_topic, ‘_bbp_anonymous_name’, “{$sp_posts[0]->guest_name}” );

    update_post_meta( $inserted_topic, ‘_bbp_anonymous_email’, “{$sp_posts[0]->guest_email}” );

    } else

    echo “Failed to add {$sp_forum->topic_name}n”;

    }

    else

    {

    if(!($sp_posts[0]->user_id))

    echo(“Guest TOPICStart: {$sp_posts[0]->guest_name}n”);

    $inserted_topic = wp_insert_post( array(

    ‘post_parent’ => $forum_map[$sp_topic->forum_id],

    ‘post_author’ => $sp_posts[0]->user_id,

    ‘post_content’ => $sp_posts[0]->post_content,

    ‘post_title’ => $sp_topic->topic_name,

    ‘post_name’ => $sp_topic->topic_slug,

    ‘post_status’ => ‘publish’,

    ‘post_date_gmt’ => $sp_topic->topic_date,

    ‘post_date’ => get_date_from_gmt( $sp_topic->topic_date ),

    ‘post_type’ => bbp_get_topic_post_type(),

    ) );

    if ($inserted_topic) {

    echo “Added {$sp_topic->topic_name}n”;

    update_post_meta( $inserted_topic, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_topic, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_topic, ‘_mbbb_sp_id’, “topic_{$sp_topic->topic_id}” );

    } else

    echo “Failed to add {$sp_forum->topic_name}n”;

    }

    }

    else{

    echo “ADD”;

    $inserted_topic = $post_id;

    }

    }

    //Import posts

    $post_count = 0;

    if ($sp_posts) {

    foreach ($sp_posts as $sp_post) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’post_{$sp_post->post_id}’ AND meta_key=’_mbbb_sp_id'”);

    if (!$post_id) {

    if ($post_count != 0) {

    if(! empty($sp_post->guest_name))

    {

    echo(”    Reply To: {$sp_topic->topic_name}n”);

    echo(”    Guest name: {$sp_post->guest_name}n”);

    $inserted_post = wp_insert_post( array(

    ‘post_parent’ => $inserted_topic,

    ‘post_date_gmt’ => $sp_post->post_date,

    ‘post_date’ => get_date_from_gmt( $sp_post->post_date ),

    ‘post_title’ => ‘Reply To: ‘.$sp_topic->topic_name,

    ‘post_status’ => ‘publish’,

    ‘post_type’ => bbp_get_reply_post_type(),

    ‘post_content’ => $sp_post->post_content

    ) );

    if ($inserted_post) {

    update_post_meta( $inserted_post, ‘_bbp_author_ip’, $sp_post->poster_ip );

    update_post_meta( $inserted_post, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_post, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_post, ‘_mbbb_sp_id’, “post_{$sp_post->post_id}” );

    update_post_meta( $inserted_post, ‘_bbp_anonymous_name’, “{$sp_post->guest_name}” );

    update_post_meta( $inserted_post, ‘_bbp_anonymous_email’, “{$sp_post->guest_email}” );

    bbp_update_reply_walker( $inserted_post );

    }

    }

    else

    {

    $inserted_post = wp_insert_post( array(

    ‘post_parent’ => $inserted_topic,

    ‘post_author’ => $sp_post->user_id,

    ‘post_date_gmt’ => $sp_post->post_date,

    ‘post_date’ => get_date_from_gmt( $sp_post->post_date ),

    ‘post_title’ => ‘Reply To: ‘.$sp_topic->topic_name,

    ‘post_status’ => ‘publish’,

    ‘post_type’ => bbp_get_reply_post_type(),

    ‘post_content’ => $sp_post->post_content

    ) );

    if ($inserted_post) {

    update_post_meta( $inserted_post, ‘_bbp_author_ip’, $sp_post->poster_ip );

    update_post_meta( $inserted_post, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_post, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_post, ‘_mbbb_sp_id’, “post_{$sp_post->post_id}” );

    bbp_update_reply_walker( $inserted_post );

    }

    }

    }

    else

    update_post_meta( $inserted_topic, ‘_bbp_author_ip’, $sp_post->poster_ip );

    } else

    {

    $inserted_post = $post_id;

    // echo(“Guest start topic:n”);

    }

    $post_count ++;

    }

    }

    // echo(“Guest start topic:{$sp_topic->user_id}n”);

    update_post_meta( $inserted_topic, ‘_bbp_last_reply_id’, $inserted_post );

    update_post_meta( $inserted_topic, ‘_bbp_last_active_id’, $inserted_post ? $inserted_post : $inserted_topic );

    update_post_meta( $inserted_topic, ‘_bbp_last_active_time’, $inserted_post ? $sp_post->post_date : $sp_topic->topic_date );

    update_post_meta( $inserted_topic, ‘_bbp_reply_count’, $post_count -1 );

    update_post_meta( $inserted_topic, ‘_bbp_hidden_reply_count’, 0 );

    //Topic Author – Guest (What code here?)

    if(!($sp_topic->user_id))

    {

    echo(”  Guest start topic: {$sp_posts[0]->guest_name}n”);

    // update_post_meta( $inserted_topic, ‘_bbp_anonymous_name’, “{$sp_posts[0]->guest_name}” );

    // update_post_meta( $inserted_topic, ‘_bbp_anonymous_email’, “{$sp_posts[0]->guest_email}” );

    // ??????

    }

    bbp_update_topic_walker( $inserted_topic );

    $topic_count ++;

    }

    }

    global $wp_rewrite;

    $wp_rewrite->flush_rules(false);

    }

    Please tell me what to write here

    Now the author of topic is always admin.

    //Topic Author - Guest (What code here?)

    if(!($sp_topic->user_id))

    {

    echo("  Guest start topic: {$sp_posts[0]->guest_name}n");

    // update_post_meta( $inserted_topic, '_bbp_anonymous_name', "{$sp_posts[0]->guest_name}" );

    // update_post_meta( $inserted_topic, '_bbp_anonymous_email', "{$sp_posts[0]->guest_email}" );

    // ??????

    }

    I am a newbie in php – use at your own risk!!!

    <?php

    /*

    Plugin Name: Simple Press to bbPress

    Plugin URI: http://www.4-14.org.uk/

    Description: Import Simple Press forums to bbPress

    Author: Mark Barnes

    Version: 0.1

    Author URI: http://www.4-14.org.uk/

    using: http://site.com?bbpressimport=1&delete=1

    */

    if (isset($_GET))

    add_action (‘init’, ‘mbbb_init’);

    function mbbb_init () {

    global $wpdb;

    define(‘WP_IMPORTING’, true);

    //Delete existing posts

    if (isset($_GET)) {

    $post_ids = $wpdb->get_results(“SELECT ID from {$wpdb->posts} WHERE post_type IN (‘forum’, ‘reply’, ‘topic’)”);

    if ($post_ids)

    foreach ($post_ids as $post_id)

    wp_delete_post ($post_id->ID, true);

    }

    // Import forums

    $forum_map = array();

    $sp_forums = $wpdb->get_results(“SELECT forum_desc, forum_name, forum_slug, forum_seq, forum_id FROM {$wpdb->prefix}sfforums ORDER BY forum_seq”);

    if ($sp_forums) {

    foreach ($sp_forums as $sp_forum) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’forum_{$sp_forum->forum_id}’ AND meta_key=’_mbbb_sp_id'”);

    if (!$post_id) {

    $inserted_forum = wp_insert_post( array(

    ‘post_author’ => get_current_user_id(),

    ‘post_content’ => $sp_forum->forum_desc,

    ‘post_title’ => $sp_forum->forum_name,

    ‘post_excerpt’ => ”,

    ‘post_status’ => ‘publish’,

    ‘comment_status’ => ‘closed’,

    ‘ping_status’ => ‘closed’,

    ‘post_name’ => $sp_forum->forum_slug,

    ‘post_parent’ => 0,

    ‘post_type’ => bbp_get_forum_post_type(),

    ‘menu_order’ => $sp_forum->forum_seq

    ) );

    if ($inserted_forum) {

    echo “Added {$sp_forum->forum_name}n”;

    update_post_meta( $inserted_forum, ‘_mbbb_sp_id’, “forum_{$sp_forum->forum_id}” );

    } else

    echo “Failed to add {$sp_forum->forum_name}n”;

    } else

    $inserted_forum = $post_id;

    $forum_map[$sp_forum->forum_id] = $inserted_forum;

    }

    }

    // Import topics

    $topic_count = 0;

    $sp_topics = $wpdb->get_results (“SELECT forum_id, user_id, topic_name, topic_slug, topic_date, topic_id FROM {$wpdb->prefix}sftopics ORDER BY topic_date ASC”);

    if ($sp_topics) {

    foreach ($sp_topics as $sp_topic) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’topic_{$sp_topic->topic_id}’ AND meta_key=’_mbbb_sp_id'”);

    $sp_posts = $wpdb->get_results (“SELECT topic_id, user_id, post_date, guest_name, guest_email, post_content, poster_ip, post_id from {$wpdb->prefix}sfposts WHERE topic_id = ‘{$sp_topic->topic_id}’ ORDER BY post_date ASC”);

    if (isset($forum_map[$sp_topic->forum_id]) && $sp_posts) {

    if (!$post_id) {

    if(! empty($sp_posts[0]->guest_name))

    {

    echo(“Topic: {$sp_topic->topic_name}n”);

    echo(“Guest name: {$sp_posts[0]->guest_name}n”);

    $inserted_topic = wp_insert_post( array(

    ‘post_parent’ => $forum_map[$sp_topic->forum_id],

    ‘post_content’ => $sp_posts[0]->post_content,

    ‘post_title’ => $sp_topic->topic_name,

    ‘post_name’ => $sp_topic->topic_slug,

    ‘post_status’ => ‘publish’,

    ‘post_date_gmt’ => $sp_topic->topic_date,

    ‘post_date’ => get_date_from_gmt( $sp_topic->topic_date ),

    ‘post_type’ => bbp_get_topic_post_type(),

    ) );

    if ($inserted_topic) {

    update_post_meta( $inserted_topic, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_topic, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_topic, ‘_mbbb_sp_id’, “topic_{$sp_topic->topic_id}” );

    update_post_meta( $inserted_topic, ‘_bbp_anonymous_name’, “{$sp_posts[0]->guest_name}” );

    update_post_meta( $inserted_topic, ‘_bbp_anonymous_email’, “{$sp_posts[0]->guest_email}” );

    } else

    echo “Failed to add {$sp_forum->topic_name}n”;

    }

    else

    {

    if(!($sp_posts[0]->user_id))

    echo(“Guest TOPICStart: {$sp_posts[0]->guest_name}n”);

    $inserted_topic = wp_insert_post( array(

    ‘post_parent’ => $forum_map[$sp_topic->forum_id],

    ‘post_author’ => $sp_posts[0]->user_id,

    ‘post_content’ => $sp_posts[0]->post_content,

    ‘post_title’ => $sp_topic->topic_name,

    ‘post_name’ => $sp_topic->topic_slug,

    ‘post_status’ => ‘publish’,

    ‘post_date_gmt’ => $sp_topic->topic_date,

    ‘post_date’ => get_date_from_gmt( $sp_topic->topic_date ),

    ‘post_type’ => bbp_get_topic_post_type(),

    ) );

    if ($inserted_topic) {

    echo “Added {$sp_topic->topic_name}n”;

    update_post_meta( $inserted_topic, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_topic, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_topic, ‘_mbbb_sp_id’, “topic_{$sp_topic->topic_id}” );

    } else

    echo “Failed to add {$sp_forum->topic_name}n”;

    }

    }

    else{

    echo “ADD”;

    $inserted_topic = $post_id;

    }

    }

    //Import posts

    $post_count = 0;

    if ($sp_posts) {

    foreach ($sp_posts as $sp_post) {

    $post_id = $wpdb->get_var (“SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_value=’post_{$sp_post->post_id}’ AND meta_key=’_mbbb_sp_id'”);

    if (!$post_id) {

    if ($post_count != 0) {

    if(! empty($sp_post->guest_name))

    {

    echo(”    Reply To: {$sp_topic->topic_name}n”);

    echo(”    Guest name: {$sp_post->guest_name}n”);

    $inserted_post = wp_insert_post( array(

    ‘post_parent’ => $inserted_topic,

    ‘post_date_gmt’ => $sp_post->post_date,

    ‘post_date’ => get_date_from_gmt( $sp_post->post_date ),

    ‘post_title’ => ‘Reply To: ‘.$sp_topic->topic_name,

    ‘post_status’ => ‘publish’,

    ‘post_type’ => bbp_get_reply_post_type(),

    ‘post_content’ => $sp_post->post_content

    ) );

    if ($inserted_post) {

    update_post_meta( $inserted_post, ‘_bbp_author_ip’, $sp_post->poster_ip );

    update_post_meta( $inserted_post, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_post, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_post, ‘_mbbb_sp_id’, “post_{$sp_post->post_id}” );

    update_post_meta( $inserted_post, ‘_bbp_anonymous_name’, “{$sp_post->guest_name}” );

    update_post_meta( $inserted_post, ‘_bbp_anonymous_email’, “{$sp_post->guest_email}” );

    bbp_update_reply_walker( $inserted_post );

    }

    }

    else

    {

    $inserted_post = wp_insert_post( array(

    ‘post_parent’ => $inserted_topic,

    ‘post_author’ => $sp_post->user_id,

    ‘post_date_gmt’ => $sp_post->post_date,

    ‘post_date’ => get_date_from_gmt( $sp_post->post_date ),

    ‘post_title’ => ‘Reply To: ‘.$sp_topic->topic_name,

    ‘post_status’ => ‘publish’,

    ‘post_type’ => bbp_get_reply_post_type(),

    ‘post_content’ => $sp_post->post_content

    ) );

    if ($inserted_post) {

    update_post_meta( $inserted_post, ‘_bbp_author_ip’, $sp_post->poster_ip );

    update_post_meta( $inserted_post, ‘_bbp_forum_id’, $forum_map[$sp_topic->forum_id] );

    update_post_meta( $inserted_post, ‘_bbp_topic_id’, $inserted_topic );

    update_post_meta( $inserted_post, ‘_mbbb_sp_id’, “post_{$sp_post->post_id}” );

    bbp_update_reply_walker( $inserted_post );

    }

    }

    }

    else

    update_post_meta( $inserted_topic, ‘_bbp_author_ip’, $sp_post->poster_ip );

    } else

    {

    $inserted_post = $post_id;

    // echo(“Guest start topic:n”);

    }

    $post_count ++;

    }

    }

    // echo(“Guest start topic:{$sp_topic->user_id}n”);

    update_post_meta( $inserted_topic, ‘_bbp_last_reply_id’, $inserted_post );

    update_post_meta( $inserted_topic, ‘_bbp_last_active_id’, $inserted_post ? $inserted_post : $inserted_topic );

    update_post_meta( $inserted_topic, ‘_bbp_last_active_time’, $inserted_post ? $sp_post->post_date : $sp_topic->topic_date );

    update_post_meta( $inserted_topic, ‘_bbp_reply_count’, $post_count -1 );

    update_post_meta( $inserted_topic, ‘_bbp_hidden_reply_count’, 0 );

    //Topic Author – Guest (What code here?)

    if(!($sp_topic->user_id))

    {

    echo(”  Guest start topic: {$sp_posts[0]->guest_name}n”);

    // update_post_meta( $inserted_topic, ‘_bbp_anonymous_name’, “{$sp_posts[0]->guest_name}” );

    // update_post_meta( $inserted_topic, ‘_bbp_anonymous_email’, “{$sp_posts[0]->guest_email}” );

    // ??????

    }

    bbp_update_topic_walker( $inserted_topic );

    $topic_count ++;

    }

    }

    global $wp_rewrite;

    $wp_rewrite->flush_rules(false);

    }

    Solved!

    $wpdb->query("UPDATE wp_posts SET post_author = '0' WHERE ID =".$inserted_topic.";");

    Solved!

    $wpdb->query("UPDATE wp_posts SET post_author = '0' WHERE ID =".$inserted_topic.";");


    jotaace
    Participant

    @jotaace

    Hi AlexKramer,

    Sorry but i can’t find the way to use the plugin. Would you mind to post a little instructions on its usage? I only know how to paste the code in a txt file, renaming as php, zipping and installing as a plugin.

    And where to paste the code lines of your previous post in the plugin, please?

    I’ll be very grateful if I really can import my forum.

    Thanks in advance.

Viewing 25 replies - 1 through 25 (of 36 total)

You must be logged in to reply to this topic.