How to clean up old interfaces on zc.relation catalog?

后端 未结 4 2118
既然无缘
既然无缘 2021-01-22 14:48

I was using plone.directives.form version 1.0 with Plone 4.2.5 and after upgrading to 4.2.6 I started seeing the following traceback and I guess its due to plone.

4条回答
  •  旧巷少年郎
    2021-01-22 15:19

    Just for reference that's how I fixed it:

    While still on plone.directives.form 1.0 update your objects so that they do no longer provide the plone.directives.form.schema.Schema interface.

    Then re-create the relations:

    from z3c.relationfield import RelationValue
    from zc.relation.interfaces import ICatalog
    from zope.app.intid.interfaces import IIntIds
    from zope.component import getUtility
    from zope.event import notify
    from zope.lifecycleevent import ObjectModifiedEvent
    
    logger = logging.getLogger(LOGGER)
    relations_catalog = getUtility(ICatalog)
    intids = getUtility(IIntIds)
    
    relations = [rel for rel in relations_catalog.findRelations()]
    len_relations = len(relations)
    logger.info('Relations needed to update: {0}'.format(len_relations))
    
    for relation in relations:
        # get the object link and the object linked
        object_with_link = relation.from_object
        object_linked_to = relation.to_object
    
        # remove the broken relation
        object_with_link.reference = None
    
        # let the catalog remove the old relation
        notify(ObjectModifiedEvent(object_with_link))
    
        # create a new relation
        object_linked_to_intid = intids.getId(object_linked_to)
        new_relation = RelationValue(object_linked_to_intid)
        object_with_link.reference = new_relation
    
        # let the catalog know about this new relation
        notify(ObjectModifiedEvent(object_with_link))
    

    After this, stop the instance, run buildout again to update plone.directives.form to version 1.1 and voilà!

提交回复
热议问题