Migrating To Orchard

No Comments February 28, 2011

It’s time to jump ship again and move to a new Blog system – this time I’ve settled on Orchard, a .NET CMS system with (amongst other things) a full-featured blogging engine.

Migrating from my previous system (dasBlog) has been fairly straightforward, but not without its little challenges. I’ll detail the main steps I had to take in the hope that it will make life easier for anyone else attempting the same thing.

Using WebMatrix I set up a blank Orchard site on my local machine, and got the basic settings configured for the new site, leaving my existing site up and running on my hosting provider. From the Orchard Gallery link within Orchard itself, I downloaded and enabled the BlogML Module.

I then downloaded the DasBlog <-> BlogML utility and ran it against my local backup of my dasBlog site, generating a BlogML format export. I did an initial test-run importing the BlogML which worked fine, but I quickly hit an issue with all the images that I had embedded in my existing blog posts.

Rather than editing all my existing posts and uploading new images for each one, I hacked together a small bit of code to grab assets from my existing site embed them in the BlogML export as Base64 encoded strings:

XDocument doc = XDocument.Load(@"blog.xml");
XNamespace ns = XNamespace.Get("http://www.blogml.com/2006/09/BlogML");

var posts = doc.Descendants(ns + "post");
var postsWithAttachments = posts.Where(p => p.Descendants(ns + "attachment").Count() > 0);

foreach (var post in postsWithAttachments)
{
    foreach (var attachment in post.Descendants(ns + "attachment"))
    {
        WebClient client = new WebClient();
        var attribute = attachment.Attribute("external-uri").Value;

        Console.Write("{0}: ", attribute);

        byte[] data = null;
        try
        {
            data = client.DownloadData(attribute);
        }
        catch { }

        if (data != null)
        {
            Console.WriteLine("OK");
            attachment.SetAttributeValue("embedded", "true");
            attachment.SetValue(System.Convert.ToBase64String(data));
        }
        else
        {
            Console.WriteLine("Failed");
        }
    }
}

posts.Descendants(ns + "trackback").Cast<XNode>().ToList().ForEach(n => n.Remove());
doc.Save(@"blog2.xml");

As 99.9% of the trackback links in the export were from spam sites, I decided to simply drop them all from the export file. The BlogML plugin within Orchard handled the resulting BlogML file without a problem – I know this is not in any way ideal, especially for very large sites, but it worked well for me; all the images were duly extracted and recreated in the appropriate Media folder.

The only other issue was, I suspect, as a result of my hosting provider; Orchard would continually force me to log back in every 20 or so seconds once the site had been published up to the net. Adding a

<machinekey decryption="AES" validation="SHA1" decryptionkey="..." validationkey="..." />

directive to my web.config seemed to fix (or at least mask) the issue for the time being. There is a useful <machineKey> Generator available to get around the drudgery of having to generate the keys yourself.

And that’s basically it; I’ve got a lot to learn about Orchard, and I’ve got a few ideas for some useful modules that I hope to bring online fairly soon.


No Comments