Migrating from (now obsolete) custom ATImage content type

 ̄綄美尐妖づ 提交于 2019-12-05 11:52:13

Yes, there is a recommended approach:

http://pypi.python.org/pypi/Products.contentmigration

The only thing that you have to do is to write a custom migration from FalconImage to Image.

Bye, Giacomo

You need to use Products.contentmigration but the docs there are no place to start. Use the docs at plone.org for a step-by-step on migrating content.

Thanks to Giacomo and Ross for the pointers.

Just in case it is useful to others, my migration code ended up looking like the following:

from Products.contentmigration.walker import CustomQueryWalker
from Products.contentmigration.archetypes import InplaceATItemMigrator

class FalconImageMigrator(InplaceATItemMigrator):
    walker = CustomQueryWalker
    src_meta_type = "FalconImage"
    src_portal_type = "FalconImage"
    dst_meta_type = "ATBlob"
    dst_portal_type = "Image"

    # Following stolen from plone.app.blob.migrations, ATImageToBlobImageMigrator
    # migrate all fields except 'image', which needs special handling...
    fields_map = {
        'image': None,
    }

    def migrate_data(self):
        self.new.getField('image').getMutator(self.new)(self.old)

    # ATFileToBlobMigrator reindexes certain fields. Otherwise we
    # need to clear and rebuild the entire catalog.
    def last_migrate_reindex(self):
        self.new.reindexObject(idxs=['object_provides', 'portal_type',
           'Type', 'UID'])

migrator = FalconImageMigrator
walker   = migrator.walker(portal, FalconImageMigrator)

walker.go()
print walker.getOutput()

Complications:

  1. Image is a little odd as a destination type, as data gets migrated into the blob store.

  2. We need to update the catalog so that "resolveuid/UID" links generated by TinyMCE continue to work. last_migrate_reindex() method on Migrator class should be faster than clearing and rebuilding the entire catalog from scratch.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!