Last active
August 29, 2015 14:19
-
-
Save jone/00ab50abcb0213ec7621 to your computer and use it in GitHub Desktop.
Plone: Remove versions of deleted objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from AccessControl.SecurityManagement import newSecurityManager | |
from pprint import pprint | |
from Products.CMFCore.utils import getToolByName | |
from Products.CMFPlone.interfaces import IPloneSiteRoot | |
from Testing.makerequest import makerequest | |
from zope.app.component.hooks import setSite | |
app = globals()['app'] | |
user = None | |
while not user: | |
user = app.acl_users.getUser(raw_input('Admin user ID (Zope level): ').strip()) | |
user = user.__of__(app.acl_users) | |
newSecurityManager(app, user) | |
app = makerequest(app) | |
overview_view = app.restrictedTraverse('plone-overview') | |
print 'SITES:' | |
for site in overview_view.sites(): | |
print '-', '/'.join(site.getPhysicalPath()) | |
while True: | |
site_path = raw_input('Path to Plone site to update: ').strip().strip('/') | |
try: | |
site = app.restrictedTraverse(site_path) | |
except Exception, exc: | |
print 'ERROR:', exc | |
else: | |
print 'FOUND:', site | |
if not IPloneSiteRoot.providedBy(site): | |
print 'ERROR: not a Plone site:', site | |
else: | |
break | |
setSite(site) | |
historiesstorage = getToolByName(site, 'portal_historiesstorage') | |
hidhandler = getToolByName(site, "portal_historyidhandler") | |
shadowstorage = historiesstorage._getShadowStorage()._storage | |
versions_repo = historiesstorage._getZVCRepo() | |
print 'Gathering statistics..' | |
statistics = historiesstorage.zmi_getStorageStatistics() | |
pprint(statistics['summaries']) | |
print '' | |
print 'Deleting', statistics['summaries']['deletedHistories'], 'histories', \ | |
'and', statistics['summaries']['deletedVersions'], 'versions.' | |
for historyinfo in statistics['deleted']: | |
history_id = historyinfo['history_id'] | |
history = historiesstorage._getShadowHistory(history_id) | |
for zvc_key in set([ | |
historiesstorage._getZVCAccessInfo(history_id, selector, True)[0] | |
for selector in history._available]): | |
if zvc_key in versions_repo._histories: | |
del versions_repo._histories[zvc_key] | |
shadowstorage.pop(history_id, None) | |
import transaction | |
transaction.commit() | |
print 'All done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@buchi thanks, updated 😉