Newer
Older
floop.migration / floop / migration / migrate.py
from StringIO import StringIO

from Products.contentmigration.walker import CustomQueryWalker
from Products.contentmigration.inplace import BaseInplaceMigrator, InplaceItemMigrationMixin
from DateTime import DateTime

class ZWikiMigrator(object, InplaceItemMigrationMixin, BaseInplaceMigrator):
    """Migrate the old item type to the new item type
    """
    walker = CustomQueryWalker
    src_meta_type = "ZWiki Page"
    src_portal_type = "Wiki Page"
    dst_meta_type = "ATDocument"
    dst_portal_type = "Document"

    def __init__(self, *args, **kwargs):
        self.old = args[0] #The original object
        self.orig_id = self.old.getId() #The original object id
        self.old_id = 'old_%s' % self.orig_id #Change the old id to this after copying
        self.new_id = self.old.getId() #Make the new object id this
        self.parent = self.old.getParentNode() #Grap the object's parent

        super(ZWikiMigrator, self).__init__(*args, **kwargs)

    def migrate_page(self):
        self.new.setText(self.old.src())
        self.new.setTitle(self.old.title)

    def migrate_owner(self):
        self.new.setCreators([self.old.creator])

    def last_migrate_date(self):
        self.new.creation_date = DateTime(self.old.creation_time)
        self.new.setModificationDate(DateTime(self.old.last_edit_time))

    def last_migrate_contenttype(self):
        self.new.setContentType('text/structured')

def migrate(portal):
    """The migrate function that runs everything.  This is what gets imported
    for your tests.
    """
    out = StringIO()  #Big o
    migrators = (ZWikiMigrator,)

    #Run the migrations
    for migrator in migrators:
        print >>out, "--Migrating %ss \n\n" % migrator.src_meta_type
        walker = migrator.walker(portal, migrator)
        walker.go(out=out)
        print >>out, walker.getOutput()

    return out.getvalue()