Commit fe5f2c60 by 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.
1 parent 8145752e
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
Portal class Portal class
""" """
from six.moves import map
import threading import threading
from weakref import ref as weakref from weakref import ref as weakref
from OFS.Application import Application, AppInitializer from OFS.Application import Application, AppInitializer
...@@ -324,7 +325,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -324,7 +325,7 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
from Products.Localizer.MessageCatalog import ( from Products.Localizer.MessageCatalog import (
message_catalog_alias_sources message_catalog_alias_sources
) )
sm = self.getSiteManager() sm = self._components
for message_catalog in self.Localizer.objectValues(): for message_catalog in self.Localizer.objectValues():
sm.registerUtility(message_catalog, sm.registerUtility(message_catalog,
provided=ITranslationDomain, provided=ITranslationDomain,
...@@ -334,21 +335,22 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -334,21 +335,22 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
provided=ITranslationDomain, provided=ITranslationDomain,
name=alias) name=alias)
def _doInitialSiteManagerMigration(self): def _registerMissingTools(self):
self._createInitialSiteManager() from Products.CMFCore import interfaces, utils
# Now that we have a sitemanager, se can do things that require tool_id_list = ("portal_skins", "portal_types", "portal_membership",
# one. Including setting up ZTK style utilities and adapters. We "portal_url", "portal_workflow")
# can even call setSite(self), as long as we roll back that later, if None in map(self.get, tool_id_list):
# since we are actually in the middle of a setSite() call. return False
from zope.site.hooks import getSite, setSite sm = self._components
old_site = getSite() for tool_id in tool_id_list:
try: tool = self[tool_id]
setSite(self) tool_interface = utils._tool_interface_registry.get(tool_id)
# setSite(self) is not really necessary for the migration below, but if tool_interface is not None:
# could be needed by other migrations to be added here. # Note: already registered tools will be either:
self._doTranslationDomainRegistration() # - updated
finally: # - registered again after being unregistered
setSite(old_site) sm.registerUtility(aq_base(tool), tool_interface)
return True
# backward compatibility auto-migration # backward compatibility auto-migration
def getSiteManager(self): def getSiteManager(self):
...@@ -366,13 +368,25 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin): ...@@ -366,13 +368,25 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
# as cheap as it is on the case that self._components is already # as cheap as it is on the case that self._components is already
# set. # set.
_components = self._components _components = self._components
if _components is not None: if _components is None:
return _components # only create _components
# This method below can take as (reasonably) long as it pleases self._createInitialSiteManager()
# since it will not be run ever again _components = self._components
self._doInitialSiteManagerMigration() # Now that we have a sitemanager, se can do things that require
assert self._components is not None, 'Migration Failed!' # one. Including setting up ZTK style utilities and adapters. We
return self._components # 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') security.declareProtected(Permissions.View, 'view')
def view(self): def view(self):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!