The most important thing to realize is that this will not update any
existing objects in the database. Only new objects will have the new class.
If you need to switch old objects, you'll need to write a migration.
I found an issue.
When you del object it runs also handlers which subscribed on remove events, in my case it runs event from p.a.discussion to clean comments.
I installed the collective.folderishtypes addon, and it works fine when creating new items.
Now I'd like to convert all events to folderish events. I can't find a solution.
I seeking help to debug this script that I run from a Plone debug console (running iPython):
from plone import api
from Products.CMFCore.utils import getToolByName
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2Base
from collective.folderishtypes.dx.content import FolderishEvent
import transaction
portal = api.portal.get()
catalog = getToolByName(portal, 'portal_catalog')
brains = portal.portal_catalog(portal_type='Event')
for brain in brains:
obj = brain.getObject()
if obj.__class__ == FolderishEvent and obj.meta_type == 'Dexterity Container' : continue
obj_id = obj.getId()
parent = obj.__parent__
parent._delOb(obj_id)
obj.__class__ = FolderishEvent
obj.meta_type = 'Dexterity Container'
parent._setOb(obj_id, obj)
BTreeFolder2Base._initBTrees(obj)
transaction.commit()
obj.reindexObject(idxs=['is_folderish', 'object_provides', ])
transaction.commit()
url = obj.absolute_url()
print(f"{obj_id} = {obj.__class__}, {obj.portal_type}, {url}")
break
I run it a few times to convert a few events, then I run the plone instance to check if the events were successfully converted to folderish events (appending /folder_content to the url of converted events). I get error pages that says " This page does not seem to exist…"
Why??
Edit: I gave up and used another method:
exported the site to json files (using collective.jsonify)
deleted all events and news
re-imported all of them from json files (with collective.transmogrifier)