在Plone 4.0.7中,FileField到BlobField迁移期间reindexObject失败

时间:2011-08-09 21:43:29

标签: migration plone filefield reindex

我正在尝试从plone 3.3.5迁移到plone 4.0.7并且我坚持将所有FileFields转换为BlobFields的步骤。

Plone升级脚本成功转换所有本机FileField但我有几个自定义的基于AT的类,必须手动转换。我尝试了两种方法进行转换,这导致了同样的错误。

  1. 使用Plone migration guidea source code example

  2. 中概述的schemaextender
  3. 将所有FileField重命名为blob字段,然后运行此脚本:

    from AccessControl.SecurityManagement import newSecurityManager
    from AccessControl import getSecurityManager
    
    from Products.CMFCore.utils import getToolByName
    from zope.app.component.hooks import setSite
    
    from Products.contentmigration.migrator import BaseInlineMigrator
    from Products.contentmigration.walker import CustomQueryWalker
    
    from plone.app.blob.field import BlobField
    
    
    admin=app.acl_users.getUserById("admin")
    newSecurityManager(None, admin)
    
    portal = app.plone
    setSite(portal)
    
    
    def find_all_types_fields(portal_catalog, type_instance_to_search):
        output = {}
        searched = []
        for k in catalog():
            kobj = k.getObject()
            if kobj.__class__.__name__ in searched:
                continue
            searched.append(kobj.__class__.__name__)
            for field in kobj.schema.fields():
                if isinstance(field, type_instance_to_search):
                    if kobj.__class__.__name__ in output:
                        output[kobj.__class__.__name__].append(field.__name__)
                    else:
                        output[kobj.__class__.__name__] = [field.__name__]
        return output
    
    def produce_migrator(field_map):
        source_class = field_map.keys()[0]
        fields = {}
        for x in field_map.values()[0]: fields[x] = None
    
        class FileBlobMigrator(BaseInlineMigrator):
            '''Migrating ExtensionBlobField (which is still a FileField) to BlobField'''
            src_portal_type = source_class
            src_meta_type = source_class
            fields_map = fields
            def migrate_data(self):
                '''Unfinished'''
                for k in self.fields_map.keys():
                    #print "examining attributes"
                    #import pdb; pdb.set_trace()
                    #if hasattr(self.obj, k):
                    if k in self.obj.schema.keys():
                        print("***converting attribute:", k)
                        field = self.obj.getField(k).get(self.obj)
                        mutator = self.obj.getField(k).getMutator(self.obj)
                        mutator(field)
            def last_migrate_reindex(self):
                '''Unfinished'''
                self.obj.reindexObject()
        return FileBlobMigrator
    
    def consume_migrator(portal_catalog, migrator):
        walker = CustomQueryWalker(portal_catalog, migrator, full_transaction=True)
        transaction.savepoint(optimistic=True)
        walker_status = walker.go()
        return walker.getOutput()
    
    def migrate_blobs(catalog, migrate_type):
        all_fields = find_all_types_fields(catalog, migrate_type)
        import pdb; pdb.set_trace()
        for k in [ {k : all_fields[k]} for k in all_fields]:
            migrator = produce_migrator(k)
            print consume_migrator(catalog, migrator)
    
    
    catalog = getToolByName(portal, 'portal_catalog')
    
    migrate_blobs(catalog, BlobField)
    
  4. 问题发生在self.obj.reindexObject()行,我收到以下回溯:

        2011-08-09 17:21:12 ERROR Zope.UnIndex KeywordIndex: unindex_object could not remove documentId -1945041983 from index object_provides.  This should not happen.
        Traceback (most recent call last):
        File "/home/alex/projects/plone4/eggs/Zope2-2.12.18-py2.6-linux-x86_64.egg/Products/PluginIndexes/common/UnIndex.py", line 166, in removeForwardIndexEntry indexRow.remove(documentId)
        KeyError: -1945041983
        > /home/alex/projects/plone4/eggs/Zope2-2.12.18-py2.6-linux-x86_64.egg/Products/PluginIndexes/common/UnIndex.py(192)removeForwardIndexEntry()
            191                            str(documentId), str(self.id)),
        --> 192                            exc_info=sys.exc_info())
            193         else:
    

    如果我删除触发重建索引的行,转换成功完成,但如果我稍后尝试手动重新编制目录,则无法再找到已转换的每个对象,而且我有点不知所措现在

    该网站安装了LinguaPlone,可能与此有关吗?

1 个答案:

答案 0 :(得分:2)

一种选择是在没有reindexObject()调用的情况下运行迁移,并在迁移后在目录ZMI Advanced选项卡中执行“Clear and Rebuild”。