• Note: Discussing 3.5… I’ve tried 3.6 and it seems to have similar issues. Also, this is more of a something I’d like to share note rather an actual issue since for the most part I’ve hacked around it.
    Hi – I encountered a couple issues importing comments on my sites:
    1) Anonymous comments without names were assigned to the administrator, avatar and ip included.
    2) When I first used the plugin I couldn’t find the bulk import through the discussion area in the admin panel, and by the time I did I already imported several posts one-by-one. The bulk import failed, even after deleting the respective posts+topics.

    So, I mucked around with code and found that it may be that the bbppt_imported comment meta flag stays set regardless of whether or not the topics/posts were deleted.
    —————–
    Note that this may be due to user error but I did put in some hacks to work around these. A couple caveats:
    1) The anonymous user issue isn’t 100% solved – the anonymous comments (all of them, even though with names other than anonymous) show up the in the administrator’s posting history. I’m not sure how bbpress handles anonymous ids and such and that may be the way to go…
    2) The logic to workaround the topics already been deleted works, but the $force_import_comments thing is a bit of a hack – maybe I need to override the do_import_comment filter or make it next to ! get_comment_meta( $post_comment->comment_ID, ‘bbppt_imported’, true ) in apply_filters
    ——-
    Patch (diff -bu):

    --- bbpress-post-topics\index.php 2012-10-19 02:27:48.000000000 -0700
    +++ bbpress-post-topics2\index.php 2013-04-14 16:07:52.626601800 -0700
    @@ -192,6 +192,8 @@
    return;
    }

    + $force_import_comments = false;
    +
    if( isset( $_POST['bbpress_topic'] ) ) {
    /**
    * Post was created through the full post editor form
    @@ -221,11 +223,37 @@

    $bbppt_options = $this->get_topic_options_for_post( $post_ID );
    $create_topic = ( isset($bbppt_options['enabled']) && $bbppt_options['enabled'] );
    +
    + $topic_slug = isset( $bbppt_options['slug'] ) ? $bbppt_options['slug'] : '';
    + if(! empty( $topic_slug ) ) {
    + if( is_numeric( $topic_slug ) ) {
    + $topic = bbp_get_topic( (int)$topic_slug );
    + } else {
    + $topic = bbppt_get_topic_by_slug( $topic_slug );
    + }
    + }
    +
    + if( empty( $topic_slug ) || $topic != null ) {
    $use_defaults = ( isset( $bbppt_options['use_defaults'] ) && $bbppt_options['use_defaults'] );

    bbppt_debug( 'Processing topic for existing post ' . $post_ID . ' with the following settings: ' . print_r( $bbppt_options, true ) );
    bbppt_debug( 'Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults );
    + }
    + else {
    + /**
    + * Post marked with existing topic but topic deleted - use defaults
    + */
    + $bbppt_options = get_option( 'bbpress_discussion_defaults' );
    + $use_defaults = true;
    +
    + /**
    + * Force comment import
    + */
    + $force_import_comments = true;

    + bbppt_debug( 'Processing a previously deleted topic for unattended post ' . $post_ID . ' with the following settings: ' . print_r( $bbppt_options, true ) );
    + bbppt_debug( 'Creating topic?: ' . $create_topic . '; using defaults?: ' . $use_defaults );
    + }
    } else if( $this->has_draft_settings( $post ) ) {
    /**
    * If the post has draft settings saved, use draft settings
    @@ -312,7 +340,7 @@

    /** Export comments from the post to the new bbPress topic */
    if( $bbppt_options['copy_comments'] ) {
    - bbppt_import_comments( $post_ID, $topic_ID );
    + bbppt_import_comments( $post_ID, $topic_ID, $force_import_comments );
    update_post_meta( $post_ID, 'bbpress_discussion_comments_copied', time() );
    }

    @@ -349,7 +377,7 @@

    /** Export comments from the post to the new bbPress topic */
    if( $bbppt_options['copy_comments'] ) {
    - bbppt_import_comments( $post_ID, $topic_ID );
    + bbppt_import_comments( $post_ID, $topic_ID, $force_import_comments );
    update_post_meta( $post_ID, 'bbpress_discussion_comments_copied', time() );
    }

    @@ -957,7 +985,7 @@
    * @param int $post_id ID of the post whose comments to import to topic
    * @param int $topic_id ID of the topic where comments will be added as replies
    */
    -function bbppt_import_comments( $post_id, $topic_id ) {
    +function bbppt_import_comments( $post_id, $topic_id, $force_import = false ) {

    $topic_forum = bbp_get_topic_forum_id( $topic_id );

    @@ -974,7 +1002,7 @@
    /** Allow individual comments to be skipped with bbppt_do_import_comment filter
    * By default, skip comments that have already been imported
    */
    – if( ! apply_filters( ‘bbppt_do_import_comment’, ! get_comment_meta( $post_comment->comment_ID, ‘bbppt_imported’, true ), $post_comment ) )
    + if( ! $force_import && ! apply_filters( ‘bbppt_do_import_comment’, ! get_comment_meta( $post_comment->comment_ID, ‘bbppt_imported’, true ), $post_comment ) )
    continue;

    // If user is not registered
    @@ -988,6 +1016,12 @@
    $post_comment->user_id = $existing_user->ID;
    }

    + // 2. Give the user the name “Anonymous” if not found, otherwise bbpress
    + // will assign it the administrator’s account, avatar and all
    + if( empty( $post_comment->user_id ) && empty( $post_comment->comment_author )) {
    + $post_comment->comment_author = ‘Anonymous’;
    + }
    +
    }

    // Reply data

    http://ww.wp.xz.cn/extend/plugins/bbpress-post-topics/

Viewing 1 replies (of 1 total)
  • Hi bmkdnf –

    Thanks for catching these issues!

    You know I’m not really sure how/if bbPress handles anonymous replies. What you’ve posted is a great start, but I’ll take a look and see what bbPress is expecting and if it can be made cleaner.

    I think a better solution to the situation where a deleted topic orphans the postmeta topic_id is to hook bbp_delete_topic and check it against postmeta values. Maybe the topic should also carry a meta value referencing the topic, although that might introduce more trouble than it’s worth.

    The same could be done for comments and replies, since the reply meta stores the comment ID.

    – David

Viewing 1 replies (of 1 total)

The topic ‘Importing Comments: Anonymous Users Reimporting’ is closed to new replies.