Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Import

Codex HomeImport Forums → Custom Import

Related: #2134 Improve readability in Example.php Forum Importer (Inline Docs & Code Formatting)

You can customize the included example.php located in /bbpress/includes/admin/converters/Example.php to setup an import from any MySQL database.

A good reference is to look at the included converters bbPress1.php, phpBB.php and SimplePress5.php and compare the database table and field mappings as that should give you some good hints.


The below is a work in progress on stepping through an example of customizing the included Example.php converter taken from the support forums request for help making a Mingle Forums converter. Another great post by @robin-w on converting Snitz Forums from a Microsoft Access to MySQL databse with a custom importer can also be read here.

  1. One of the first steps you need is to find the database schema of the current SQL database you want to import from, this can be in the docs of the exisisting sofware or you can find this using phpMyAdmin, for now I’ll just link to this here from the original post
  2. We also need to determine the database prefix that will be used in the ‘Import Forums’ UI
  3. Is the existing forum sharing the same target WordPress Database or is the existing database completely separate to the target WordPress database?
    In this example using Mingle it is a WordPress plugin and shares the same database as WordPress and adds the following tables tables to the existing WordPress database (WordPress is setup in this case using wp_ as the database prefix):

    wp_forum_forums
    wp_forum_groups
    wp_forum_posts
    wp_forum_threads
    wp_forum_usergroup2user
    wp_forum_usergroups

  4. Make a copy of Example.php in the same folder and call it Mingle.php (The filename here IS case sensitive)
  5. Open up your favourite text editor (Notepad, Text Pad, Notepad++, Sublime Text etc) and start editing your newly created Mingle.php file
    • Give the converter a unique name by making the following changes:

      Line #4 From:
      * Implementation of Example converter.
      Line #4 To:
      * Implementation of Mingle Forums converter.

      Line #06 From:
      class Example_Converter extends BBP_Converter_Base
      Line #06 To:
      class Mingle extends BBP_Converter_Base
      (Ensure the above matches the first part of the filename as it IS case sensitive)

  6. Starting with the Forum Section and the first database table and field mapping ‘Forum ID’in Example.php Line #18
    • 18 // Forum id. Stored in postmeta.
      19 $this->field_map[] = array(
      20 'from_tablename' => 'forum', 'from_fieldname' => 'forumid',
      21 'to_type' => 'forum', 'to_fieldname' => '_bbp_forum_id'
      22 );

      See that we have a ‘from_tablename’ called ‘forum’ and a ‘from_fieldname’ called ‘forumid’ these are the only two values that you will need to change in most cases. Both the ‘to_type’ ‘to_type’ and ‘to_fieldname’ values is where this data is stored in bbPress and we don’t need to change any of these.
    • If we compare these same values with bbPress1.php:

      29 'from_tablename' => 'forums',
      30 'from_fieldname' => 'forum_id',
    • Compared with phpBB.php:

      18 'from_tablename' => 'forums',
      19 'from_fieldname' => 'forum_id',
    • Compared with SimplePress5.php:

      20 'from_tablename' => 'sfforums',
      21 'from_fieldname' => 'forum_id',
    • If we look at the Mingle Forums database schema:
      wp_forum_forums
      id
      name
      parent_id
      description
      views
      sort
    • A calculated guess would have us use the following for our first database mapping

    • 'from_tablename' => 'forum_forums',
      'from_fieldname' => 'id',

    • Next in the Forum Section for the second database mapping ‘Forum Parent ID’ in Example.php Line#24
    • 24 // Forum parent id. If no parent, than 0. Stored in postmeta.
      25 $this->field_map[] = array(
      26 'from_tablename' => 'forum', 'from_fieldname' => 'parentid',
      27 'to_type' => 'forum', 'to_fieldname' => '_bbp_parent_id'
      28 );
    • The calculated guess this time will have us use the following for our second database mapping

    • 'from_tablename' => 'forum_forums',
      'from_fieldname' => 'parent_id',

    • Now we repeat this for each of the existing database mappings in Example.php
  7. Joining tables for particular field values…
  8. Tags – If the source forum does not use topic tags you can remove this section from the converter, if it does edit the ‘from’ values.
  9. Users…
  10. Migrating BBCode, Smileys and Custom HTML…
  11. Next steps…