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).<br /><br />Another approach is to import/export. This actually works great so I put together a script that will automate this process.<br /><br />You need to call this from either an External Method or from zopectl debug (or ipython). That’s an exercise up to the reader…<br /><br /># moveSites.py<br /><pre># Move a Plone site without losing the modification times and workflow status<br /># we rely on export/import to do this<br /># You need to provide a valid REQUEST so that the import doesn’t fail<br /># if running from zopectl debug you can use makerequest to wrap your app object<br /># with a fake request<br /># Author: Jordan Baker (jbbNOASPM@scryent.com)<br />import tempfile<br />import os<br /><br />def moveSite(portal, new_location):<br /># export the site to a tempfile<br />f = tempfile.NamedTemporaryFile()<br />portal._p_jar.exportFile(portal._p_oid, f)<br /># re-import in the correct location<br />f.seek(0)<br />new_location._importObjectFromFile(f, verify=False, set_owner=False)<br /># delete the old site<br />oid = portal.id<br />portal.aq_parent.manage_delObjects(ids=[oid])<br /># update the catalog in the new site<br />new_location[oid].portal_catalog.refreshCatalog(clear=True)<br /># NamedTemporaryFile should delete the underlying temporary file<br /># when its object is garbage collected<br /></pre>
Jordan Baker: copying a plone site
Originally from Planet Plone by