Attention

This document was written for an old version of Plone, Plone 3, and was last updated 902 days ago.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Dump the workflow states

by John Samuel Anderson last modified Dec 03, 2009 03:42 AM
Query the portal_catalog and write simple text files with the original workflow states for each item.

Thankfully, I have lots of backups. Even better, I have a QA server, which has a pretty recent snapshot from Production.  If I can see what states the items had before I messed them up, then I could reset the ones that are wrong.  (If it's too many to do manually, I can always hack a python script, right?)

I tried several different approaches.  This one actually worked:

def dump_catalog_by_state():
    #Import stuff and set up environment.
    from Products.CMFCore.utils import getToolByName
    from AccessControl.SecurityManagement import newSecurityManager
    from Products.CMFCore.tests.base.security import OmnipotentUser
    admin = OmnipotentUser()
    newSecurityManager(None, admin)
    OUTPUT_PATH = '/var/tmp/dump/'
    #Now do it.
    print "Getting list of plone sites...",
    #getPloneSites is our own custom Script python.
    #You could give it a list of site objects, I suppose.
    sites = app.getPloneSites() 
    print "Found %s site(s)." % len(sites)
    for site in sites:
        catalog = getToolByName(site, 'portal_catalog')
        states = ['open', 'pending', 'private', 'restricted', ]
        for state in states:
            print "Querying '%s' catalog for items in the '%s' state" % (site.id, state),
            items = catalog({'review_state': state})
            print "Found %s item(s)." % len(items)
            urls = [item.getPath() + '\n' for item in items]
            #Dump to file.
            filename = "%s%s-%s" % (OUTPUT_PATH, site.id, state)
            print "Dumping to %s" % filename,
            dump = file(filename, "w")
            dump.writelines(urls)
            dump.close()
            print "Dumped."

I copied-and-pasted this function into the debug shell (bin/instance debug) and ran it.  Out came a lot of text files!  This is exactly the information I needed.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.