Created
September 26, 2013 19:55
-
-
Save toutpt/6719656 to your computer and use it in GitHub Desktop.
Script to migrate FSS to blob. You have to write an uprade step and put this code inside. Most of the time you need to adapt it to your project / content types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def upgrade_fss2attr_storage(portal_setup): | |
"""We use fss on plone3, so we need first to come back to default | |
plone so the migration of plone will next do the job to go on blob""" | |
site = portal_setup.aq_parent | |
#fss2attributestorage | |
from cStringIO import StringIO | |
from Products.Archetypes.Storage import AttributeStorage | |
from iw.fss.FileSystemStorage import FileSystemStorage | |
# attr_storage = AttributeStorage() | |
fss_storage = FileSystemStorage() | |
catalog = getToolByName(site, 'portal_catalog') | |
brains = catalog(portal_type="File") | |
files = [b.getObject() for b in brains] | |
brains = catalog(portal_type="Image") | |
images = [b.getObject() for b in brains] | |
def migrateFile(f): | |
field = f.Schema()['file'] | |
content = StringIO(str(fss_storage.get('file', f))) | |
fss_storage.unset('file', f) | |
field.set(f, content) | |
def migrateImage(img): | |
field = img.Schema()['image'] | |
try: | |
content = StringIO(str(fss_storage.get('image', img))) | |
except AttributeError: | |
logger.error('img %s has no image attribute'%img) | |
return | |
fss_storage.unset('image', img) | |
field.set(img, content) | |
for f in files: | |
migrateFile(f) | |
for img in images: | |
migrateImage(img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment