Thursday, April 12, 2007

copying a plone site

Copying sites has recently gotten a lot better since 2.5.2 fixed some bugs with modification times getting reset but still you generally can't use copy & paste to copy sites as I have found it doesn't retain the review state of your documents (and this is by design actually I think). Another approach is to import/export. This actually works great so I put together a script that will automate this process. You need to call this from either an External Method or from zopectl debug (or ipython). That's an exercise up to the reader... #
# Move a Plone site without losing the modification times and workflow status
# we rely on export/import to do this
# You need to provide a valid REQUEST so that the import doesn't fail
# if running from zopectl debug you can use makerequest to wrap your app object
# with a fake request
# Author: Jordan Baker (
import tempfile
import os

def moveSite(portal, new_location):
# export the site to a tempfile
f = tempfile.NamedTemporaryFile()
portal._p_jar.exportFile(portal._p_oid, f)
# re-import in the correct location
new_location._importObjectFromFile(f, verify=False, set_owner=False)
# delete the old site
oid =
# update the catalog in the new site
# NamedTemporaryFile should delete the underlying temporary file
# when its object is garbage collected

No comments: