Personal tools
You are here: Home Weblog Scrawld

Scrawld

Posted by Sean Fulmer at May 25, 2008 09:25 PM |
Filed under:

How I migrated my old blog entries over to Scrawl, a lightweight blogging solution for Plone

I've been doing the "news-items-as-blog" thing in Plone here for a while. It fits well in a plain-vanilla Plone environment, but the presentation never felt very "bloggy" to me. I wanted to try something new, but I didn't want to stray too far from the "pure Plone" approach to blogging, so when I noticed Scrawl in the Plone products index, I thought I'd give it a try.

Installation of Scrawl was straightforward, and after creating a few test entries with it, I was ready to migrate my news items over to Scrawl's "blog entry" content type. This was pretty easy, since Scrawl simply repurposes the News Item content type. First, I re-named the folder that contained my existing news items. Then, I created a new folder with the same ID as the old folder. Finally, I ran the following script (from my custom skin folder) to create Blog Entries with the same content and ID's as my old News Items:

from Products.CMFCore.utils import getToolByName

# get the catalog & workflow tools
pc = getToolByName(context, "portal_catalog")
wf = getToolByName(context, "portal_workflow")

# folder where the new Scrawl items will go
# change this for your own needs
nblog = context.nowhere.archive

# get News Items and create Blog Entries
entries = [e.getObject() for e in
            pc.searchResults(portal_type="News Item")]
for e in entries:

    # get info from the old object
    nid = e.id
    nkws = e.Subject()
    cdate = e.CreationDate()
    edate = e.getEffectiveDate()
    mdate = e.ModificationDate()
    ntitle = e.Title()
    ndescr = e.Description()
    ntext =  e.getText()
    ntype = e.Schema()['text'].getContentType(e)

    # create the new object
    nblog.invokeFactory(type_name = "Blog Entry", id=nid)
    item = nblog[nid]
    item.editMetadata(subject=nkws)
    item.setFormat(ntype)
    item.update(title=ntitle,
                text=ntext,
                description=ndescr,
                creation_date=cdate,
                effective_date=edate,
                )

    # my items are initially private, so two steps to publish
    wf.doActionFor(item, "show")
    wf.doActionFor(item, "publish")

    # set the dates on the new object to match the old object
    item.setCreationDate(cdate)
    item.setEffectiveDate(edate)
    item.setModificationDate(mdate)
    item.indexObject()
    print "created "+ nid

return printed

After running that, I had published blog entries that were copies of my old new items, with the same id's and in the same location as the old items, completely migrated with old URLs intact.

Feel free to copy and modify that script for your own needs - it's a simple example of how to migrate one content type over to another.

Edit: It just occurred to me that my script up there does not migrate comments. I only had a couple of comments on my old entries, so it's not a big deal for me, but it might be for you.

Document Actions
About Me
Sean Fulmer is a Plone developer/integrator and tech support geek living in the middle of nowhere in southwestern New Mexico, USA.
Clicky Web Analytics