Commit 124b1619 authored by Julien Muchembled's avatar Julien Muchembled

Make sure automatic migration of core tools does not modify ZODB when if fails

parent 5b8ec677
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import sys import sys
import os import os
import inspect import inspect
import transaction
from types import ModuleType from types import ModuleType
from Products.ERP5Type.dynamic.dynamic_module import registerDynamicModule from Products.ERP5Type.dynamic.dynamic_module import registerDynamicModule
...@@ -42,7 +43,7 @@ from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderModuleType, ...@@ -42,7 +43,7 @@ from Products.ERP5Type.dynamic.accessor_holder import AccessorHolderModuleType,
createAllAccessorHolderList createAllAccessorHolderList
from Products.ERP5Type.TransactionalVariable import TransactionalResource from Products.ERP5Type.TransactionalVariable import TransactionalResource
from zLOG import LOG, ERROR, INFO, WARNING from zLOG import LOG, ERROR, INFO, WARNING, PANIC
def _importClass(classpath): def _importClass(classpath):
try: try:
...@@ -346,32 +347,40 @@ def synchronizeDynamicModules(context, force=False): ...@@ -346,32 +347,40 @@ def synchronizeDynamicModules(context, force=False):
migrate = False migrate = False
from Products.ERP5Type.Tool.PropertySheetTool import PropertySheetTool from Products.ERP5Type.Tool.PropertySheetTool import PropertySheetTool
from Products.ERP5Type.Tool.TypesTool import TypesTool from Products.ERP5Type.Tool.TypesTool import TypesTool
for tool_class in TypesTool, PropertySheetTool: try:
# if the instance has no property sheet tool, or incomplete for tool_class in TypesTool, PropertySheetTool:
# property sheets, we need to import some data to bootstrap # if the instance has no property sheet tool, or incomplete
# (only likely to happen on the first run ever) # property sheets, we need to import some data to bootstrap
tool_id = tool_class.id # (only likely to happen on the first run ever)
tool = getattr(portal, tool_id, None) tool_id = tool_class.id
if tool is None: tool = getattr(portal, tool_id, None)
tool = tool_class() if tool is None:
portal._setObject(tool_id, tool, set_owner=False, suppress_events=True) tool = tool_class()
tool = getattr(portal, tool_id) portal._setObject(tool_id, tool, set_owner=False,
elif tool._isBootstrapRequired(): suppress_events=True)
migrate = True tool = getattr(portal, tool_id)
elif tool._isBootstrapRequired():
migrate = True
else:
continue
tool._bootstrap()
tool.__class__ = getattr(erp5.portal_type, tool.portal_type)
if migrate:
portal.migrateToPortalTypeClass()
portal.portal_skins.changeSkin(None)
TransactionalResource(tpc_finish=lambda txn:
_bootstrapped.add(portal.id))
LOG('ERP5Site', INFO, 'Transition successful, please update your'
' business templates')
else: else:
continue _bootstrapped.add(portal.id)
tool._bootstrap() except:
tool.__class__ = getattr(erp5.portal_type, tool.portal_type) # Required because the exception may be silently dropped by the caller.
transaction.doom()
if migrate: LOG('ERP5Site', PANIC, "Automatic migration of type and"
portal.migrateToPortalTypeClass() " property sheet tool failed", error=sys.exc_info())
portal.portal_skins.changeSkin(None) raise
TransactionalResource(tpc_finish=lambda txn:
_bootstrapped.add(portal.id))
LOG('ERP5Site', INFO, 'Transition successful, please update your'
' business templates')
else:
_bootstrapped.add(portal.id)
LOG("ERP5Type.dynamic", 0, "Resetting dynamic classes") LOG("ERP5Type.dynamic", 0, "Resetting dynamic classes")
try: try:
......
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