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):
'invoking group messages: method_id=%s, paths=%s'
% (method_id, ['/'.join(m.object_path) for m in message_list]))
# Invoke a group method.
object_list = []
expanded_object_list = []
new_message_list = []
path_dict = {}
path_set = set()
# Filter the list of messages. If an object is not available, mark its
# message as non-executable. In addition, expand an object if necessary,
# and make sure that no duplication happens.
......@@ -1198,16 +1197,14 @@ class ActivityTool (Folder, UniqueObject):
m.setExecutionState(MESSAGE_NOT_EXECUTABLE, context=self)
continue
try:
i = len(new_message_list) # This is an index of this message
# in new_message_list
if m.hasExpandMethod():
subobject_list = m.getObjectList(self)
else:
subobject_list = (obj,)
for subobj in subobject_list:
path = subobj.getPath()
if path not in path_dict:
path_dict[path] = i
if path not in path_set:
path_set.add(path)
if alternate_method_id is not None \
and hasattr(aq_base(subobj), alternate_method_id):
# if this object is alternated,
......@@ -1218,9 +1215,8 @@ class ActivityTool (Folder, UniqueObject):
active_obj = subobj.activate(**activity_kw)
getattr(active_obj, alternate_method_id)(*m.args, **m.kw)
else:
expanded_object_list.append(subobj)
object_list.append(obj)
new_message_list.append(m)
expanded_object_list.append((subobj, m.args, m.kw))
new_message_list.append((m, obj))
except:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
......@@ -1231,32 +1227,33 @@ class ActivityTool (Folder, UniqueObject):
# NOTE: expanded_object_list must be set to failed objects by the
# callee. If it fully succeeds, expanded_object_list must be
# empty when returning.
result = method(expanded_object_list, **m.kw)
result = method(expanded_object_list)
else:
result = None
except:
# In this case, the group method completely failed.
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)
LOG('WARNING ActivityTool', 0,
'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)
if error_log is not None:
error_log.raising(exc_info)
else:
# Obtain all indices of failed messages.
# Note that this can be a partial failure.
failed_message_set = set(path_dict[obj.getPath()]
for obj in expanded_object_list)
failed_message_set = set(id(x[2]) for x in expanded_object_list)
# Only for succeeded messages, an activity process is invoked (if any).
for i, m in enumerate(new_message_list):
if i in failed_message_set:
for m, obj in new_message_list:
# 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)
else:
try:
m.activateResult(self, result, object_list[i])
m.activateResult(self, result, obj)
except:
m.setExecutionState(MESSAGE_NOT_EXECUTED, context=self)
else:
......
......@@ -1885,8 +1885,9 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal()
organisation = portal.organisation._getOb(self.company_id)
# Defined a group method
def setFoobar(self, object_list, number=1):
for obj in object_list:
def setFoobar(self, object_list):
for obj, args, kw in object_list:
number = kw.get('number', 1)
if getattr(obj,'foobar', None) is not None:
obj.foobar = obj.foobar + number
else:
......@@ -2009,7 +2010,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
transaction.commit()
self.tic()
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
# generate missleading errors (duplicate uid).
if activity_tool.countMessage(method_id='dummy_activity') == 0:
......@@ -2437,7 +2438,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
transaction.commit()
self.tic()
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
# generate missleading errors (duplicate uid).
if activity_tool.countMessage(method_id='dummy_activity') == 0:
......
......@@ -759,6 +759,16 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
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')
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