Commit 929ed43d authored by Ivan Tyagov's avatar Ivan Tyagov

Make sure that enabling a Preference (which generates a reindex activity) in a...

Make sure that enabling a Preference (which generates a reindex activity) in a business template installation is wrapped into proper execution activity order. This is required to prevent calling an recursiveReindexObject on a deleted object. 

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30720 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 89e08833
...@@ -787,6 +787,23 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -787,6 +787,23 @@ class ObjectTemplateItem(BaseTemplateItem):
""" """
pass pass
def setSafeReindexationMode(self, context):
"""
Postpone indexations after unindexations.
This avoids alarming error messages about a single uid being used
by "deleted" path and reindexed object. This can happen here for
objects on which the uid was restored: previous object was deleted,
hence the "deleted" path, and new object does have the same uid.
"""
original_reindex_parameters = context.getPlacelessDefaultReindexParameters()
if original_reindex_parameters is None:
original_reindex_parameters = {}
activate_kw = original_reindex_parameters.get('activate_kw', {}).copy()
activate_kw['after_method_id'] = 'unindexObject'
context.setPlacelessDefaultReindexParameters(activate_kw=activate_kw, \
**original_reindex_parameters)
return original_reindex_parameters
def install(self, context, trashbin, **kw): def install(self, context, trashbin, **kw):
self.beforeInstall() self.beforeInstall()
update_dict = kw.get('object_to_update') update_dict = kw.get('object_to_update')
...@@ -817,17 +834,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -817,17 +834,8 @@ class ObjectTemplateItem(BaseTemplateItem):
# sort to add objects before their subobjects # sort to add objects before their subobjects
keys = self._objects.keys() keys = self._objects.keys()
keys.sort() keys.sort()
# Postpone indexations after unindexations. # set safe activities execution order
# This avoids alarming error messages about a single uid being used original_reindex_parameters = self.setSafeReindexationMode(context)
# by "deleted" path and reindexed object. This can happen here for
# objects on which the uid was restored: previous object was deleted,
# hence the "deleted" path, and new object does have the same uid.
original_reindex_parameters = context.getPlacelessDefaultReindexParameters()
if original_reindex_parameters is None:
original_reindex_parameters = {}
activate_kw = original_reindex_parameters.get('activate_kw', {}).copy()
activate_kw['after_method_id'] = 'unindexObject'
context.setPlacelessDefaultReindexParameters(activate_kw=activate_kw, **original_reindex_parameters)
for path in keys: for path in keys:
if update_dict.has_key(path) or force: if update_dict.has_key(path) or force:
# get action for the oject # get action for the oject
...@@ -1036,7 +1044,7 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1036,7 +1044,7 @@ class ObjectTemplateItem(BaseTemplateItem):
group_value_list.remove(widget_id) group_value_list.remove(widget_id)
# now set new group object # now set new group object
obj.groups = new_groups_dict obj.groups = new_groups_dict
# Remove after_method_id # restore previous activities execution order
context.setPlacelessDefaultReindexParameters(**original_reindex_parameters) context.setPlacelessDefaultReindexParameters(**original_reindex_parameters)
else: else:
# for old business template format # for old business template format
...@@ -1236,11 +1244,15 @@ class PreferenceTemplateItem(PathTemplateItem): ...@@ -1236,11 +1244,15 @@ class PreferenceTemplateItem(PathTemplateItem):
pref = portal.unrestrictedTraverse(object_path) pref = portal.unrestrictedTraverse(object_path)
# XXX getPreferenceState is a bad name # XXX getPreferenceState is a bad name
if pref.getPreferenceState() == 'disabled': if pref.getPreferenceState() == 'disabled':
# set safe activities execution order
original_reindex_parameters = self.setSafeReindexationMode(context)
portal.portal_workflow.doActionFor( portal.portal_workflow.doActionFor(
pref, pref,
'enable_action', 'enable_action',
comment="Initialized during Business Template " \ comment="Initialized during Business Template " \
"installation.") "installation.")
# restore previous activities execution order
context.setPlacelessDefaultReindexParameters(**original_reindex_parameters)
class CategoryTemplateItem(ObjectTemplateItem): class CategoryTemplateItem(ObjectTemplateItem):
......
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