Commit 31fa6ce6 authored by Aurel's avatar Aurel

remove light install in installation of categories so that uid are always preserved

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9967 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 54a199c3
...@@ -863,68 +863,66 @@ class CategoryTemplateItem(ObjectTemplateItem): ...@@ -863,68 +863,66 @@ class CategoryTemplateItem(ObjectTemplateItem):
self._objects[relative_url] = obj self._objects[relative_url] = obj
obj.wl_clearLocks() obj.wl_clearLocks()
def install(self, context, trashbin, light_install = 0, **kw): def install(self, context, trashbin, **kw):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
if context.getTemplateFormatVersion() == 1: if context.getTemplateFormatVersion() == 1:
if light_install == 0: portal = context.getPortalObject()
ObjectTemplateItem.install(self, context, trashbin, **kw) category_tool = portal.portal_categories
else: tool_id = self.tool_id
portal = context.getPortalObject() keys = self._objects.keys()
category_tool = portal.portal_categories keys.sort()
tool_id = self.tool_id for path in keys:
keys = self._objects.keys() if update_dict.has_key(path) or force:
keys.sort() if not force:
for path in keys: action = update_dict[path]
if update_dict.has_key(path) or force: if action == 'nothing':
if not force: continue
action = update_dict[path] else:
if action == 'nothing': action = 'backup'
# Wrap the object by an aquisition wrapper for _aq_dynamic.
obj = self._objects[path]
obj = obj.__of__(category_tool)
container_path = path.split('/')[:-1]
category_id = path.split('/')[-1]
try:
container = category_tool.unrestrictedTraverse(container_path)
except KeyError:
# parent object can be set to nothing, in this case just go on
container_url = '/'.join(container_path)
if update_dict.has_key(container_url):
if update_dict[container_url] == 'nothing':
continue continue
else: raise
action = 'backup' container_ids = container.objectIds()
# Wrap the object by an aquisition wrapper for _aq_dynamic. # Object already exists
obj = self._objects[path] object_uid = None
obj = obj.__of__(category_tool) subobjects_dict = {}
container_path = path.split('/')[:-1] if category_id in container_ids:
category_id = path.split('/')[-1] object_uid = container[category_id].getUid()
try: subobjects_dict = self._backupObject(action, trashbin, container_path, category_id)
container = category_tool.unrestrictedTraverse(container_path) container.manage_delObjects([category_id])
except KeyError: category = container.newContent(portal_type=obj.getPortalType(), id=category_id)
# parent object can be set to nothing, in this case just go on if object_uid is not None:
container_url = '/'.join(container_path) category.setUid(object_uid)
if update_dict.has_key(container_url): for property in obj.propertyIds():
if update_dict[container_url] == 'nothing': if property not in ('id', 'uid'):
continue category.setProperty(property, obj.getProperty(property, evaluate=0))
raise # import sub objects if there is
container_ids = container.objectIds() if len(subobjects_dict) > 0:
# Object already exists # get a jar
object_uid = None connection = obj._p_jar
if category_id in container_ids: o = category
object_uid = container[category_id].getUid() while connection is None:
subobjects_dict = self._backupObject(action, trashbin, container_path, category_id) o = o.aq_parent
container.manage_delObjects([category_id]) connection = o._p_jar
category = container.newContent(portal_type=obj.getPortalType(), id=category_id) # import subobjects
if object_uid is not None: for subobject_id in subobjects_dict.keys():
category.setUid(object_uid) subobject_data = subobjects_dict[subobject_id]
for property in obj.propertyIds(): subobject_data.seek(0)
if property not in ('id', 'uid'): subobject = connection.importFile(subobject_data)
category.setProperty(property, obj.getProperty(property, evaluate=0)) if subobject_id not in category.objectIds():
# import sub objects if there is category._setObject(subobject_id, subobject)
if len(subobjects_dict) > 0:
# get a jar
connection = obj._p_jar
o = category
while connection is None:
o = o.aq_parent
connection = o._p_jar
# import subobjects
for subobject_id in subobjects_dict.keys():
subobject_data = subobjects_dict[subobject_id]
subobject_data.seek(0)
subobject = connection.importFile(subobject_data)
if subobject_id not in category.objectIds():
category._setObject(subobject_id, subobject)
else: else:
BaseTemplateItem.install(self, context, trashbin, **kw) BaseTemplateItem.install(self, context, trashbin, **kw)
portal = context.getPortalObject() portal = context.getPortalObject()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment