Skip to:

Import data from system 'XYZ' (phpBB 2, 3 / SMF / etc)

  • Where are we now?

    Aside from the questions surrounding integration with WordPress, another of our big questions is “how do I import from _____” (insert a different forum product of your choosing)

    Right now the approach is ad-hoc at best: We are handing a PHP script around hand-to-hand that is able to convert a phpBB v2.0.x forum over to bbPress v. 0.9, and if you want to convert a different forum (say, SMF) the accepted wisdom is to install phpBB, convert to that, then convert to bbPress 0.9 and then upgrade.

    The official coding standards for WordPress state:

    Avoid touching the database directly. If there is a defined function that can get the data you need, use it. Database abstraction (using functions instead of queries) helps keep your code forward-compatible and, in cases where results are cached in memory, it can be many times faster.

    As it stands bbPress imports clearly violate that principle by using the script we are passing around.

    Solving the problem

    Importing data clearly is an example where a strategy pattern solves things in an elegant fashion.

    The strategy pattern (also known as the policy pattern) is a particular software design pattern, whereby algorithms can be selected at runtime.

    The strategy pattern is useful for situations where it is necessary to dynamically swap the algorithms used in an application. The strategy pattern is intended to provide a means to define a family of algorithms, encapsulate each one as an object, and make them interchangeable. The strategy pattern lets the algorithms vary independently from clients that use them.

    More concretely, this means creating a bbPress Import plugin which provides an overall multi-step process, and delegates to an external sub-plugin to retrieve the external datasource specific steps. I would argue that this ought to be a plugin (and remain a plugin rather than being pulled into the core of bbPress) because once you’ve imported from a given external forum, you can deactivate and uninstall the “import” code as its no longer required.


    1. We need to create a basic import plugin. — This I have done, it’s experimental and I’d like some more eyes on the code before calling it “done”
    2. We need to create import strategies for external forums, starting with phpBB2 — This I have done, by extracting SQL from the script we all pass hand-to-hand. Again, it needs more eyes on the code as a QA step.
    3. We need to create import strategies for other external forums, specifically SMF and phpBB3 — this is where the strategy pattern comes into its own – each can be developed independently and combined later. Its also a great place for community input.

    Looking further out

    The import plugin relies on calling the internal bb_new_post, bb_new_topic, bb_new_forum and to a certain degree the bb_new_user methods. As we move toward bbPress being a plugin to WordPress, these will become the only way to import data, as the script we pass around will become evermore obsolete.

    Secondly, WordPress itself has an import framework. I suspect that any “import plugin” we write now will become somewhat obsolete in that timeframe. That said, if we do things right, the import strategies we create might migrate over. What I dont know is the timeframe. Is the bbPress-as-a-plugin-to-Wordpress change close enough on the horizon that we should simply target the WordPress import framework directly?

    Thoughts / comments?

Viewing 2 replies - 1 through 2 (of 2 total)
  • glad to hear you’re still working on this as it will help a lot of people! Do we actually have any concrete information about how close any integration with wordpress is, in order to make the decisions you suggest?

    We need to create a basic import plugin. — This I have done, it’s experimental and I’d like some more eyes on the code before calling it “done”

    I’ve looked for it but haven’t found it. I guess it hasn’t been published yet?

    I ask for help in making a single-use script to import topics and posts into existing BBPress installation.

    I need to import a legacy Q&A (hundreds of them) stored in a flat file. I need to handle fields missing in the source, which contains: Q poster, Q poster’s e-mail (optional), Q post date, Q content, A content. I want to import those and fill the missing fields with arbitrary values.

    I chose to use API to do the task, which is a right choice, what was pointed above. I converted the source file manually and imported it into a multi-dimensional array. Then I want to use functions bb_insert_topic and bb_insert_post in a simple loop:

    $topic_id = bb_insert_topic(array(...));

    bb_insert_post(array('topic_id' => $topic_id, ...);

    The problem is: I can create topics/posts only for current user. Any poster_ parameters passed to bb_insert_ are ignored. In other words, I can’t create anonymous topics/posts with poster credits I specify. I guess I’m missing a setting or constant?

    The PHP script is located in the root folder of BBPress. I do require('./bb-load.php'); and log in to my keymaster user in the browser. All of $bbdb, $bb and $bb_current_user are populated (I used FirePHP to debug).

    What am I missing?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar