Due to copying items (with ims.zip), I have some objects with spaces in their ids. For some reason, I am not able to change the ids of folders from a script. If I run this script twice, brain.id is still 'some thing' instead of 'some-thing'. obj.id is (correct) 'some-thing', but even clearing and rebuilding the catalog does not seem to work.
Are there any other (better) ways of doing this, should I use plone.api.rename or something similar instead?
(PS: the content was originally added on another instance (but with same versions/add-ons)
#python 3 #from plone.indexer import indexer from zope.component.hooks import setSite from zope.lifecycleevent import modified import transaction setSite(app['mysite']) brains = app.mysite.portal_catalog(portal_type="Folder") if brains: print('Total objects: ') print(len(brains)) for brain in brains: if ' ' in brain.id: obj = brain.getObject() ide = obj.id.replace(' ', '-') print(ide) obj.id = ide #update don't use this api.content.rename(obj=obj, new_id=ide) #update, use this #tried all combinations of this #obj.reindexObject(idxs=['id']) #obj.reindexObject(idxs=['getId']) #obj.reindexObject() #obj.reindexObject(idxs=['modified']) obj.reindexObject() #and this outside of loop (and also inside, #just to be sure) transaction.commit()