Commit b9839738 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Make sure that erp5.component modules are reset on all ZEO clients.

parent 13908ec0
......@@ -46,14 +46,19 @@ class ComponentTool(BaseTool):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
def reset(self):
def reset(self, is_sync=False):
"""
XXX-arnau: global reset
"""
import erp5.component
container_type_info = self.getPortalObject().portal_types.getTypeInfo(
self.getPortalType())
portal = self.getPortalObject()
if not is_sync:
portal.newCacheCookie('component_classes')
erp5.component._last_reset = portal.getCacheCookie('component_classes')
container_type_info = portal.portal_types.getTypeInfo(self.getPortalType())
for content_type in container_type_info.getTypeAllowedContentTypeList():
module_name = content_type.split(' ')[0].lower()
......
......@@ -26,12 +26,39 @@
#
##############################################################################
from Products.ERP5.ERP5Site import getSite
from types import ModuleType
class ComponentModule(ModuleType):
_resetting = False
_last_reset = -1
def __getattribute__(self, name):
"""
Synchronize between ZEO clients
XXX-arnau: surely bad from a performance POV and not thread-safe
"""
if name[0] == '_' or self._resetting:
return super(ComponentModule, self).__getattribute__(name)
import erp5.component
site = getSite()
cookie = site.getCacheCookie('component_classes')
if self._last_reset == -1:
self._last_reset = site.getCacheCookie('component_classes')
elif cookie != self._last_reset:
self._resetting = True
site.portal_components.reset(is_sync=True)
self._resetting = False
return super(ComponentModule, self).__getattribute__(name)
from types import ModuleType
from zLOG import LOG, INFO
def generateComponentClassWrapper(namespace):
def generateComponentClass(component_name):
from Products.ERP5.ERP5Site import getSite
site = getSite()
component_id = '%s.%s' % (namespace, component_name)
......
......@@ -122,10 +122,11 @@ def initializeDynamicModules():
loadTempPortalTypeClass)
# Components
erp5.component = ModuleType("erp5.component")
from component_class import ComponentModule, generateComponentClassWrapper
erp5.component = ComponentModule("erp5.component")
sys.modules["erp5.component"] = erp5.component
from component_class import generateComponentClassWrapper
erp5.component.extension = registerDynamicModule(
'erp5.component.extension',
generateComponentClassWrapper('erp5.component.extension'))
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