Index: src/includes/admin/admin.php
===================================================================
--- src/includes/admin/admin.php	(revision 6192)
+++ src/includes/admin/admin.php	(working copy)
@@ -117,15 +117,16 @@
 	 * @access private
 	 */
 	private function includes() {
-		require( $this->admin_dir . 'tools.php'     );
-		require( $this->admin_dir . 'converter.php' );
-		require( $this->admin_dir . 'settings.php'  );
-		require( $this->admin_dir . 'functions.php' );
-		require( $this->admin_dir . 'metaboxes.php' );
-		require( $this->admin_dir . 'forums.php'    );
-		require( $this->admin_dir . 'topics.php'    );
-		require( $this->admin_dir . 'replies.php'   );
-		require( $this->admin_dir . 'users.php'     );
+		require( $this->admin_dir . 'tools.php'        );
+		require( $this->admin_dir . 'converter.php'    );
+		require( $this->admin_dir . 'repair-tools.php' );
+		require( $this->admin_dir . 'settings.php'     );
+		require( $this->admin_dir . 'functions.php'    );
+		require( $this->admin_dir . 'metaboxes.php'    );
+		require( $this->admin_dir . 'forums.php'       );
+		require( $this->admin_dir . 'topics.php'       );
+		require( $this->admin_dir . 'replies.php'      );
+		require( $this->admin_dir . 'users.php'        );
 	}
 
 	/**
@@ -1127,4 +1128,5 @@
 	bbpress()->admin = new BBP_Admin();
 
 	bbpress()->admin->converter = new BBP_Converter();
+	bbpress()->admin->converter = new BBP_Repair_Tools();
 }
Index: src/includes/admin/converters/FavSub.php
===================================================================
--- src/includes/admin/converters/FavSub.php	(nonexistent)
+++ src/includes/admin/converters/FavSub.php	(working copy)
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * bbPress 2.5 to 2.6 favorite and subscription converter.
+ *
+ * @package bbPress
+ * @subpackage Converters
+ */
+
+/**
+ * Implementation of FavSub v3 Converter.
+ *
+ * @since 2.6.0 bbPress (rXXXX)
+ *
+ * @link Codex Docs https://codex.bbpress.org/
+ */
+class FavSub extends BBP_Converter_Base {
+
+	/**
+	 * Main Constructor
+	 *
+	 * @uses FavSub::setup_globals()
+	 */
+	function __construct() {
+		parent::__construct();
+		$this->setup_globals();
+	}
+
+	/**
+	 * Sets up the field mappings
+	 */
+	public function setup_globals() {
+
+		/** Forum Subscriptions Section ***************************************/
+
+		// Subscribed forum ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_forum_subscriptions',
+			'to_type'         => 'forum_subscriptions_test01',
+			'to_fieldname'    => '_bbp_forum_subscriptions_test01'
+		);
+
+		// Subscribed user ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_forum_subscriptions',
+			'to_type'         => 'forum_subscriptions_test01',
+			'to_fieldname'    => 'user_id',
+			'callback_method' => 'callback_userid'
+		);
+
+		/** Topic Subscriptions Section ***************************************/
+
+		// Subscribed topic ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_subscriptions',
+			'to_type'         => 'topic_subscriptions_test01',
+			'to_fieldname'    => '_bbp_subscriptions'
+		);
+
+		// Subscribed user ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_subscriptions',
+			'to_type'         => 'topic_subscriptions_test01',
+			'to_fieldname'    => 'user_id',
+			'callback_method' => 'callback_userid'
+		);
+
+		/** Favorites Section *************************************************/
+
+		// Favorited topic ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_favorites',
+			'to_type'         => 'favorites_test01',
+			'to_fieldname'    => '_bbp_favorites'
+		);
+
+		// Favorited user ID (Stored in usermeta)
+		$this->field_map[] = array(
+			'from_tablename'  => 'usermeta',
+			'from_fieldname'  => 'wp__bbp_favorites',
+			'to_type'         => 'favorites_test01',
+			'to_fieldname'    => 'user_id',
+			'callback_method' => 'callback_userid'
+		);
+	}
+
+	/**
+	 * This method allows us to indicates what is or is not converted for each
+	 * converter.
+	 */
+	public function info() {
+		return '';
+	}
+
+}

Property changes on: src/includes/admin/converters/FavSub.php
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: src/includes/admin/repair-tools.php
===================================================================
--- src/includes/admin/repair-tools.php	(nonexistent)
+++ src/includes/admin/repair-tools.php	(working copy)
@@ -0,0 +1,1050 @@
+<?php
+
+/**
+ * bbPress Repair Tools
+ *
+ * @package bbPress
+ * @subpackage Administration
+ */
+
+// Exit if accessed directly.
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Main BBP_Repair_Tools Class
+ */
+class BBP_Repair_Tools {
+
+	/**
+	 * The main bbPress repair tools loader
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function __construct() {
+
+		// 'I wonder where I'll float next.'
+		if ( empty( $_SERVER['REQUEST_METHOD'] ) ) {
+			return;
+		}
+
+		// Bail if request is not correct.
+		switch ( strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
+
+			// Repair tools are running.
+			case 'POST' :
+				if ( ( empty( $_POST['action'] ) || ( 'bbp_repair_tool_process' != $_POST['action'] ) ) ) {
+					return;
+				}
+
+				break;
+
+			// Some other admin page.
+			case 'GET'  :
+				if ( ( empty( $_GET['page'] ) || ( 'bbp-repair' != $_GET['page'] ) ) ) {
+					return;
+				}
+
+				break;
+		}
+
+		// Proceed with the actions.
+		$this->setup_actions();
+	}
+
+	/**
+	 * Setup the default actions
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	private function setup_actions() {
+
+		// Attach to the admin head with our ajax requests cycle and css.
+		add_action( 'bbp_admin_head',              array( $this, 'admin_head'              ) );
+
+		// Attach the repair tool admin settings action to the WordPress admin init action.
+		add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) );
+
+		// Attach to the admin ajax request to process cycles.
+		add_action( 'wp_ajax_bbp_repair_tool_process', array( $this, 'process_callback'        ) );
+	}
+
+	/**
+	 * Register the settings
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function register_admin_settings() {
+
+		// Add the main section.
+		add_settings_section( 'bbpress_repair_tool_main',     __( 'Repair Tools Settings', 'bbpress' ),  'bbp_repair_tool_setting_callback_main_section', 'bbpress_repair_tool' );
+
+		// Rows Limit.
+		add_settings_field( '_bbp_repair_tool_rows',          __( 'Rows Limit',        'bbpress' ),  'bbp_repair_tool_setting_callback_rows', 'bbpress_repair_tool', 'bbpress_repair_tool_main' );
+		register_setting  ( 'bbpress_repair_tool_main',        '_bbp_repair_tool_rows',               'intval' );
+
+		// Delay Time.
+		add_settings_field( '_bbp_repair_tool_delay_time',    __( 'Delay Time',        'bbpress' ), 'bbp_repair_tool_setting_callback_delay_time', 'bbpress_repair_tool', 'bbpress_repair_tool_main' );
+		register_setting  ( 'bbpress_repair_tool_main',        '_bbp_repair_tool_delay_time',        'intval' );
+	}
+
+	/**
+	 * Admin scripts
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function admin_head() { ?>
+
+		<style type="text/css" media="screen">
+			/*<![CDATA[*/
+
+			div.bbp-repair-tool-updated,
+			div.bbp-repair-tool-warning {
+				border-radius: 3px 3px 3px 3px;
+				border-style: solid;
+				border-width: 1px;
+				padding: 5px 5px 5px 5px;
+			}
+
+			div.bbp-repair-tool-updated {
+				height: 300px;
+				overflow: auto;
+				display: none;
+				background-color: #FFFFE0;
+				border-color: #E6DB55;
+				font-family: monospace;
+				font-weight: bold;
+			}
+
+			div.bbp-repair-tool-updated p {
+				margin: 0.5em 0;
+				padding: 2px;
+				float: left;
+				clear: left;
+			}
+
+			div.bbp-repair-tool-updated p.loading {
+				padding: 2px 20px 2px 2px;
+				background-image: url('<?php echo admin_url(); ?>images/wpspin_light.gif');
+				background-repeat: no-repeat;
+				background-position: center right;
+			}
+
+			#bbp-repair-tool-stop {
+				display:none;
+			}
+
+			#bbp-repair-tool-progress {
+				display:none;
+			}
+
+			/*]]>*/
+		</style>
+
+		<script language="javascript">
+
+			var bbp_repair_tool_is_running = false;
+			var bbp_repair_tool_run_timer;
+			var bbp_repair_tool_delay_time = 0;
+
+			function bbp_repair_tool_grab_data() {
+				var values = {};
+				jQuery.each(jQuery('#bbp-repair-tool-settings').serializeArray(), function(i, field) {
+					values[field.name] = field.value;
+				});
+
+				if( values['_bbp_repair_tool_restart'] ) {
+					jQuery('#_bbp_repair_tool_restart').removeAttr("checked");
+				}
+
+				if( values['_bbp_repair_tool_delay_time'] ) {
+					bbp_repair_tool_delay_time = values['_bbp_repair_tool_delay_time'] * 1000;
+				}
+
+				values['action'] = 'bbp_repair_tool_process';
+				values['_ajax_nonce'] = '<?php echo  wp_create_nonce( 'bbp_repair_tool_process' ); ?>';
+
+				return values;
+			}
+
+			function bbp_repair_tool_start() {
+				if( false === bbp_repair_tool_is_running ) {
+					bbp_repair_tool_is_running = true;
+					jQuery('#bbp-repair-tool-start').hide();
+					jQuery('#bbp-repair-tool-stop').show();
+					jQuery('#bbp-repair-tool-progress').show();
+					bbp_repair_tool_log( '<p class="loading"><?php esc_html_e( 'Starting Repair', 'bbpress' ); ?></p>' );
+					bbp_repair_tool_run();
+				}
+			}
+
+			function bbp_repair_tool_run() {
+				jQuery.post(ajaxurl, bbp_repair_tool_grab_data(), function(response) {
+					var response_length = response.length - 1;
+					response = response.substring(0,response_length);
+					bbp_repair_tool_success(response);
+				});
+			}
+
+			function bbp_repair_tool_stop() {
+				jQuery('#bbp-repair-tool-start').show();
+				jQuery('#bbp-repair-tool-stop').hide();
+				jQuery('#bbp-repair-tool-progress').hide();
+				jQuery('#bbp-repair-tool-message p').removeClass( 'loading' );
+				bbp_repair_tool_is_running = false;
+				clearTimeout( bbp_repair_tool_run_timer );
+			}
+
+			function bbp_repair_tool_success(response) {
+				bbp_repair_tool_log(response);
+
+				if ( response === '<p class="loading"><?php esc_html_e( 'Conversion Complete', 'bbpress' ); ?></p>' || response.indexOf('error') > -1 ) {
+					bbp_repair_tool_log('<p>Repair any missing information: <a href="<?php echo admin_url(); ?>tools.php?page=bbp-repair">Continue</a></p>');
+					bbp_repair_tool_stop();
+				} else if( bbp_repair_tool_is_running ) { // keep going
+					jQuery('#bbp-repair-tool-progress').show();
+					clearTimeout( bbp_repair_tool_run_timer );
+					bbp_repair_tool_run_timer = setTimeout( 'bbp_repair_tool_run()', bbp_repair_tool_delay_time );
+				} else {
+					bbp_repair_tool_stop();
+				}
+			}
+
+			function bbp_repair_tool_log(text) {
+				if ( jQuery('#bbp-repair-tool-message').css('display') === 'none' ) {
+					jQuery('#bbp-repair-tool-message').show();
+				}
+				if ( text ) {
+					jQuery('#bbp-repair-tool-message p').removeClass( 'loading' );
+					jQuery('#bbp-repair-tool-message').prepend( text );
+				}
+			}
+
+		</script>
+
+		<?php
+	}
+
+	/**
+	 * Wrap the repair tool output in paragraph tags, so styling can be applied
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 *
+	 * @param string $output
+	 */
+	private static function repair_tool_output( $output = '' ) {
+
+		// Get the last query.
+		$before = '<p class="loading">';
+		$after  = '</p>';
+		$query  = get_option( '_bbp_repair_tool_query' );
+
+		if ( ! empty( $query ) ) {
+			$before = '<p class="loading" title="' . esc_attr( $query ) . '">';
+		}
+
+		echo $before . $output . $after;
+	}
+
+	/**
+	 * Callback processor
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function process_callback() {
+
+		// Bail if user cannot view import page.
+		if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
+			wp_die( '0' );
+		}
+
+		// Verify intent.
+		check_ajax_referer( 'bbp_repair_tool_process' );
+
+		if ( ! ini_get( 'safe_mode' ) ) {
+			set_time_limit( 0 );
+			ini_set( 'memory_limit',   '256M' );
+			ini_set( 'implicit_flush', '1'    );
+			ignore_user_abort( true );
+		}
+
+		// Save step and count so that it can be restarted.
+		if ( ! get_option( '_bbp_repair_tool_step' ) || ( ! empty( $_POST['_bbp_repair_tool_restart'] ) ) ) {
+			update_option( '_bbp_repair_tool_step',  1 );
+			update_option( '_bbp_repair_tool_start', 0 );
+		}
+
+		$step  = (int) get_option( '_bbp_repair_tool_step',  1 );
+		$min   = (int) get_option( '_bbp_repair_tool_start', 0 );
+		$count = (int) ! empty( $_POST['_bbp_repair_tool_rows'] ) ? $_POST['_bbp_repair_tool_rows'] : 100;
+		$max   = ( $min + $count ) - 1;
+		$start = $min;
+
+		// Bail if platform did not get saved.
+		$platform = ! empty( $_POST['_bbp_repair_tool_platform' ] ) ? $_POST['_bbp_repair_tool_platform' ] : get_option( '_bbp_repair_tool_platform' );
+		if ( empty( $platform ) ) {
+			return;
+		}
+
+		// Include the appropriate repair tool.
+		$repair_tool = bbp_new_repair( $platform );
+
+		switch ( $step ) {
+
+			// STEP 1. Clean all tables.
+			case 1 :
+				if ( ! empty( $_POST['_bbp_repair_tool_clean'] ) ) {
+					if ( $repair_tool->clean( $start ) ) {
+						update_option( '_bbp_repair_tool_step',  $step + 1 );
+						update_option( '_bbp_repair_tool_start', 0         );
+						$this->sync_table( true );
+						if ( empty( $start ) ) {
+							$this->repair_tool_output( __( 'No data to clean', 'bbpress' ) );
+						}
+					} else {
+						update_option( '_bbp_repair_tool_start', $max + 1 );
+						$this->repair_tool_output( sprintf( __( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
+					}
+				} else {
+					update_option( '_bbp_repair_tool_step',  $step + 1 );
+					update_option( '_bbp_repair_tool_start', 0         );
+				}
+
+				break;
+
+			// STEP 18. Convert forum subscriptions.
+			case 18 :
+				if ( $repair_tool->convert_forum_subscriptions_test01( $start ) ) {
+					update_option( '_bbp_repair_tool_step',  $step + 1 );
+					update_option( '_bbp_repair_tool_start', 0         );
+					if ( empty( $start ) ) {
+						$this->repair_tool_output( __( 'No forum subscriptions to convert', 'bbpress' ) );
+					}
+				} else {
+					update_option( '_bbp_repair_tool_start', $max + 1 );
+					$this->repair_tool_output( sprintf( __( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
+				}
+
+				break;
+
+
+			// STEP 19. Convert topic subscriptions.
+			case 19 :
+				if ( $repair_tool->convert_topic_subscriptions_tes01( $start ) ) {
+					update_option( '_bbp_repair_tool_step',  $step + 1 );
+					update_option( '_bbp_repair_tool_start', 0         );
+					if ( empty( $start ) ) {
+						$this->repair_tool_output( __( 'No topic subscriptions to convert', 'bbpress' ) );
+					}
+				} else {
+					update_option( '_bbp_repair_tool_start', $max + 1 );
+					$this->repair_tool_output( sprintf( __( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
+				}
+
+				break;
+
+			// STEP 20. Convert topic favorites.
+			case 20 :
+				if ( $repair_tool->convert_favorites_test01( $start ) ) {
+					update_option( '_bbp_repair_tool_step',  $step + 1 );
+					update_option( '_bbp_repair_tool_start', 0         );
+					if ( empty( $start ) ) {
+						$this->repair_tool_output( __( 'No favorites to convert', 'bbpress' ) );
+					}
+				} else {
+					update_option( '_bbp_repair_tool_start', $max + 1 );
+					$this->repair_tool_output( sprintf( __( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $min, $max ) );
+				}
+
+				break;
+
+			default :
+				delete_option( '_bbp_repair_tool_step'  );
+				delete_option( '_bbp_repair_tool_start' );
+				delete_option( '_bbp_repair_tool_query' );
+
+				$this->repair_tool_output( __( 'Repair tools complete', 'bbpress' ) );
+
+				break;
+		}
+	}
+
+	/**
+	 * Create Tables for fast syncing
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function sync_table( $drop = false ) {
+
+		$bbp_db     = bbp_db();
+		$table_name = $bbp_db->prefix . 'bbp_repair_tool_translator';
+		if ( ! empty( $drop ) && $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) {
+			$bbp_db->query( "DROP TABLE {$table_name}" );
+		}
+
+		require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
+
+		if ( ! empty( $bbp_db->charset ) ) {
+			$charset_collate = "DEFAULT CHARACTER SET $bbp_db->charset";
+		}
+
+		if ( ! empty( $bbp_db->collate ) ) {
+			$charset_collate .= " COLLATE $bbp_db->collate";
+		}
+
+		$sql = array();
+		$max_index_length = 191;
+
+		/** Translator ********************************************************/
+
+		$sql[] = "CREATE TABLE {$table_name} (
+					meta_id mediumint(8) unsigned not null auto_increment,
+					value_type varchar(25) null,
+					value_id bigint(20) unsigned not null default '0',
+					meta_key varchar(255) null,
+					meta_value varchar(255) null,
+				PRIMARY KEY (meta_id),
+					KEY value_id (value_id),
+					KEY meta_join (meta_key({$max_index_length}), meta_value({$max_index_length}))
+				) {$charset_collate};";
+
+		dbDelta( $sql );
+	}
+}
+
+/**
+ * Base class to be extended by specific individual importers
+ *
+ * @since 2.1.0 bbPress (r3813)
+ */
+abstract class BBP_Repair_Tools_Base {
+
+	/**
+	 * @var array() This is the field mapping array to process.
+	 */
+	protected $field_map = array();
+
+	/**
+	 * @var object This is the connection to the WordPress database.
+	 */
+	protected $wpdb;
+
+	/**
+	 * @var object This is the connection to the other platforms database.
+	 */
+	protected $opdb;
+
+	/**
+	 * @var int This is the max rows to process at a time.
+	 */
+	public $max_rows;
+
+	/**
+	 * @var array() Map of topic to forum.  It is for optimization.
+	 */
+	private $map_topicid_to_forumid = array();
+
+	/**
+	 * @var array() Map of from old forum ids to new forum ids.  It is for optimization.
+	 */
+	private $map_forumid = array();
+
+	/**
+	 * @var array() Map of from old topic ids to new topic ids.  It is for optimization.
+	 */
+	private $map_topicid = array();
+
+	/**
+	 * @var array() Map of from old reply_to ids to new reply_to ids.  It is for optimization.
+	 */
+	private $map_reply_to = array();
+
+	/**
+	 * @var array() Map of from old user ids to new user ids.  It is for optimization.
+	 */
+	private $map_userid = array();
+
+	/**
+	 * @var str This is the charset for your wp database.
+	 */
+	public $charset;
+
+	/**
+	 * @var boolean Sync table available.
+	 */
+	public $sync_table = false;
+
+	/**
+	 * @var str Sync table name.
+	 */
+	public $sync_table_name;
+
+	/** Methods ***************************************************************/
+
+	/**
+	 * This is the constructor and it connects to the platform databases.
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	public function __construct() {
+		$this->setup_globals();
+	}
+
+	/**
+	 * [setup_globals description]
+	 *
+	 * @since 2.6.0 bbPress (rXXXX)
+	 */
+	private function setup_globals() {
+
+		/** Get database connections ******************************************/
+
+		$this->wpdb         = bbp_db();
+		$this->max_rows     = (int) $_POST['_bbp_repair_tool_rows'];
+		$this->opdb         = new wpdb( $_POST['_bbp_repair_tool_db_user'], $_POST['_bbp_repair_tool_db_pass'], $_POST['_bbp_repair_tool_db_name'], $_POST['_bbp_repair_tool_db_server'] );
+		$this->opdb->prefix = $_POST['_bbp_repair_tool_db_prefix'];
+
+		/**
+		 * Error Reporting
+		 */
+		$this->wpdb->show_errors();
+		$this->opdb->show_errors();
+
+		/**
+		 * Syncing
+		 */
+		$this->sync_table_name = $this->wpdb->prefix . 'bbp_repair_tool_translator';
+		if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) {
+			$this->sync_table = true;
+		} else {
+			$this->sync_table = false;
+		}
+
+		/**
+		 * Character set
+		 */
+		if ( empty( $this->wpdb->charset ) ) {
+			$this->charset = 'UTF8';
+		} else {
+			$this->charset = $this->wpdb->charset;
+		}
+
+		/**
+		 * Default mapping.
+		 */
+
+		/** User Section ******************************************************/
+
+		$this->field_map[] = array(
+			'to_type'      => 'user',
+			'to_fieldname' => 'role',
+			'default'      => get_option( 'default_role' )
+		);
+	}
+
+	/**
+	 * Convert Users
+	 */
+	public function convert_users( $start = 1 ) {
+		return $this->convert_table( 'user', $start );
+	}
+
+	/**
+	 * Convert Forum Subscriptions
+	 */
+	public function convert_forum_subscriptions_test01( $start = 1 ) {
+		return $this->convert_table( 'forum_subscriptions_test01', $start );
+	}
+
+	/**
+	 * Convert Topic Subscriptions
+	 */
+	public function convert_topic_subscriptions_test01( $start = 1 ) {
+		return $this->convert_table( 'topic_subscriptions_test01', $start );
+	}
+
+	/**
+	 * Convert Favorites
+	 */
+	public function convert_favorites_test01( $start = 1 ) {
+		return $this->convert_table( 'favorites', $start );
+	}
+
+	/**
+	 * Convert Table
+	 *
+	 * @param string to type
+	 * @param int Start row
+	 */
+	public function convert_table( $to_type, $start ) {
+
+		// Are we usig a sync table, or postmeta?
+		if ( $this->wpdb->get_var( "SHOW TABLES LIKE '" . $this->sync_table_name . "'" ) === $this->sync_table_name ) {
+			$this->sync_table = true;
+		} else {
+			$this->sync_table = false;
+		}
+
+		// Set some defaults.
+		$has_insert     = false;
+		$from_tablename = '';
+		$field_list     = $from_tables = $tablefield_array = array();
+
+		// Toggle Table Name based on $to_type (destination).
+		switch ( $to_type ) {
+			case 'user' :
+				$tablename = $this->wpdb->users;
+				break;
+
+			case 'forum_subscriptions_test01' :
+				$tablename = $this->wpdb->postmeta;
+				break;
+
+			case 'topic_subscriptions_test01' :
+				$tablename = $this->wpdb->postmeta;
+				break;
+
+			case 'favorites_test01' :
+				$tablename = $this->wpdb->postmeta;
+				break;
+
+			default :
+				$tablename = $this->wpdb->posts;
+		}
+
+		// Get the fields from the destination table.
+		if ( ! empty( $tablename ) ) {
+			$tablefield_array = $this->get_fields( $tablename );
+		}
+
+		/** Step 1 ************************************************************/
+
+		// Loop through the field maps, and look for to_type matches.
+		foreach ( $this->field_map as $item ) {
+
+			// Yay a match, and we have a from table, too.
+			if ( ( $item['to_type'] === $to_type ) && ! empty( $item['from_tablename'] ) ) {
+
+				// $from_tablename was set from a previous loop iteration.
+				if ( ! empty( $from_tablename ) ) {
+
+					// Doing some joining.
+					if ( ! in_array( $item['from_tablename'], $from_tables ) && in_array( $item['join_tablename'], $from_tables ) ) {
+						$from_tablename .= ' ' . $item['join_type'] . ' JOIN ' . $this->opdb->prefix . $item['from_tablename'] . ' AS ' . $item['from_tablename'] . ' ' . $item['join_expression'];
+					}
+
+				// $from_tablename needs to be set.
+				} else {
+					$from_tablename = $item['from_tablename'] . ' AS ' . $item['from_tablename'];
+				}
+
+				// Specific FROM expression data used.
+				if ( ! empty( $item['from_expression'] ) ) {
+
+					// No 'WHERE' in expression.
+					if ( stripos( $from_tablename, "WHERE" ) === false ) {
+						$from_tablename .= ' ' . $item['from_expression'];
+
+					// 'WHERE' in expression, so replace with 'AND'
+					} else {
+						$from_tablename .= ' ' . str_replace( "WHERE", "AND", $item['from_expression'] );
+					}
+				}
+
+				// Add tablename and fieldname to arrays, formatted for querying.
+				$from_tables[] = $item['from_tablename'];
+				$field_list[]  = 'convert(' . $item['from_tablename'] . '.' . $item['from_fieldname'] . ' USING "' . $this->charset . '") AS ' . $item['from_fieldname'];
+			}
+		}
+
+		/** Step 2 ************************************************************/
+
+		// We have a $from_tablename, so we want to get some data to convert.
+		if ( ! empty( $from_tablename ) ) {
+
+			// Get some data from the old forums.
+			$field_list  = array_unique( $field_list );
+			$forum_query = 'SELECT ' . implode( ',', $field_list ) . ' FROM ' . $this->opdb->prefix . $from_tablename . ' LIMIT ' . $start . ', ' . $this->max_rows;
+			$forum_array = $this->opdb->get_results( $forum_query, ARRAY_A );
+
+			// Set this query as the last one ran.
+			update_option( '_bbp_repair_tool_query', $forum_query );
+
+			// Query returned some results.
+			if ( ! empty( $forum_array ) ) {
+
+				// Loop through results.
+				foreach ( (array) $forum_array as $forum ) {
+
+					// Reset some defaults.
+					$insert_post = $insert_postmeta = $insert_data = array();
+
+					// Loop through field map, again...
+					foreach ( $this->field_map as $row ) {
+
+						// Types match and to_fieldname is present. This means
+						// we have some work to do here.
+						if ( ( $row['to_type'] === $to_type ) && isset( $row['to_fieldname'] ) ) {
+
+							// This row has a destination that matches one of the
+							// columns in this table.
+							if ( in_array( $row['to_fieldname'], $tablefield_array ) ) {
+
+								// Allows us to set default fields.
+								if ( isset( $row['default'] ) ) {
+									$insert_post[ $row['to_fieldname'] ] = $row['default'];
+
+								// Translates a field from the old forum.
+								} elseif ( isset( $row['callback_method'] ) ) {
+									if ( ( 'callback_userid' === $row['callback_method'] ) && empty( $_POST['_bbp_repair_tool_convert_users'] ) ) {
+										$insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
+									} else {
+										$insert_post[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) );
+									}
+
+								// Maps the field from the old forum.
+								} else {
+									$insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
+								}
+
+							// Destination field is not empty, so we might need
+							// to do some extra work or set a default.
+							} elseif ( ! empty( $row['to_fieldname'] ) ) {
+
+								// Allows us to set default fields.
+								if ( isset( $row['default'] ) ) {
+									$insert_postmeta[ $row['to_fieldname'] ] = $row['default'];
+
+								// Translates a field from the old forum.
+								} elseif ( isset( $row['callback_method'] ) ) {
+									if ( ( $row['callback_method'] === 'callback_userid' ) && ( 0 == $_POST['_bbp_repair_tool_convert_users'] ) ) {
+										$insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
+									} else {
+										$insert_postmeta[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) );
+									}
+
+								// Maps the field from the old forum.
+								} else {
+									$insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
+								}
+							}
+						}
+					}
+
+					/** Step 3 ************************************************/
+
+					// Something to insert into the destination field.
+					if ( count( $insert_post ) > 0 || ( $to_type == 'tags' && count( $insert_postmeta ) > 0 ) ) {
+
+						switch ( $to_type ) {
+
+							/** New user **************************************/
+
+							case 'user':
+								if ( username_exists( $insert_post['user_login'] ) ) {
+									$insert_post['user_login'] = 'imported_' . $insert_post['user_login'];
+								}
+
+								if ( email_exists( $insert_post['user_email'] ) ) {
+									$insert_post['user_email'] = 'imported_' . $insert_post['user_email'];
+								}
+
+								$post_id = wp_insert_user( $insert_post );
+
+								if ( is_numeric( $post_id ) ) {
+
+									foreach ( $insert_postmeta as $key => $value ) {
+
+										add_user_meta( $post_id, $key, $value, true );
+
+										if ( '_id' === substr( $key, -3 ) && ( true === $this->sync_table ) ) {
+											$this->wpdb->insert( $this->sync_table_name, array( 'value_type' => 'user', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value ) );
+										}
+									}
+								}
+								break;
+
+							/** Forum Subscriptions ***************************/
+
+							case 'forum_subscriptions_test01':
+								$user_id = $insert_post['user_id'];
+								if ( is_numeric( $user_id ) ) {
+									foreach ($insert_postmeta as $key => $value) {
+
+										// Only extract values from the key _bbp_forum_subscriptions.
+										if ( '_bbp_forum_subscriptions' == $key ) {
+
+											// Get the new forum ID
+											$forum_id = $this->callback_forumid( $value );
+
+											// Add the topic ID to the users subscribed forums.
+											bbp_add_user_forum_subscription( $user_id, $forum_id );
+										}
+									}
+								}
+								break;
+
+							/** Subscriptions *********************************/
+
+							case 'topic_subscriptions_test01':
+								$user_id = $insert_post['user_id'];
+								if ( is_numeric( $user_id ) ) {
+									foreach ($insert_postmeta as $key => $value) {
+
+										// Only extract values from the key _bbp_subscriptions.
+										if ( '_bbp_subscriptions' == $key ) {
+
+											// Get the new topic ID
+											$topic_id = $this->callback_topicid( $value );
+
+											// Add the topic ID to the users subscribed topics.
+											bbp_add_user_topic_subscription( $user_id, $topic_id );
+										}
+									}
+								}
+								break;
+
+							/** Favorites *************************************/
+
+							case 'favorites_test01':
+								$user_id = $insert_post['user_id'];
+								if ( is_numeric( $user_id ) ) {
+
+									// Loop through the array
+									foreach ($insert_postmeta as $key => $value) {
+
+										// Only extract values from the key _bbp_favorites.
+										if ( '_bbp_favorites' == $key ) {
+
+											// Our array may contain comma delimited favorites so lets explode these.
+											$insert_postmeta = explode(",", $insert_postmeta['_bbp_favorites']);
+
+											// Loop through our updated exploded array.
+											foreach ($insert_postmeta as $key => $value) {
+
+												// Get the new topic ID.
+												$topic_id = $this->callback_topicid( $value );
+
+												// Add the topic ID to the users favorites.
+												bbp_add_user_favorite( $user_id, $topic_id );
+											}
+										}
+									}
+								}
+								break;
+						}
+						$has_insert = true;
+					}
+				}
+			}
+		}
+
+		return ! $has_insert;
+	}
+
+	/**
+	 * This method converts old reply_to post id to new bbPress reply_to post id.
+	 *
+	 * @since 2.4.0 bbPress (r5093)
+	 */
+	public function convert_reply_to_parents( $start ) {
+
+		$has_update = false;
+
+		if ( ! empty( $this->sync_table ) ) {
+			$query = 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;
+		} else {
+			$query = 'SELECT post_id AS value_id, meta_value FROM ' . $this->wpdb->postmeta . ' WHERE meta_key = "_bbp_old_reply_to_id" AND meta_value > 0 LIMIT ' . $start . ', ' . $this->max_rows;
+		}
+
+		update_option( '_bbp_repair_tool_query', $query );
+
+		$reply_to_array = $this->wpdb->get_results( $query );
+
+		foreach ( (array) $reply_to_array as $row ) {
+			$reply_to = $this->callback_reply_to( $row->meta_value );
+			$this->wpdb->query( 'UPDATE ' . $this->wpdb->postmeta . ' SET meta_value = "' . $reply_to . '" WHERE meta_key = "_bbp_reply_to" AND post_id = "' . $row->value_id . '" LIMIT 1' );
+			$has_update = true;
+		}
+
+		return ! $has_update;
+	}
+
+
+	/**
+	 * This method deletes data from the wp database.
+	 */
+	public function clean( $start ) {
+
+		$start      = 0;
+		$has_delete = false;
+
+		/** Delete bbconverter topics/forums/posts ****************************/
+
+		if ( true === $this->sync_table ) {
+			$query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->posts . ' ON(value_id = ID) WHERE meta_key LIKE "_bbp_%" AND value_type = "post" GROUP BY value_id ORDER BY value_id DESC LIMIT ' . $this->max_rows;
+		} else {
+			$query = 'SELECT post_id AS value_id FROM ' . $this->wpdb->postmeta . ' WHERE meta_key LIKE "_bbp_%" GROUP BY post_id ORDER BY post_id DESC LIMIT ' . $this->max_rows;
+		}
+
+		update_option( '_bbp_repair_tool_query', $query );
+
+		$posts = $this->wpdb->get_results( $query, ARRAY_A );
+
+		if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) {
+			foreach ( (array) $posts as $value ) {
+				wp_delete_post( $value['value_id'], true );
+			}
+			$has_delete = true;
+		}
+
+		/** Delete bbconverter users ******************************************/
+
+		if ( true === $this->sync_table ) {
+			$query = 'SELECT value_id FROM ' . $this->sync_table_name . ' INNER JOIN ' . $this->wpdb->users . ' ON(value_id = ID) WHERE meta_key = "_bbp_old_user_id" AND value_type = "user" LIMIT ' . $this->max_rows;
+		} else {
+			$query = 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" LIMIT ' . $this->max_rows;
+		}
+
+		update_option( '_bbp_repair_tool_query', $query );
+
+		$users = $this->wpdb->get_results( $query, ARRAY_A );
+
+		if ( ! empty( $users ) ) {
+			foreach ( $users as $value ) {
+				wp_delete_user( $value['value_id'] );
+			}
+			$has_delete = true;
+		}
+
+		unset( $posts );
+		unset( $users );
+
+		return ! $has_delete;
+	}
+
+	/**
+	 * This method deletes passwords from the wp database.
+	 *
+	 * @param int Start row
+	 */
+	public function clean_passwords( $start ) {
+
+		$has_delete = false;
+
+		/** Delete bbconverter passwords **************************************/
+
+		$query       = 'SELECT user_id, meta_value FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" LIMIT ' . $start . ', ' . $this->max_rows;
+		update_option( '_bbp_repair_tool_query', $query );
+
+		$repair_tool = $this->wpdb->get_results( $query, ARRAY_A );
+
+		if ( ! empty( $repair_tool ) ) {
+
+			foreach ( $repair_tool as $value ) {
+				if ( is_serialized( $value['meta_value'] ) ) {
+					$this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "" ' . 'WHERE ID = "' . $value['user_id'] . '"' );
+				} else {
+					$this->wpdb->query( 'UPDATE ' . $this->wpdb->users . ' ' . 'SET user_pass = "' . $value['meta_value'] . '" ' . 'WHERE ID = "' . $value['user_id'] . '"' );
+					$this->wpdb->query( 'DELETE FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_password" AND user_id = "' . $value['user_id'] . '"' );
+				}
+			}
+			$has_delete = true;
+		}
+
+		return ! $has_delete;
+	}
+
+	/**
+	 * This method implements the authentication for the different forums.
+	 *
+	 * @param string Unencoded password.
+	 */
+	abstract protected function authenticate_pass( $password, $hash );
+
+	/**
+	 * Info
+	 */
+	abstract protected function info();
+
+	/**
+	 * This method grabs appropriate fields from the table specified
+	 *
+	 * @param string The table name to grab fields from
+	 */
+	private function get_fields( $tablename ) {
+		$rval        = array();
+		$field_array = $this->wpdb->get_results( 'DESCRIBE ' . $tablename, ARRAY_A );
+
+		foreach ( $field_array as $field ) {
+			$rval[] = $field['Field'];
+		}
+
+		if ( $tablename === $this->wpdb->users ) {
+			$rval[] = 'role';
+			$rval[] = 'yim';
+			$rval[] = 'aim';
+			$rval[] = 'jabber';
+		}
+		return $rval;
+	}
+
+	/** Callbacks *************************************************************/
+
+	/**
+	 * A mini cache system to reduce database calls to user ID's
+	 *
+	 * @param string $field
+	 * @return string
+	 */
+	private function callback_userid( $field ) {
+		if ( ! isset( $this->map_userid[ $field ] ) ) {
+			if ( ! empty( $this->sync_table ) ) {
+				$row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT value_id, meta_value FROM ' . $this->sync_table_name . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) );
+			} else {
+				$row = $this->wpdb->get_row( $this->wpdb->prepare( 'SELECT user_id AS value_id FROM ' . $this->wpdb->usermeta . ' WHERE meta_key = "_bbp_old_user_id" AND meta_value = "%s" LIMIT 1', $field ) );
+			}
+
+			if ( ! is_null( $row ) ) {
+				$this->map_userid[ $field ] = $row->value_id;
+			} else {
+				if ( ! empty( $_POST['_bbp_repair_tool_convert_users'] ) && ( (int) $_POST['_bbp_repair_tool_convert_users'] == 1 ) ) {
+					$this->map_userid[ $field ] = 0;
+				} else {
+					$this->map_userid[ $field ] = $field;
+				}
+			}
+		}
+		return $this->map_userid[ $field ];
+	}
+}
+
+/**
+ * This is a function that is purposely written to look like a "new" statement.
+ * It is basically a dynamic loader that will load in the platform conversion
+ * of your choice.
+ *
+ * @param string $platform Name of valid platform class.
+ */
+function bbp_new_repair( $platform ) {
+	$found = false;
+
+	if ( $curdir = opendir( bbpress()->admin->admin_dir . 'converters/' ) ) {
+		while ( $file = readdir( $curdir ) ) {
+			if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === FALSE ) {
+				$file = preg_replace( '/.php/', '', $file );
+				if ( $platform === $file ) {
+					$found = true;
+					continue;
+				}
+			}
+		}
+		closedir( $curdir );
+	}
+
+	if ( true === $found ) {
+		require_once( bbpress()->admin->admin_dir . 'converters/' . $platform . '.php' );
+		return new $platform;
+	} else {
+		return null;
+	}
+}

Property changes on: src/includes/admin/repair-tools.php
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Index: src/includes/admin/settings.php
===================================================================
--- src/includes/admin/settings.php	(revision 6192)
+++ src/includes/admin/settings.php	(working copy)
@@ -1553,6 +1553,85 @@
 <?php
 }
 
+/** Repair Tool Section *********************************************************/
+
+/**
+ * Main settings section description for the settings page
+ *
+ * @since 2.6.0 bbPress (rXXXX)
+ */
+function bbp_repair_tool_setting_callback_main_section() {
+?>
+
+	<p><?php _e( 'Some optional parameters to help tune the repair tools process.', 'bbpress' ); ?></p>
+
+<?php
+}
+
+/**
+ * Edit Rows Limit setting field
+ *
+ * @since 2.6.0 bbPress (rXXXX)
+ */
+function bbp_repair_tool_setting_callback_rows() {
+?>
+
+	<input name="_bbp_repair_tool_rows" id="_bbp_repair_tool_rows" type="text" value="<?php bbp_form_option( '_bbp_repair_tool_rows', '100' ); ?>" class="small-text" />
+	<label for="_bbp_repair_tool_rows"><?php esc_html_e( 'rows to process at a time', 'bbpress' ); ?></label>
+	<p class="description"><?php esc_html_e( 'Keep this low if you experience out-of-memory issues.', 'bbpress' ); ?></p>
+
+<?php
+}
+
+/**
+ * Edit Delay Time setting field
+ *
+ * @since 2.6.0 bbPress (rXXXX)
+ */
+function bbp_repair_tool_setting_callback_delay_time() {
+?>
+
+	<input name="_bbp_repair_tool_delay_time" id="_bbp_repair_tool_delay_time" type="text" value="<?php bbp_form_option( '_bbp_repair_tool_delay_time', '1' ); ?>" class="small-text" />
+	<label for="_bbp_repair_tool_delay_time"><?php esc_html_e( 'second(s) delay between each group of rows', 'bbpress' ); ?></label>
+	<p class="description"><?php esc_html_e( 'Keep this high to prevent too-many-connection issues.', 'bbpress' ); ?></p>
+
+<?php
+}
+
+/** Repair Tool Page ************************************************************/
+
+/**
+ * The main settings page
+ *
+ * @uses settings_fields() To output the hidden fields for the form
+ * @uses do_settings_sections() To output the settings sections
+ */
+function bbp_repair_tool_settings() {
+?>
+
+	<div class="wrap">
+		<h1><?php esc_html_e( 'Forum Tools', 'bbpress' ); ?></h1>
+		<h2 class="nav-tab-wrapper"><?php bbp_tools_admin_tabs( esc_html__( 'Import Forums', 'bbpress' ) ); ?></h2>
+
+		<form action="#" method="post" id="bbp-repair-tool-settings">
+
+			<?php settings_fields( 'bbpress_repair_tool' ); ?>
+
+			<?php do_settings_sections( 'bbpress_repair_tool' ); ?>
+
+			<p class="submit">
+				<input type="button" name="submit" class="button-primary" id="bbp-repair-tool-start" value="<?php esc_attr_e( 'Start', 'bbpress' ); ?>" onclick="bbp_repair_tool_start();" />
+				<input type="button" name="submit" class="button-primary" id="bbp-repair-tool-stop" value="<?php esc_attr_e( 'Stop', 'bbpress' ); ?>" onclick="bbp_repair_tool_stop();" />
+				<img id="bbp-repair-tool-progress" src="">
+			</p>
+
+			<div class="bbp-repair-tool-updated" id="bbp-repair-tool-message"></div>
+		</form>
+	</div>
+
+<?php
+}
+
 /** Helpers *******************************************************************/
 
 /**
Index: src/includes/admin/tools.php
===================================================================
--- src/includes/admin/tools.php	(revision 6193)
+++ src/includes/admin/tools.php	(working copy)
@@ -154,8 +154,26 @@
 				</div>
 			</div>
 		</form>
+
+		<form action="#" method="post" id="bbp-repair-tool-settings">
+
+			<?php settings_fields( 'bbpress_repair_tool' ); ?>
+
+			<?php do_settings_sections( 'bbpress_repair_tool' ); ?>
+
+			<p class="submit">
+				<input type="button" name="submit" class="button-primary" id="bbp-repair-tool-start" value="<?php esc_attr_e( 'Start', 'bbpress' ); ?>" onclick="bbp_repair_tool_start();" />
+				<input type="button" name="submit" class="button-primary" id="bbp-repair-tool-stop" value="<?php esc_attr_e( 'Stop', 'bbpress' ); ?>" onclick="bbp_repair_tool_stop();" />
+				<img id="bbp-repair-tool-progress" src="">
+			</p>
+
+			<div class="bbp-repair-tool-updated" id="bbp-repair-tool-message"></div>
+		</form>
+
+
 	</div>
 
+
 <?php
 }
 
