Marcos Placona Blog

Programming, technology and the taming of the web.

Migrating Mango Blog to WordPress

Reading time: 5 – 8 minutes

Migration in actionPhoto by: gagilas

As previously promised, today I’ll be publishing my migration scrips from Mango Blog to WordPress.

As mentioned previously, I wrote this script entirely for my own benefit, so please excuse me if it doesn’t meet your expectations. It has only been tested on mySQL, but should run on other SQL engines without major updates.

The script is supposed to deal with all the posts and comments, and will convert code snippets that use the SyntaxHighlighter plugin (by Tony Garcia) into the default Alex Gorbatchev‘s SyntaxHighlighter style. So the only thing you will need to do, is install a WordPress plugin that can deal with the tags. I’m using a plugin called SyntaxHighlighter Evolved, and am very happy so far.

It will also make sure all the categories are adequately created and asigned to your posts as they are created, so you won’t have to manually create them, or import them in a separate batch. Categories in WordPress a very tricky, and it took me a great deal of time to understand exactly how they are stored, and how the relationships work, so this should save you a long time on the migration.

I’ll briefly explain the script’s functionality here, but the comments on the code should be enough ro help someone trying to extend it, or even make it work with other blogging engines.

There is only one file responsible for the actions, and as long as the right method is called (batchPostWordpress), everything should happen automatically, and your posts, along with comments and everything else will be migrated. The only thing this script does not deal with, are the images, but as you should already be using only image paths (i.e. you are not storing anything on the database), your images should still work as long as they are stored on the right path. In my case, as I normally store images on a separate server, I wouldn’t have to worry about that.

Step ONE:

You must have two ColdFusion DSN’s on your server. One is for the current Mango Blog, and another for the new WordPress install. Obviously your WordPress won’t be using this DSN after you have migrated, but as this is a ColdFusion script, and you will be using ColdFusion to migrate your content, you will need a DSN created on your ColdFusion server.

In my case, I was “creative”, and called one mango (pointing to the mangoblog datrabase) and another one wordpress (pointing to the wordpress database). No rocket science up to here as you can see.

Step TWO:

Download the files, and extract them to your ColdFusion root, or anywhere where you can execute CFML files. For this example, I’m executing everything from ColdFusion’s root ( OR localhost).

Having the files in there, open runner.cfm, and change the variables mango_dsn and wordpress_dsn to suit your needs. Mine looks like this:

<cfset posts = createObject("component", "PostManager").init	(
											mango_dsn : 'mango',
											wordpress_dsn : 'wordpress'
											) />

On the next lines, you will find the following:

<cfset qPosts = posts.batchPostWordpress(
									start 	: 0,
									limit 	: 100
										) />

This pretty much says everything. It’s calling the method batchPostWordpress and processing posts in batches of 100 posts. I ran this with batches of 200 posts without any problems, and it only took about 30 seconds running on Railo. The numbers may vary according to the number of posts you have, as well as the number of comments and categories. Remember that if you have too many comments, your posts will take longer to be migrated, as everything is created in one go.

Step Three:

Run the file  runner.cfm (in my case, and wait till the page stops loading. Once everything is done, you should see a message saying “Done!” on the screen.

Well done, you’ve just migrated from Mango Blog to WordPress without any major hassle.

This script is dealing with a number of custom things I had on my setup, such as different ways of posting code snippets. It should be a problem to people using only one way, or not using it at all, as it tries to replace text only, and won’t break anything should the text isn’t available.

The private method cleanupPostCode, is the method that dos all the conversions, and it’s there that you will need to add any other conversion you may need should you be using other form of syntax highlighting. I’d recommend that id you are not using it, you can simply replace lines 153 and 154 to read:

<cfset var cleanContent = arguments.content>
<cfset var cleanExcerpt = arguments.excerpt>

This way, you are not cleaning up your post’s code, and that should make the code run considerably faster. if you leave it as it was before, it won’t break anything as previously stated.

I hope this script is of any use to someone, and if you feel like modifying / improving the code, please contact me sending the updates, and I’ll merge it and give credit where credit is due. Also, on the right-hand menu, you will find a link to PayPal, where you can make donations to help maintaining this website. Any amount will be much appreciated.


  1. Marcos,

    Thanks a ton for posting these, worked like a charm!

    I made a few tweaks, since the blog I was migrating had tons of technical content, I added cfqueryparam’s to all the insert statements so SQL and source code in the blog content did not break the insert statements. The only other tweak I made was to handle table prefix names that we configured, otherwise it went perfect. Thank you again!


  2. I keep getting the following ColdFusion error:
    Cannot declare local variable content twice.
    Local variables cannot have the same names as parameters or other local variables.
    The error occurred in C:\inetpub\wwwroot\Mango2Wordpress\runner.cfm: line 2
    1 :
    2 : <cfset posts = createObject("component", "PostManager").init (
    3 : mango_dsn : 'fgi_blogs',
    4 : wordpress_dsn : 'fgi_wordpress'

  3. Marcos Placona

    October 26, 2010 at 12:37

    What CFML engine are you using?

  4. CF8. I noticed there a some places in the code where there is an argument variable AND a local variable with var scope inside a method. One is called “content” (in a couple places) and another is qCategories. Also, my code is in a subdirectory of my localhost root, so I realized I had to prefix my call to PostManager with my subdirectory name. That was part of the issue, but still doesn’t resolve the “cannot declare local variable X twice” error.

  5. I had to make some tweaks to the CFC in order to get it to work for me – most notably the database name “wordpress” was hardcoded as a prefix to the INSERT statements, but my database name was not “wordpress” (had a prefix from the hosting provider). Hopefully that’s a time-saver for others 🙂

  6. Marcos Placona

    October 27, 2010 at 09:47

    Thanks for reporting back Paul. Glad you’re all sorted 😉

  7. Hi Marco this for sharing this. I’m getting the same error message “Cannot declare local variable content twice” as Paul. I didn’t have any prefix on WordPress tables. I’m running CF8, any suggestion?

    thank you,

  8. Hi there, sadly I am abandoning CF and Mango because I can’t get it to work anymore on Mavericks.
    Running the Mango-WP I get the error:
    CONTENT is already defined in argument scope.
    I had a look and I couldn’t figure this one out… can you help? I am probably on the latest version of CF. Or second latest. If I can get this to work I will happily donate!!!
    PS I couldn’t get past CAPTCHA to contact you directly 🙁

  9. Marcos Placona

    December 16, 2013 at 17:54

    Let me know if you still haven’t got past that, and I will have a look at it for you.

Leave a Reply

Your email address will not be published.