How to retain UUID when migrating content type?

Similar migration situation here: we iterate over the content of some old site and recreate new items on the target system through plone.restapi. New content is - of course - created with new UIDs, links using resolveuid/<uid> don't work.

For each new object create we call a browser view on the target system calling

   setattr(self.context, '_plone.uuid', old_uid)
   self.context.reindexObject(idxs=['UID'])

self.context is the target object which usually has the same path then the original object - so addressing a related browser view should be easy.

Complete code:

    def setuid(self, uid):
        """ Set given `uid` on current context object """
        from plone.protect.interfaces import IDisableCSRFProtection
        from zope.interface import alsoProvides

        alsoProvides(self.request, IDisableCSRFProtection)
        setattr(self.context, '_plone.uuid', uid)
        self.context.reindexObject(idxs=['UID'])
        self.request.response.setStatus(200)
4 Likes