Commit ee1a4d70 authored by Julien Muchembled's avatar Julien Muchembled

BusinessTemplate: remove dead code

This reverts most fixes to r28422. They are not useful anymore since objects
are not modified anymore during download.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38633 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 06a327f0
...@@ -4852,42 +4852,22 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -4852,42 +4852,22 @@ Business Template is a set of definitions, such as skins, portal types and categ
# Create temporary modules/classes for classes defined by this BT. # Create temporary modules/classes for classes defined by this BT.
# This is required if the BT contains instances of one of these classes. # This is required if the BT contains instances of one of these classes.
orig_module_dict = {} module_id_list = []
instance_oid_list = []
for template_id in self.getTemplateDocumentIdList(): for template_id in self.getTemplateDocumentIdList():
module_id = 'Products.ERP5Type.Document.' + template_id module_id = 'Products.ERP5Type.Document.' + template_id
orig_module_dict[module_id] = sys.modules.get(module_id) if module_id not in sys.modules:
# Always redefine the module, so that 'instance_oid_list' contains module_id_list.append(module_id)
# the full list of oid to remove from pickle cache.
sys.modules[module_id] = module = imp.new_module(module_id) sys.modules[module_id] = module = imp.new_module(module_id)
module.SimpleItem = SimpleItem.SimpleItem setattr(module, template_id, type(template_id,
module.instance_oid_list = instance_oid_list (SimpleItem.SimpleItem,), {'__module__': module_id}))
exec """class %s(SimpleItem):
def __setstate__(self, state):
instance_oid_list.append(self._p_oid)
return SimpleItem.__setstate__(self, state)""" % template_id \
in module.__dict__
for item_name in self._item_name_list: for item_name in self._item_name_list:
getattr(self, item_name).importFile(bta) getattr(self, item_name).importFile(bta)
if instance_oid_list:
# If a temporary class was used, we must force all instances using it
# to be reloaded (i.e. unpickle) on next access (at installation).
# Doing a savepoint will pickle them to a temporary storage so that all
# references to it can be freed.
transaction.savepoint(optimistic=True)
self._p_jar.cacheMinimize()
gc.collect()
# Remove temporary modules created above to allow import of real modules # Remove temporary modules created above to allow import of real modules
# (during the installation). # (during the installation).
# Restore original module if any, in case the new one is not installed. for module_id in module_id_list:
for module_id, module in orig_module_dict.iteritems():
if module is None:
del sys.modules[module_id] del sys.modules[module_id]
else:
sys.modules[module_id] = module
def getItemsList(self): def getItemsList(self):
"""Return list of items in business template """Return list of items in business template
......
...@@ -6630,12 +6630,15 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -6630,12 +6630,15 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
sequence_list.play(self, quiet=quiet) sequence_list.play(self, quiet=quiet)
def test_167_InstanceAndRelatedClassDefinedInSameBT(self): def test_167_InstanceAndRelatedClassDefinedInSameBT(self):
# This test does too much since we don't modify objects anymore during
# download. Objects are cleaned up during installation, which does not
# require any specific action about garbage collection or pickle cache.
from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem from Products.ERP5Type.Document.BusinessTemplate import BaseTemplateItem
portal = self.portal portal = self.portal
BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties BaseTemplateItem_removeProperties = BaseTemplateItem.removeProperties
marker_list = [] marker_list = []
def removeProperties(self, obj, export): def removeProperties(self, obj, export):
# Check it works if the object is modified during download. # Check it works if the object is modified during install.
obj.int_index = marker_list.pop() obj.int_index = marker_list.pop()
return obj return obj
SimpleItem_getCopy = SimpleItem._getCopy SimpleItem_getCopy = SimpleItem._getCopy
...@@ -6655,15 +6658,16 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor): ...@@ -6655,15 +6658,16 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
del self.logged[:] del self.logged[:]
# check its class has not yet been overriden # check its class has not yet been overriden
self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False)) self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False))
for i in xrange(6): for i in (0, 1):
marker_list.append(i) marker_list.append(i)
gc.disable() gc.disable()
bt = template_tool.download(bt_path) bt = template_tool.download(bt_path)
assert not marker_list assert marker_list
if i in (2, 4, 5): if i:
transaction.commit() transaction.commit()
self.tic() self.tic()
bt.install(force=1) bt.install(force=1)
assert not marker_list
gc.enable() gc.enable()
self.assertEqual(portal.some_file.int_index, i) self.assertEqual(portal.some_file.int_index, i)
transaction.commit() transaction.commit()
......
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