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

后端 未结 4 2115
既然无缘
既然无缘 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:07

    In case someone runs into this type of problem and cannot bring the old package back, here's another approach:

    import transaction
    
    from AccessControl.SecurityManagement import newSecurityManager
    from AccessControl.User import system
    
    from Testing.makerequest import makerequest
    
    from zope.component.hooks import setSite
    from zope.globalrequest import setRequest
    
    from zc.relation.interfaces import ICatalog
    from z3c.relationfield.event import _relations
    from z3c.relationfield.event import _setRelation
    from zope.component import getUtility
    
    app = makerequest(app)
    newSecurityManager(None, system)
    portal = app.Plone
    setSite(portal)
    portal.REQUEST['PARENTS'] = [portal]
    portal.REQUEST.setVirtualRoot('/')
    setRequest(portal.REQUEST)
    
    THRESHOLD = 100
    
    relations_catalog = getUtility(ICatalog)
    
    paths = ['/'.join(r.from_object.getPhysicalPath())
             for r in relations_catalog.findRelations() if r.from_object]
    
    relations_catalog.clear()
    
    counter = 0
    for path in paths:
        obj = app.unrestrictedTraverse(path)
        for name, relation in _relations(obj):
            _setRelation(obj, name, relation)
        counter += 1
        if counter % THRESHOLD == 0:
            transaction.savepoint()
    transaction.commit()
    

提交回复
热议问题