Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purging all old CMFEditions versions

Tags:

plone

We have big huge site which database should be prepared for development copies.

How one can remove all old history versions of all content items? This way we could greatly reduce the size of data needed to transfer to developer computers.

Plone 4.0

like image 727
Mikko Ohtamaa Avatar asked Mar 13 '12 11:03

Mikko Ohtamaa


1 Answers

  1. Go to portal_purgepolicy and set the number to some number (I usually use '3' to keep at least some history).
  2. Run the following script:

    from DateTime import DateTime
    from Products.CMFCore.utils import getToolByName
    from Products.CMFEditions.utilities import dereference
    
    
    policy = getToolByName(self.context, 'portal_purgepolicy')
    catalog = getToolByName(self.context, 'portal_catalog')
    
    for count, brain in enumerate(catalog()):
        obj = brain.getObject()
    
        # only purge old content
        if obj.created() < (DateTime() - 30):
            obj, history_id = dereference(obj)
            policy.beforeSaveHook(history_id, obj)
            print 'purged object ' + obj.absolute_url_path()
    
like image 130
zupo Avatar answered Sep 28 '22 10:09

zupo