A customer had instantiated a portlet on its homepage. He then made several changes that got saved in version history.
Later, the add-on that provided the portlet was uninstalled from the site.
When saving that page, the user would obviously get a broken object error.
To fix this issue, it was necessary to both remove the broken portlet on the given page and to delete (purge) all CMFEditions versions of that page that were holding an instance of the broken portlet.
While the former was easy (just use manage portlets page to remove the portlet), the latter took me much more time.
I document how I did it for anyone that might need to do something similar.
Through instance debug
, I was able to find which versions were broken with a loop like:
>>> for i in range(my_page.version_id): ... print i ... portal_repository.isUpToDate(my_page, i)
I purged the given versions with:
>>> from Products.CMFEditions.utilities import dereference >>> dereference(my_page) (<ATDocument at /Plone/my_page>, 1) >>> for i in range(77,15,-1): ... portal_historiesstorage.purge(1, i, metadata={'sys_metadata': {'comment':'purge version with broken portlet'}}, countPurged=False)
I also had to update the version_id before comitting:
>>> from transaction import commit >>> my_page.version_id = 15 >>> commit()