How to code a forum importer


Importers are used when you want to move data(users and posts) to codoforum from a different forum platform such as PHPBB, SMF etc.

The importer already exists within codoforum, but you will have to code some part(a driver) to fetch the data from your old forum.

Writing the driver

Writing a driver for codoforum is very easy and can be completed within 15-20 mins.

All the drivers used by the importer are stored in
codoforum/sys/Lib/Importer/Drivers/

Before starting, let us assume our requirements . We want to import data from an arbitrary forum named ForumX that stores its forum categories in table categories , topics in table topics, posts in table posts and users in table users

First Step

  • Copy any one of the drivers present in the Drivers folder
  • Rename the copied file to ForumX.php
  • Open the file and rename the class to ForumX (importer name)

Note: The name of the file and the class inside the file must be same.

Second step

Let us go line by line in our driver file .


public $max_rows = 100;

This value is set by the user running the importer, so you do not have to edit this value.


public $post_has_topic = false;

Before setting this value , let us understand a small concept about the codoforum importer.
The importer has two types of drivers which are based on how the forum is implemented.

Type 1
Some forum systems like Drupal store the topic message and the post messages separately .

Type 2
But many forum systems like SMF, Kunena, etc stores all topic messages inside the posts table . The topics table only has a link to the corresponding message of the topic in the posts table.

If the forum system for which you are making an importer is type 1, then it will be

public $post_has_topic = false;

And if the forum system is of type 2, then it will be

public $post_has_topic = true;

To understand the two types better, let us consider an example .
Assume that in a forum system, some user A posted a topic with the title "X vs Y" and message "Why is X better than Y"
And then a second user B posted a reply with the message "X is better because of Z"

Type 1 forums will store the data as follows

The topic table:

topic_id topic_title topic_message
1 X vs Y Why is X better than Y

And the posts table:

post_id topic_id post_message
1 1 X is better because of Z

Type 2 forums will store the data as follows

The topic table:

topic_id topic_title post_id
1 X vs Y 1

And the posts table:

post_id topic_id post_message
1 1 Why is X better than Y
2 1 X is better because of Z


Moving on, our next function in our driver is

public function get_cats()

You need to edit the query of above function, so that you get below information

  • category id -> cat_id
  • category name -> cat_name
  • category description -> cat_description
  • category order -> cat_order
  • category parent id -> cat_pid

Right of the arrow "->" are the SQL ALIAS that should be used. For eg.

SELECT category_id AS cat_id ....  
FROM categories

The cat_id used above is the alias

If you remember, categories is the name of the table we assumed in the beginning where our forum categories will be stored



Now, our next function in our driver is

public function get_topics($start)

You need to edit the query so that you get below information

  • topic id -> topic_id
  • topic title -> title
  • category id -> cat_id
  • topic created time -> topic_created
  • topic updated time -> topic_updated
  • last post time -> last_post_time
  • user id who created -> uid
  • post message -> message
  • post id -> post_id

Here, the post message is selected only if you had set

public $post_has_topic = false;

i.e in a Type 1 forum otherwise it is optional .

And the post id is selected only if you had set

public $post_has_topic = true;

i.e in a Type 2 forum otherwise it is optional .

The $start variable is used in the LIMIT clause to get a particular range of results . Since we limit the number of results that we get in one request , on every request the $start variable is incremented by the maximum number of rows fetched in one request



Then, our next function in our driver is

public function get_posts($start)

You need to edit above function to get following details:

  • category id -> cat_id
  • topic id -> topic_id
  • user id -> uid
  • post message -> message
  • post created time -> post_created
  • post modified time -> post_modified



Further, our next function in our driver is

public function get_users($start)

You need to edit above function to get following details:

  • user id -> uid
  • username -> username
  • nickname -> name
  • password -> pass
  • email -> mail
  • forum signature -> signature
  • user created time -> created
  • user last login time -> last_access
  • user status -> status
  • user avatar url -> avatar
  • user role id -> rid [OPTIONAL]

The user's role id is like a group id which tells codoforum that the user belongs to which group (guest, user, moderator, administrator, etc)
The user's role id is optional , and if it is not selected, codoforum will consider all importer users as normal users.

The user status can be 1 or 0 .

1 -> Confirmed user
2 -> Unconfirmed user



Our last function in our driver is

public function get_user_by_mail($mail)

The above function is used by the importer to check if the email address of the administrator provided during import exists , and if it exists it returns the userid of that user (i.e administrator)

You need to edit the function, such that it returns the user id of the user when the user's email address is passed .


Third step

After completing the second step, the importer is now ready to use . It will now automatically be listed in the importer page in the codoforum admin area.

© CODOFORUM 2018. All Rights Reserved.