Skip to:
Content

bbPress.org

Changeset 5542


Ignore:
Timestamp:
10/01/2014 04:59:14 AM (10 years ago)
Author:
netweb
Message:

Vanilla2: Include anonymous topic and reply import support in Vanilla.php importer
Props netweb. See #2347

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/converters/Vanilla.php

    r5537 r5542  
    198198        );
    199199
     200        // Topic author name (Stored in postmeta as _bbp_anonymous_name)
     201        $this->field_map[] = array(
     202            'to_type'      => 'topic',
     203            'to_fieldname' => '_bbp_old_topic_author_name_id',
     204            'default'      => 'Anonymous'
     205        );
     206
     207        // Is the topic anonymous (Stored in postmeta)
     208        $this->field_map[] = array(
     209            'from_tablename'  => 'Discussion',
     210            'from_fieldname'  => 'InsertUserID',
     211            'to_type'         => 'topic',
     212            'to_fieldname'    => '_bbp_old_is_topic_anonymous_id',
     213            'callback_method' => 'callback_check_anonymous'
     214        );
     215
    200216        // Topic title.
    201217        $this->field_map[] = array(
     
    368384        );
    369385
     386        // Reply author name (Stored in postmeta as _bbp_anonymous_name)
     387        $this->field_map[] = array(
     388            'to_type'      => 'reply',
     389            'to_fieldname' => '_bbp_old_reply_author_name_id',
     390            'default'      => 'Anonymous'
     391        );
     392
     393        // Is the reply anonymous (Stored in postmeta)
     394        $this->field_map[] = array(
     395            'from_tablename'  => 'Comment',
     396            'from_fieldname'  => 'InsertUserID',
     397            'to_type'         => 'reply',
     398            'to_fieldname'    => '_bbp_old_is_reply_anonymous_id',
     399            'callback_method' => 'callback_check_anonymous'
     400        );
     401
    370402        // Reply content.
    371403        $this->field_map[] = array(
     
    544576        $count = absint( (int) $count - 1 );
    545577        return $count;
     578    }
     579
     580    /**
     581     * Check the anonymous topic or reply status.
     582     *
     583     * This method checks each imported topic or reply if the author user ID
     584     * was imported to determine if the topic or reply author is anonymous as
     585     * Vanilla v2.x does not store a topic or reply status for deleted users.
     586     *
     587     * @since  (r5541)
     588     *
     589     * @param string $is_user_anonymous Vanilla v2.x numeric topic status
     590     * @return string WordPress safe
     591     */
     592    public function callback_check_anonymous( $is_user_anonymous = 0 ) {
     593        if ( !empty( $this->sync_table ) ) {
     594            $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%d" LIMIT 1', $is_user_anonymous ) );
     595        } else {
     596            $row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT meta_value FROM ' . $this->wpdb->usermeta .  ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%d" LIMIT 1', $is_user_anonymous ) );
     597        }
     598
     599        // An imported user ID exists therefore the topic/reply is not anonymous
     600        if ( !is_null( $row ) ) {
     601            $is_user_anonymous = 'false';
     602        // No imported user ID there the topic/reply is anonymous
     603        } else {
     604            $is_user_anonymous = 'true';
     605        }
     606
     607        return $is_user_anonymous;
    546608    }
    547609
Note: See TracChangeset for help on using the changeset viewer.