Commit 623e0230 authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: pass arguments of all messages to the grouping method

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37683 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c6e376ad
...@@ -1178,10 +1178,9 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1178,10 +1178,9 @@ class ActivityTool (Folder, UniqueObject):
'invoking group messages: method_id=%s, paths=%s' 'invoking group messages: method_id=%s, paths=%s'
% (method_id, ['/'.join(m.object_path) for m in message_list])) % (method_id, ['/'.join(m.object_path) for m in message_list]))
# Invoke a group method. # Invoke a group method.
object_list = []
expanded_object_list = [] expanded_object_list = []
new_message_list = [] new_message_list = []
path_dict = {} path_set = set()
# Filter the list of messages. If an object is not available, mark its # Filter the list of messages. If an object is not available, mark its
# message as non-executable. In addition, expand an object if necessary, # message as non-executable. In addition, expand an object if necessary,
# and make sure that no duplication happens. # and make sure that no duplication happens.
...@@ -1198,16 +1197,14 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1198,16 +1197,14 @@ class ActivityTool (Folder, UniqueObject):
m.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=self)
continue continue
try: try:
i = len(new_message_list) # This is an index of this message
# in new_message_list
if m.hasExpandMethod(): if m.hasExpandMethod():
subobject_list = m.getObjectList(self) subobject_list = m.getObjectList(self)
else: else:
subobject_list = (obj,) subobject_list = (obj,)
for subobj in subobject_list: for subobj in subobject_list:
path = subobj.getPath() path = subobj.getPath()
if path not in path_dict: if path not in path_set:
path_dict[path] = i path_set.add(path)
if alternate_method_id is not None \ if alternate_method_id is not None \
and hasattr(aq_base(subobj), alternate_method_id): and hasattr(aq_base(subobj), alternate_method_id):
# if this object is alternated, # if this object is alternated,
...@@ -1218,9 +1215,8 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1218,9 +1215,8 @@ class ActivityTool (Folder, UniqueObject):
active_obj = subobj.activate(**activity_kw) active_obj = subobj.activate(**activity_kw)
getattr(active_obj, alternate_method_id)(*m.args, **m.kw) getattr(active_obj, alternate_method_id)(*m.args, **m.kw)
else: else:
expanded_object_list.append(subobj) expanded_object_list.append((subobj, m.args, m.kw))
object_list.append(obj) new_message_list.append((m, obj))
new_message_list.append(m)
except: except:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
...@@ -1231,32 +1227,33 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1231,32 +1227,33 @@ class ActivityTool (Folder, UniqueObject):
# NOTE: expanded_object_list must be set to failed objects by the # NOTE: expanded_object_list must be set to failed objects by the
# callee. If it fully succeeds, expanded_object_list must be # callee. If it fully succeeds, expanded_object_list must be
# empty when returning. # empty when returning.
result = method(expanded_object_list, **m.kw) result = method(expanded_object_list)
else: else:
result = None result = None
except: except:
# In this case, the group method completely failed. # In this case, the group method completely failed.
exc_info = sys.exc_info() exc_info = sys.exc_info()
for m in new_message_list: for m, obj in new_message_list:
m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info, log=False) m.setExecutionState(MESSAGE_NOT_EXECUTED, exc_info, log=False)
LOG('WARNING ActivityTool', 0, LOG('WARNING ActivityTool', 0,
'Could not call method %s on objects %s' % 'Could not call method %s on objects %s' %
(method_id, expanded_object_list), error=exc_info) (method_id, [x[0] for x in expanded_object_list]), error=exc_info)
error_log = getattr(self, 'error_log', None) error_log = getattr(self, 'error_log', None)
if error_log is not None: if error_log is not None:
error_log.raising(exc_info) error_log.raising(exc_info)
else: else:
# Obtain all indices of failed messages. # Obtain all indices of failed messages.
# Note that this can be a partial failure. # Note that this can be a partial failure.
failed_message_set = set(path_dict[obj.getPath()] failed_message_set = set(id(x[2]) for x in expanded_object_list)
for obj in expanded_object_list)
# Only for succeeded messages, an activity process is invoked (if any). # Only for succeeded messages, an activity process is invoked (if any).
for i, m in enumerate(new_message_list): for m, obj in new_message_list:
if i in failed_message_set: # We use id of kw dict (persistent object) to know if there is a
# failed 3-tuple corresponding to Message m.
if id(m.kw) in failed_message_set:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
else: else:
try: try:
m.activateResult(self, result, object_list[i]) m.activateResult(self, result, obj)
except: except:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self) m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
else: else:
......
...@@ -1885,8 +1885,9 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -1885,8 +1885,9 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal() portal = self.getPortal()
organisation = portal.organisation._getOb(self.company_id) organisation = portal.organisation._getOb(self.company_id)
# Defined a group method # Defined a group method
def setFoobar(self, object_list, number=1): def setFoobar(self, object_list):
for obj in object_list: for obj, args, kw in object_list:
number = kw.get('number', 1)
if getattr(obj,'foobar', None) is not None: if getattr(obj,'foobar', None) is not None:
obj.foobar = obj.foobar + number obj.foobar = obj.foobar + number
else: else:
...@@ -2009,7 +2010,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2009,7 +2010,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
transaction.commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQLAndFail(self, object_list, **kw): def modifySQLAndFail(self, object_list):
# Only create the dummy activity if none is present: we would just # Only create the dummy activity if none is present: we would just
# generate missleading errors (duplicate uid). # generate missleading errors (duplicate uid).
if activity_tool.countMessage(method_id='dummy_activity') == 0: if activity_tool.countMessage(method_id='dummy_activity') == 0:
...@@ -2437,7 +2438,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -2437,7 +2438,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
transaction.commit() transaction.commit()
self.tic() self.tic()
activity_tool = self.getActivityTool() activity_tool = self.getActivityTool()
def modifySQL(self, object_list, *arg, **kw): def modifySQL(self, object_list):
# Only create the dummy activity if none is present: we would just # Only create the dummy activity if none is present: we would just
# generate missleading errors (duplicate uid). # generate missleading errors (duplicate uid).
if activity_tool.countMessage(method_id='dummy_activity') == 0: if activity_tool.countMessage(method_id='dummy_activity') == 0:
......
...@@ -759,6 +759,16 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -759,6 +759,16 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
self.catalog_object(object, url, idxs=idxs, sql_catalog_id=sql_catalog_id,**kw) self.catalog_object(object, url, idxs=idxs, sql_catalog_id=sql_catalog_id,**kw)
def catalogObjectList(self, object_list, *args, **kw):
"""Catalog a list of objects"""
if type(object_list[0]) is tuple:
tmp_object_list = [x[0] for x in object_list]
super(CatalogTool, self).catalogObjectList(tmp_object_list, **x[2])
# keep failed objects in 'object_list'
object_list[:] = [x for x in object_list if x[0] in tmp_object_list]
else:
super(CatalogTool, self).catalogObjectList(object_list, *args, **kw)
security.declarePrivate('unindexObject') security.declarePrivate('unindexObject')
def unindexObject(self, object=None, path=None, uid=None,sql_catalog_id=None): def unindexObject(self, object=None, path=None, uid=None,sql_catalog_id=None):
""" """
......
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