diff --git a/collective/blueprint/jsonmigrator/blueprint.py b/collective/blueprint/jsonmigrator/blueprint.py index 19fe7fc..0667109 100644 --- a/collective/blueprint/jsonmigrator/blueprint.py +++ b/collective/blueprint/jsonmigrator/blueprint.py @@ -23,6 +23,16 @@ from Products.Archetypes.interfaces import IBaseObject from AccessControl.interfaces import IRoleManager +from plone.dexterity.utils import iterSchemata +from zope.schema import getFieldsInOrder + +try: + from plone.dexterity.interfaces import IDexterityContent + dexterity_available = True +except: + dexterity_available = False + + DATAFIELD = '_datafield_' STATISTICSFIELD = '_statistics_field_prefix_' @@ -111,7 +121,7 @@ class Statistics(object): def __init__(self, transmogrifier, name, options, previous): self.stats = {'START_TIME': int(time.time()), 'TIME_LAST_STEP': 0, - 'STEP': options.get('log-step', 25), + 'STEP': int(options.get('log-step', 25)), 'OBJ_COUNT': 0, 'EXISTED': 0, 'ADDED': 0, @@ -201,7 +211,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): obj.setFormat(item[mimetypekey]) yield item @@ -247,7 +257,7 @@ def __iter__(self): if obj is None or not getattr(obj, 'workflow_history', False): yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): item_tmp = item # get back datetime stamp and set the workflow history @@ -303,7 +313,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): if getattr(aq_base(obj), '_delProperty', False): for prop in item[propertieskey]: if getattr(aq_base(obj), prop[0], None) is not None: @@ -362,7 +372,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): if item[ownerkey][0] and item[ownerkey][1]: try: @@ -380,7 +390,6 @@ def __iter__(self): obj._owner = item[ownerkey][1] except Exception, e: raise Exception('ERROR: %s SETTING __OWNERSHIP TO %s' % (str(e), item[pathkey])) - yield item @@ -512,6 +521,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue + # AT if IBaseObject.providedBy(obj): for key in item.keys(): if not key.startswith(self.datafield_prefix): @@ -527,4 +537,34 @@ def __iter__(self): if len(value) != len(field.get(obj)): field.set(obj, value) + # dexterity + if dexterity_available and IDexterityContent.providedBy(obj): + for key in item.keys(): + if not key.startswith(self.datafield_prefix): + continue + if not os.path.exists(item[key]): + continue + + fieldname = key[len(self.datafield_prefix):] + f = open(item[key]) + value = f.read() + f.close() + + filename = item['id'].decode('utf-8') + contenttype = '' + + #get all fields for this obj + for schemata in iterSchemata(obj): + for name, field in getFieldsInOrder(schemata): + if field.__name__ == fieldname: + # create a blob instance + instance = field._type( + data=value, + filename=filename, + contentType=contenttype, + ) + # set it + field.set(field.interface(obj), instance) + continue + yield item