Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Initial patch for split data fs
Browse files Browse the repository at this point in the history
  • Loading branch information
John Carr committed Oct 2, 2012
1 parent 4d69b14 commit 8de5b05
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
0.0.14 (unreleased)
-------------------

- Nothing changed yet.
- Automatic migration to split Data.fs when mount points are declared in zope.conf


0.0.13 (2011-09-29)
Expand Down
78 changes: 75 additions & 3 deletions isotoma/recipe/plonetools/plonesite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,78 @@

from Products.CMFPlone.utils import getFSVersionTuple

from Products.ZODBMountPoint.MountedObject import manage_addMounts
from Products.ZODBMountPoint.MountedObject import manage_getMountStatus
from Products.ZODBMountPoint.MountedObject import manage_addMounts, \
manage_getMountStatus, setMountPoint, MountedObject, CustomTrailblazer

from Products.SiteAccess.AccessRule import manage_addAccessRule, getAccessRule
from Products.SiteAccess.SiteRoot import manage_addSiteRoot

import tempfile
from App.config import getConfiguration


def migrate_mount_points(portal):
# Based on a script by Andrew Mleczko
# http://plone.org/documentation/kb/migrating-an-existing-catalog-in-a-new-zodb

_MARKER = "MARK"

for mp in manage_getMountStatus(portal):
if not '** Something is in the way **' in mp['status']:
continue

print "Migrating '%s' to seperate ZODB storage" % mp['path']

path = mp['path']
id = path.split("/")[-1]

# Existing objects
old_obj = portal.unrestrictedTraverse(path)
old_parent = old_obj.aq_parent.aq_base

# New storage from the item
db_name = mp['name']
db = getConfiguration().dbtab.getDatabase(path)
new_trans = db.open()

# Try to get the root of the new storage
root_dict = new_trans.root()
if not root_dict.has_key('Application'):
from OFS.Application import Application
root_dict['Application'] = Application()
transaction.savepoint(optimistic=True)

# Verify there nothing in the way
root = root_dict['Application']
if root.get(id, _MARKER) is not _MARKER:
root.manage_delObjects([id])

print " Exporting current state..."
f=tempfile.TemporaryFile()
old_obj._p_jar.exportFile(old_obj._p_oid,f)
f.seek(0)

print " Importing into new external ZODB storage..."
new_obj = root._p_jar.importFile(f)
f.close()
transaction.savepoint(optimistic=True)

print " Set the new object in the new storage..."
blazer = CustomTrailblazer(root)
obj = blazer.traverseOrConstruct(path)
obj.aq_parent._setOb(id, new_obj)

print " Activating the new external storage..."
mo = MountedObject(path)
mo._create_mount_points = True

old_parent._p_jar.add(mo)
old_parent._setOb(id, mo)
setMountPoint(old_parent, id, mo)

transaction.savepoint(optimistic=True)


try:
import json
except ImportError:
Expand Down Expand Up @@ -179,10 +245,14 @@ def create(self, app, site_id, products_initial, profiles_initial, site_replace)
if not pre_plone3:
setSite(plone)

migrate_mount_points(plone)
transaction.commit()

if plone:
self.quickinstall(plone, products_initial)
# run GS profiles
# run GS profiles
self.runProfiles(plone, profiles_initial)

print "Finished"

def retryable(self, error_type, error):
Expand Down Expand Up @@ -345,6 +415,8 @@ def run(self, app):
if not pre_plone3:
setSite(portal)

migrate_mount_points(portal)

def runExtras(portal, script_path):
if not os.path.exists(script_path):
msg = 'The path to the extras script does not exist: %s'
Expand Down

0 comments on commit 8de5b05

Please sign in to comment.