Skip to content

Instantly share code, notes, and snippets.

@buchi
Created August 16, 2015 09:03
Show Gist options
  • Save buchi/af6f57fafddbb2a2545a to your computer and use it in GitHub Desktop.
Save buchi/af6f57fafddbb2a2545a to your computer and use it in GitHub Desktop.
Delete versions of deleted objects.
# setup dummy request
from Testing.makerequest import makerequest
app=makerequest(app)
plone = app.unrestrictedTraverse('/Plone')
# get user context of portal owner
from AccessControl.SecurityManagement import newSecurityManager
user = plone.getOwner()
newSecurityManager(app, user)
# set site
from zope.app.component.hooks import setSite
setSite(plone)
# setup skin
plone.setupCurrentSkin(plone.REQUEST)
from BTrees.OOBTree import OOBTree
from Products.CMFEditions.utilities import dereference
hstorage = plone.portal_historiesstorage
zvc_repo = hstorage._getZVCRepo()
shadow_storage = hstorage._getShadowStorage()._storage
stats = hstorage.zmi_getStorageStatistics()
print stats['summaries']
for hinfo in stats['deleted']:
hid = hinfo['history_id']
history = hstorage._getShadowHistory(hid)
for zvc_key in set([hstorage._getZVCAccessInfo(hid, selector, True)[0] for selector in history._available]):
version_history = zvc_repo._histories.get(zvc_key, None)
if version_history:
version_history._versions = OOBTree()
shadow_storage.pop(hid, None)
obj = dereference(history_id=hid, zodb_hook=plone)[0]
if obj and shasattr(obj, 'version_id'):
delattr(obj, 'version_id')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment