Commit bd156f4a authored by Jérome Perrin's avatar Jérome Perrin

TrashTool: fail if backup object container already exist

This is not supposed to happen and can hide errors.
parent 0cacb444
...@@ -80,59 +80,56 @@ class TrashTool(BaseTool): ...@@ -80,59 +80,56 @@ class TrashTool(BaseTool):
# backup the object # backup the object
# here we choose export/import to copy because cut/paste # here we choose export/import to copy because cut/paste
# do too many things and check for what we want to do # do too many things and check for what we want to do
obj = None object_path = container_path + [object_id]
if object_id not in backup_object_container.objectIds(): obj = self.unrestrictedTraverse(object_path, None)
# export object if obj is not None:
object_path = container_path + [object_id] connection = obj._p_jar
obj = self.unrestrictedTraverse(object_path, None) o = obj
if obj is not None: while connection is None:
connection = obj._p_jar o = o.aq_parent
o = obj connection=o._p_jar
while connection is None: if obj._p_oid is None:
o = o.aq_parent LOG("Trash Tool backupObject", WARNING,
connection=o._p_jar "Trying to backup uncommitted object %s" % object_path)
if obj._p_oid is None: return {}
LOG("Trash Tool backupObject", WARNING, if isinstance(obj, Broken):
"Trying to backup uncommitted object %s" % object_path) LOG("Trash Tool backupObject", WARNING,
return {} "Can't backup broken object %s" % object_path)
if isinstance(obj, Broken): klass = obj.__class__
LOG("Trash Tool backupObject", WARNING, if klass.__module__[:27] in ('Products.ERP5Type.Document.',
"Can't backup broken object %s" % object_path) 'erp5.portal_type'):
klass = obj.__class__ # meta_type is required so that a broken object
if klass.__module__[:27] in ('Products.ERP5Type.Document.', # can be removed properly from a BTreeFolder2
'erp5.portal_type'): # (unfortunately, we can only guess it)
# meta_type is required so that a broken object klass.meta_type = 'ERP5' + re.subn('(?=[A-Z])', ' ',
# can be removed properly from a BTreeFolder2 klass.__name__)[0]
# (unfortunately, we can only guess it) return {}
klass.meta_type = 'ERP5' + re.subn('(?=[A-Z])', ' ', copy = connection.exportFile(obj._p_oid)
klass.__name__)[0] # import object in trash
return {} connection = backup_object_container._p_jar
copy = connection.exportFile(obj._p_oid) o = backup_object_container
# import object in trash while connection is None:
connection = backup_object_container._p_jar o = o.aq_parent
o = backup_object_container connection=o._p_jar
while connection is None: copy.seek(0)
o = o.aq_parent try:
connection=o._p_jar backup = connection.importFile(copy)
copy.seek(0) backup.isIndexable = ConstantGetter('isIndexable', value=False)
try: # the isIndexable setting above avoids the recursion of
backup = connection.importFile(copy) # manage_afterAdd on
backup.isIndexable = ConstantGetter('isIndexable', value=False) # Products.ERP5Type.CopySupport.CopySupport.manage_afterAdd()
# the isIndexable setting above avoids the recursion of # but not on event subscribers, so we need to suppress_events,
# manage_afterAdd on # otherwise subobjects will be reindexed
# Products.ERP5Type.CopySupport.CopySupport.manage_afterAdd() backup_object_container._setObject(object_id, backup,
# but not on event subscribers, so we need to suppress_events, suppress_events=True)
# otherwise subobjects will be reindexed except (AttributeError, ImportError):
backup_object_container._setObject(object_id, backup, # XXX we can go here due to formulator because attribute
suppress_events=True) # field_added doesn't not exists on parent if it is a Trash
except (AttributeError, ImportError): # Folder and not a Form, or a module for the old object is
# XXX we can go here due to formulator because attribute # already removed, and we cannot backup the object
# field_added doesn't not exists on parent if it is a Trash LOG("Trash Tool backupObject", WARNING,
# Folder and not a Form, or a module for the old object is "Can't backup object %s" % object_path)
# already removed, and we cannot backup the object return {}
LOG("Trash Tool backupObject", WARNING,
"Can't backup object %s" % object_path)
return {}
keep_sub = kw.get('keep_subobjects', 0) keep_sub = kw.get('keep_subobjects', 0)
subobjects_dict = {} subobjects_dict = {}
......
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