Skip to:
Content

bbPress.org

Ticket #2347: 2347.diff

File 2347.diff, 7.4 KB (added by netweb, 10 years ago)
  • includes/admin/converters/phpBB.php

     
    193193                        'callback_method' => 'callback_userid'
    194194                );
    195195
     196                // Topic first poster name (Used for storing original topic author, Stored in postmeta)
     197                // Note: See #2347 http://bbpress.trac.wordpress.org/ticket/2347#comment:7
     198                $this->field_map[] = array(
     199                        'from_tablename'  => 'topics',
     200                        'from_fieldname'  => 'topic_first_poster_name',
     201                        'to_type'         => 'topic',
     202                        'to_fieldname'    => '_bbp_phpbb_topic_first_poster_name'
     203                );
     204
    196205                // Topic Author ip (Stored in postmeta)
    197206                $this->field_map[] = array(
    198207                        'from_tablename'  => 'posts',
     
    359368                        'callback_method' => 'callback_userid'
    360369                );
    361370
     371                // Reply poster username (Used for storing original post author, Stored in postmeta)
     372                // Note: See #2347 http://bbpress.trac.wordpress.org/ticket/2347#comment:7
     373                $this->field_map[] = array(
     374                        'from_tablename'  => 'posts',
     375                        'from_fieldname'  => 'post_username',
     376                        'to_type'         => 'reply',
     377                        'to_fieldname'    => '_bbp_phpbb_post_username'
     378                );
    362379                // Reply title.
    363380                $this->field_map[] = array(
    364381                        'from_tablename'  => 'posts',
     
    435452                        'to_fieldname'   => '_bbp_user_id'
    436453                );
    437454
     455                // Store old User id (Stored in usermeta)
     456                $this->field_map[] = array(
     457                        'from_tablename' => 'users',
     458                        'from_fieldname' => 'user_type',
     459                        'to_type'        => 'user',
     460                        'to_fieldname'   => '_bbp_phpbb_user_type'
     461                );
     462
    438463                // Store old User password (Stored in usermeta serialized with salt)
    439464                $this->field_map[] = array(
    440465                        'from_tablename'  => 'users',
  • includes/admin/tools.php

     
    174174                65 => array( 'bbp-user-favorites',           __( 'Remove trashed topics from user favorites',         'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
    175175                70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ),
    176176                75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ),
    177                 80 => array( 'bbp-user-role-map',            __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               )
     177                80 => array( 'bbp-user-role-map',            __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               ),
     178                85 => array( 'bbp-import-phpbb',             __( 'phpBB post import repair tasks',                    'bbpress' ), 'bbp_admin_repair_import_phpbb'             )
    178179        );
    179180        ksort( $repair_list );
    180181
     
    11101111        return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
    11111112}
    11121113
     1114/**
     1115 * phpBB post import repair tasks
     1116 *
     1117 * @since bbPress (rXXXX)
     1118 *
     1119 * @global WPDB $wpdb
     1120 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     1121 * @uses update_post_meta() To update topic meta
     1122 * @uses update_post_meta() To update reply meta
     1123 * @uses get_users() To get the imported phpBB bots
     1124 * @uses wp_delete_user() To delete the imported phpBB users (bots, crawlers & anonymous)
     1125 * @return array An array of the status code and the message
     1126 */
     1127function bbp_admin_repair_import_phpbb() {
     1128        global $wpdb;
     1129
     1130        /** phpBB Anonymous Topics ************************************************/
     1131
     1132        $statement = __( 'Running phpBB post import tasks… %s', 'bbpress' );
     1133        $r_count   = 0;
     1134        $t_count   = 0;
     1135        $u_count   = 0;
     1136
     1137        // Get the phpBB anonymous topic IDs
     1138        $topic_ids = $wpdb->query( "SELECT `posts` .`ID` AS `post_id`, '_bbp_anonymous_name', `postmeta` . `meta_value` AS `meta_value`
     1139                                                                FROM `{$wpdb->posts}` AS `posts`
     1140                                                                        LEFT JOIN `{$wpdb->postmeta}` AS `postmeta`
     1141                                                                                ON `posts`.`ID` = `postmeta`.`post_id`
     1142                                                                                AND `postmeta`.`meta_key` = '_bbp_phpbb_topic_first_poster_name'
     1143                                                                        LEFT JOIN `{$wpdb->usermeta}` AS `usermeta`
     1144                                                                                ON `usermeta` . `user_id` = `posts`.`post_author`
     1145                                                                                AND `usermeta` . `meta_key` = '_bbp_phpbb_user_type'
     1146                                                                WHERE `posts`.`post_type` = 'topic'
     1147                                                                        AND `usermeta` . `meta_value` = '2';" );
     1148
     1149        // Bail if topic IDs returned an error
     1150        if ( is_wp_error( $topic_ids ) ) {
     1151                return array( 1, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) );
     1152        }
     1153
     1154        // Stash the last results
     1155        $results = $wpdb->last_result;
     1156
     1157        // Update each anonymous topic
     1158        foreach ( $results as $anon_topic ) {
     1159
     1160                // Update topic meta _bbp_anonymous_name with anonymous user name
     1161                update_post_meta( $anon_topic->post_id, '_bbp_anonymous_name', $anon_topic->meta_value );
     1162
     1163                // Bump the count for output later
     1164                ++$t_count;
     1165        }
     1166
     1167        unset( $topic_ids, $results, $anon_topic );
     1168
     1169        /** phpBB Anonymous Replies ***********************************************/
     1170
     1171        // Get the phpBB anonymous reply IDs
     1172        $reply_ids = $wpdb->query( "SELECT `posts` .`ID` AS `post_id`, '_bbp_anonymous_name', `postmeta` . `meta_value` AS `meta_value`
     1173                                                                FROM `{$wpdb->posts}` AS `posts`
     1174                                                                        LEFT JOIN `{$wpdb->postmeta}` AS `postmeta`
     1175                                                                                ON `posts`.`ID` = `postmeta`.`post_id`
     1176                                                                                AND `postmeta`.`meta_key` = '_bbp_phpbb_post_username '
     1177                                                                        LEFT JOIN `{$wpdb->usermeta}` AS `usermeta`
     1178                                                                                ON `usermeta` . `user_id` = `posts`.`post_author`
     1179                                                                                AND `usermeta` . `meta_key` = '_bbp_phpbb_user_type'
     1180                                                                WHERE `posts`.`post_type` = 'reply'
     1181                                                                AND `usermeta` . `meta_value` = '2';" );
     1182
     1183        // Bail if reply IDs returned an error
     1184        if ( is_wp_error( $reply_ids ) ) {
     1185                return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) );
     1186        }
     1187
     1188        // Stash the last results
     1189        $results = $wpdb->last_result;
     1190
     1191        // Update each anonymous reply
     1192        foreach ( $results as $anon_reply ) {
     1193
     1194                // Update reply meta _bbp_anonymous_name with anonymous user name
     1195                update_post_meta( $anon_reply->post_id, '_bbp_anonymous_name', $anon_reply->meta_value );
     1196
     1197                // Bump the count for output later
     1198                ++$r_count;
     1199        }
     1200
     1201        unset( $reply_ids, $results, $anon_reply );
     1202
     1203        /** phpBB Anonymous Users *************************************************/
     1204
     1205        // Get the phpBB anonymous, bots and crawler user IDs
     1206        $bbp_anonymous_id = 0;
     1207        $phpbb_bots = get_users(array( 'meta_key' => '_bbp_phpbb_user_type','meta_value' => '2', ) );
     1208
     1209        // Bail if user IDs returned an error
     1210        if ( is_wp_error( $phpbb_bots ) ) {
     1211                return array( 3, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) );
     1212        }
     1213
     1214        // Delete each anonymous user
     1215        foreach ( $phpbb_bots as $phpbb_bot ) {
     1216
     1217                // Delete each imported bot user replacing posts with bbPress anonymous user ID
     1218                wp_delete_user( $phpbb_bot->ID, $bbp_anonymous_id );
     1219
     1220                // Bump the count for output later
     1221                ++$u_count;
     1222        }
     1223
     1224        unset( $phpbb_bots, $results, $phpbb_bot );
     1225
     1226        // Complete results
     1227        $result = sprintf( __( 'Complete! %s anonymous topics updated, %s anonymous replies updated and %s user bots deleted.', 'bbpress' ), bbp_number_format( $t_count ), bbp_number_format( $r_count ), bbp_number_format( $u_count ) );
     1228        return array( 0, sprintf( $statement, $result ) );
     1229}
     1230
    11131231/** Reset ********************************************************************/
    11141232
    11151233/**