How to retain UUID when migrating content type?

I have multiple document objects that I want to migrate into their own schemas. Currently “fields” are denoted by using HTML headings. So it is clear the unique schemas that should exist along with values for those fields based on layout. I will be parsing each of the major headings as a field and all of the information between that and the next heading as the values. I have done this before, and it is fairly trivial, but now I have a need to keep the UUIDs since many secondary and tertiary target systems use these as lookups. Additionally I would like not to have to transform hyperlink and image UID references. I had considered keeping them as Document but adding fields via behaviors, but that seemed like an inappropriate solution because it would forsake all the value of the content type system. Additionally the fields provided by the behaviors would be mutually exclusive and I know I’d find myself working against the grain. Is there an easy and reliable way to migrate content types while retaining the UUID on the new object?

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)
3 Likes

Thanks for the information. I had no idea that it would be that easy. I guess then the UID is just like any other field and wouldn't suffer side effects since anything that references the new object SHOULD also be conveyed.

I did not notice any side effects during various migrations.

1 Like

Plone Foundation Code of Conduct