特定文件夹的内容迁移

发布于 2024-12-16 19:30:33 字数 719 浏览 1 评论 0原文

我有一个脚本,将 Image 迁移到我的 Plone 实例的自定义类型。它的部分代码示例如下所示:

class ImagesToPhotosMigrator(InplaceATItemMigrator):
    src_portal_type = 'Image'
    src_meta_type = 'ATBlob'
    dst_portal_type = 'Photo'
    dst_meta_type = 'Photo'

    def last_migrate_reindex(self):
        self.new.reindexObject(idxs=['object_provides', 'portal_type',
            'Type', 'UID'])

    fields_map = {
    }

def getImagesToPhotosMigrationWalker(self):
    return getMigrationWalker(self, migrator=ImagesToPhotosMigrator)

def migrateImages(self):
    walker = getImagesToPhotosMigrationWalker(self)
    walker.go()
    return walker.getOutput()

脚本有效,但我希望迁移仅发生在特定文件夹中,例如 /my-folder,在脚本中添加什么?

I have a script, migrating Image to a custom type, for my Plone instance. Its partial code sample looks like this:

class ImagesToPhotosMigrator(InplaceATItemMigrator):
    src_portal_type = 'Image'
    src_meta_type = 'ATBlob'
    dst_portal_type = 'Photo'
    dst_meta_type = 'Photo'

    def last_migrate_reindex(self):
        self.new.reindexObject(idxs=['object_provides', 'portal_type',
            'Type', 'UID'])

    fields_map = {
    }

def getImagesToPhotosMigrationWalker(self):
    return getMigrationWalker(self, migrator=ImagesToPhotosMigrator)

def migrateImages(self):
    walker = getImagesToPhotosMigrationWalker(self)
    walker.go()
    return walker.getOutput()

The script works, but I want the migration only happens in a specific folder, say /my-folder, what to add in the script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岛徒 2024-12-23 19:30:33

您应该指定您引用 Products.contentmigration,因为它没有隐含在单词中“内容迁移”(最近迁移的种类比代码行还要多)。无论如何,这里是您的解决方案(CustomQueryWalker 是关键):

from Products.contentmigration.walker import CustomQueryWalker

def getImagesToPhotosMigrationWalker(self, query):
    return CustomQueryWalker(self, ImagesToPhotosMigrator, query)

def migrateImages(self):
    walker = getImagesToPhotosMigrationWalker(self, {'path' : '/youfolder'})
    walker.go()
    return walker.getOutput()

请注意,查询参数是目录查询,因此您可以指定路径、portal_type 或目录中的任何索引。

You should have specified that you refer to Products.contentmigration, cause it's not implicit in the words "content migration" (lately there are more kind of migrations than lines of code). Anyway, here your solution (CustomQueryWalker is the key):

from Products.contentmigration.walker import CustomQueryWalker

def getImagesToPhotosMigrationWalker(self, query):
    return CustomQueryWalker(self, ImagesToPhotosMigrator, query)

def migrateImages(self):
    walker = getImagesToPhotosMigrationWalker(self, {'path' : '/youfolder'})
    walker.go()
    return walker.getOutput()

Note that the query parameter is a catalog query, therefore you can specify the path, the portal_type or any index in your catalog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文