Commit 91665363 authored by Jérome Perrin's avatar Jérome Perrin

Delay installation of skins after installation of paths, because some Z SQL...

Delay installation of skins after installation of paths, because some Z SQL Methods in skins can use connections installed as path.
Z SQL Method can use any kind of Shared.DC.ZRDB.Connection.Connection, not only MySQL Database Connection.
Move code to check and update Z SQL Method connection_id in a function.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10142 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0454bdf6
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from Shared.DC.ZRDB.Connection import Connection as RDBConnection
from Globals import Persistent, PersistentMapping from Globals import Persistent, PersistentMapping
from Acquisition import Implicit, aq_base from Acquisition import Implicit, aq_base
from AccessControl.Permission import Permission from AccessControl.Permission import Permission
...@@ -140,6 +141,21 @@ def getChainByType(context): ...@@ -140,6 +141,21 @@ def getChainByType(context):
default_chain=', '.join(pw._default_chain) default_chain=', '.join(pw._default_chain)
return (default_chain, new_dict) return (default_chain, new_dict)
def fixZSQLMethod(portal, method):
"""Make sure the ZSQLMethod uses a valid connection.
"""
if not isinstance(getattr(portal, method.connection_id, None),
RDBConnection):
# if not valid, we assign to the first valid connection found
sql_connection_list = portal.objectIds(
spec=('Z MySQL Database Connection',))
if (method.connection_id not in sql_connection_list) and \
(len(sql_connection_list) != 0):
LOG('BusinessTemplate', WARNING,
'connection_id for Z SQL Method %s is invalid, using %s' % (
method.getId(), sql_connection_list[0]))
method.connection_id = sql_connection_list[0]
class BusinessTemplateArchive: class BusinessTemplateArchive:
""" """
This is the base class for all Business Template archives This is the base class for all Business Template archives
...@@ -632,12 +648,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -632,12 +648,7 @@ class ObjectTemplateItem(BaseTemplateItem):
if subobject_id not in obj.objectIds(): if subobject_id not in obj.objectIds():
obj._setObject(subobject_id, subobject) obj._setObject(subobject_id, subobject)
if obj.meta_type in ('Z SQL Method',): if obj.meta_type in ('Z SQL Method',):
# It is necessary to make sure that the sql connection fixZSQLMethod(portal, obj)
# in this method is valid.
sql_connection_list = portal.objectIds(spec=('Z MySQL Database Connection',))
if (obj.connection_id not in sql_connection_list) and \
(len(sql_connection_list) != 0):
obj.connection_id = sql_connection_list[0]
# now put original order group # now put original order group
for path in groups.keys(): for path in groups.keys():
obj = portal.unrestrictedTraverse(path) obj = portal.unrestrictedTraverse(path)
...@@ -662,12 +673,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -662,12 +673,7 @@ class ObjectTemplateItem(BaseTemplateItem):
obj.manage_afterClone(obj) obj.manage_afterClone(obj)
obj.wl_clearLocks() obj.wl_clearLocks()
if obj.meta_type in ('Z SQL Method',): if obj.meta_type in ('Z SQL Method',):
# It is necessary to make sure that the sql connection fixZSQLMethod(portal, obj)
# in this method is valid.
sql_connection_list = portal.objectIds(
spec=('Z MySQL Database Connection',))
if obj.connection_id not in sql_connection_list:
obj.connection_id = sql_connection_list[0]
def uninstall(self, context, **kw): def uninstall(self, context, **kw):
portal = context.getPortalObject() portal = context.getPortalObject()
...@@ -997,14 +1003,11 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -997,14 +1003,11 @@ class SkinTemplateItem(ObjectTemplateItem):
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
force = kw.get('force') force = kw.get('force')
p = context.getPortalObject() p = context.getPortalObject()
# It is necessary to make sure that the sql connections in Z SQL Methods are valid.
sql_connection_list = p.objectIds(spec=('Z MySQL Database Connection',))
for relative_url in self._archive.keys(): for relative_url in self._archive.keys():
folder = p.unrestrictedTraverse(relative_url) folder = p.unrestrictedTraverse(relative_url)
for obj in folder.objectValues(spec=('Z SQL Method',)): for obj in folder.objectValues(spec=('Z SQL Method',)):
if (obj.connection_id not in sql_connection_list) and \ fixZSQLMethod(p, obj)
(len(sql_connection_list) != 0):
obj.connection_id = sql_connection_list[0]
# Add new folders into skin paths. # Add new folders into skin paths.
ps = p.portal_skins ps = p.portal_skins
for skin_name, selection in ps.getSkinPaths(): for skin_name, selection in ps.getSkinPaths():
...@@ -3681,6 +3684,12 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3681,6 +3684,12 @@ Business Template is a set of definitions, such as skins, portal types and categ
# This is a global variable # This is a global variable
# Order is important for installation # Order is important for installation
# We want to have:
# * path after module, because path can be module content
# * path after categories, because path can be categories content
# * skin after paths, because we can install a custom connection string as
# path and use it with SQLMethods in a skin.
# ( and more )
_item_name_list = [ _item_name_list = [
'_product_item', '_product_item',
'_property_sheet_item', '_property_sheet_item',
...@@ -3700,8 +3709,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3700,8 +3709,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
'_portal_type_base_category_item', '_portal_type_base_category_item',
'_category_item', '_category_item',
'_module_item', '_module_item',
'_skin_item',
'_path_item', '_path_item',
'_skin_item',
'_preference_item', '_preference_item',
'_action_item', '_action_item',
'_portal_type_roles_item', '_portal_type_roles_item',
......
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