Commit 0352d59a authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

ERP5Site: register missing tools

... so that queryUtility can later access the correct ones.

Note: we do not necessarily want to register all tools.
parent be149829
......@@ -15,6 +15,7 @@
Portal class
"""
from six.moves import map
import threading
from weakref import ref as weakref
from OFS.Application import Application, AppInitializer
......@@ -36,7 +37,8 @@ from Products.ERP5Type.ERP5Type import ERP5TypeInformation
from Products.ERP5Type.Log import log as unrestrictedLog
from Products.CMFActivity.Errors import ActivityPendingError
import ERP5Defaults
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.TransactionalVariable import \
getTransactionalVariable, TransactionalResource
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from zLOG import LOG, INFO, WARNING, ERROR
......@@ -226,6 +228,7 @@ class _site(threading.local):
getSite, setSite = _site()
_missing_tools_registered = None
class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
"""
......@@ -324,7 +327,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
from Products.Localizer.MessageCatalog import (
message_catalog_alias_sources
)
sm = self.getSiteManager()
sm = self._components
for message_catalog in self.Localizer.objectValues():
sm.registerUtility(message_catalog,
provided=ITranslationDomain,
......@@ -334,21 +337,26 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
provided=ITranslationDomain,
name=alias)
def _doInitialSiteManagerMigration(self):
self._createInitialSiteManager()
# Now that we have a sitemanager, se can do things that require
# one. Including setting up ZTK style utilities and adapters. We
# can even call setSite(self), as long as we roll back that later,
# since we are actually in the middle of a setSite() call.
from zope.site.hooks import getSite, setSite
old_site = getSite()
try:
setSite(self)
# setSite(self) is not really necessary for the migration below, but
# could be needed by other migrations to be added here.
self._doTranslationDomainRegistration()
finally:
setSite(old_site)
def _registerMissingTools(self):
from Products.CMFCore import interfaces, utils
tool_id_list = ("portal_skins", "portal_types", "portal_membership",
"portal_url", "portal_workflow")
if (None in map(self.get, tool_id_list) or not
TransactionalResource.registerOnce(__name__, 'site_manager', self.id)):
return
sm = self._components
for tool_id in tool_id_list:
tool = self[tool_id]
tool_interface = utils._tool_interface_registry.get(tool_id)
if tool_interface is not None:
# Note: already registered tools will be either:
# - updated
# - registered again after being unregistered
sm.registerUtility(aq_base(tool), tool_interface)
def markRegistered(txn):
global _missing_tools_registered
_missing_tools_registered = self.id
TransactionalResource(tpc_finish=markRegistered)
# backward compatibility auto-migration
def getSiteManager(self):
......@@ -365,14 +373,29 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
# OFS.ObjectManager.ObjectManager.getSiteManager(), and is exactly
# as cheap as it is on the case that self._components is already
# set.
if self.id == _missing_tools_registered:
return self._components # fast path
_components = self._components
if _components is not None:
return _components
# This method below can take as (reasonably) long as it pleases
# since it will not be run ever again
self._doInitialSiteManagerMigration()
assert self._components is not None, 'Migration Failed!'
return self._components
if _components is None:
# only create _components
self._createInitialSiteManager()
_components = self._components
# Now that we have a sitemanager, se can do things that require
# one. Including setting up ZTK style utilities and adapters. We
# can even call setSite(self), as long as we roll back that later,
# since we are actually in the middle of a setSite() call.
from zope.site.hooks import getSite, setSite
old_site = getSite()
try:
setSite(self)
self._doTranslationDomainRegistration()
self._registerMissingTools()
finally:
setSite(old_site)
else:
self._registerMissingTools()
return _components
security.declareProtected(Permissions.View, 'view')
def view(self):
......
......@@ -462,7 +462,6 @@ def synchronizeDynamicModules(context, force=False):
portal.portal_skins.changeSkin(None)
TransactionalResource(tpc_finish=lambda txn:
_bootstrapped.add(portal.id))
transaction.get().note('Site migrated')
LOG('ERP5Site', INFO, 'Transition successful, please update your'
' business templates')
else:
......
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