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.
- 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
- We also need to determine the database prefix that will be used in the ‘Import Forums’ UI
- Make a copy of Example.php in the same folder and call it Mingle.php (The filename here IS case sensitive)
- Open up your favourite text editor (Notepad, Text Pad, Notepad++, Sublime Text etc) and start editing your newly created Mingle.php file
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):
- 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)
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'
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:
- A calculated guess would have us use the following for our first database mapping
- 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'
- The calculated guess this time will have us use the following for our second database mapping
- Now we repeat this for each of the existing database mappings in Example.php
'from_tablename' => 'forum_forums',
'from_fieldname' => 'id',
'from_tablename' => 'forum_forums',
'from_fieldname' => 'parent_id',