Commit 5f463ae1 authored by Julien Muchembled's avatar Julien Muchembled

Fix changeObjectClass for migration of Files to Embedded Files

- Use _[ds]etOb instead of _[ds]etObject and unindex old object only if
  required. This improves performance and workarounds a bug documented in
  test_02_unindexObjectDependency.
- Automatically fix 'portal_type' attribute if required.
parent 17011b4d
......@@ -40,5 +40,4 @@ def migrateToEmbeddedFile(self, force=0):
id = self.id
if force == 1:
changeObjectClass(container, id, getattr(erp5.portal_type, embedded_type))
container._getOb(id).portal_type = embedded_type
return '%s: %s -> %s' % (self.getRelativeUrl(), portal_type, embedded_type),
988
\ No newline at end of file
989
\ No newline at end of file
......@@ -19,11 +19,24 @@ def changeObjectClass(self, object_id, new_class):
"""Creates a copy of object_id inside self, changing its class to
new_class"""
old_obj = self._getOb(object_id)
self._delObject(object_id)
self._delOb(object_id)
new_obj = new_class(object_id)
new_obj.__dict__.update(old_obj.__dict__)
self._setObject(object_id, new_obj)
if new_class.__module__ == 'erp5.portal_type':
new_obj.portal_type = new_class.__name__
self._setOb(object_id, new_obj)
if self._delOb.__module__ == 'OFS.ObjectManager':
# Workaround OFS updating '_objects' in _[ds]etObject instead of _[ds]etOb
for i in self._objects:
if i['id'] == object_id:
i['meta_type'] = getattr(new_obj, 'meta_type', None)
break
new_obj = self._getOb(object_id, new_obj)
if new_obj.isIndexable:
new_obj.reindexObject()
else:
old_obj.unindexObject()
return new_obj
def updateBalanceTransactionClass(self):
"""Update Balance Transactions new indexing that occured around r16371
......
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