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

reactivate messages using their original activity queue when recreating

activity table ( manageClearActivities ). Messages where always reactivated
using SQLDict


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27487 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3a059080
...@@ -36,6 +36,7 @@ import re ...@@ -36,6 +36,7 @@ import re
from Products.CMFCore import CMFCorePermissions from Products.CMFCore import CMFCorePermissions
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
from Products.CMFActivity.ActiveResult import ActiveResult from Products.CMFActivity.ActiveResult import ActiveResult
from Products.CMFActivity.ActiveObject import DEFAULT_ACTIVITY
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from AccessControl import ClassSecurityInfo, Permissions from AccessControl import ClassSecurityInfo, Permissions
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -347,7 +348,7 @@ Exception: %s %s ...@@ -347,7 +348,7 @@ Exception: %s %s
except (socket.error, MailHostError), message: except (socket.error, MailHostError), message:
LOG('ActivityTool.notifyUser', WARNING, 'Mail containing failure information failed to be sent: %s. Exception was: %s %s\n%s' % (message, self.exc_type, self.exc_value, self.traceback)) LOG('ActivityTool.notifyUser', WARNING, 'Mail containing failure information failed to be sent: %s. Exception was: %s %s\n%s' % (message, self.exc_type, self.exc_value, self.traceback))
def reactivate(self, activity_tool): def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY):
# Reactivate the original object. # Reactivate the original object.
obj= self.getObject(activity_tool) obj= self.getObject(activity_tool)
# Change user if required (TO BE DONE) # Change user if required (TO BE DONE)
...@@ -355,7 +356,7 @@ Exception: %s %s ...@@ -355,7 +356,7 @@ Exception: %s %s
current_user = str(_getAuthenticatedUser(self)) current_user = str(_getAuthenticatedUser(self))
user = self.changeUser(self.user_name, activity_tool) user = self.changeUser(self.user_name, activity_tool)
try: try:
active_obj = obj.activate(**self.activity_kw) active_obj = obj.activate(activity=activity, **self.activity_kw)
getattr(active_obj, self.method_id)(*self.args, **self.kw) getattr(active_obj, self.method_id)(*self.args, **self.kw)
finally: finally:
# Use again the previous user # Use again the previous user
...@@ -1273,12 +1274,13 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1273,12 +1274,13 @@ class ActivityTool (Folder, UniqueObject):
folder = getToolByName(self, 'portal_skins').activity folder = getToolByName(self, 'portal_skins').activity
# Obtain all pending messages. # Obtain all pending messages.
message_list = [] message_list_dict = {}
if keep: if keep:
for activity in activity_dict.itervalues(): for activity in activity_dict.itervalues():
if hasattr(activity, 'dumpMessageList'): if hasattr(activity, 'dumpMessageList'):
try: try:
message_list.extend(activity.dumpMessageList(self)) message_list_dict[activity.__class__.__name__] =\
activity.dumpMessageList(self)
except ConflictError: except ConflictError:
raise raise
except: except:
...@@ -1309,9 +1311,10 @@ class ActivityTool (Folder, UniqueObject): ...@@ -1309,9 +1311,10 @@ class ActivityTool (Folder, UniqueObject):
folder.SQLQueue_createMessageTable() folder.SQLQueue_createMessageTable()
# Reactivate the messages. # Reactivate the messages.
for activity, message_list in message_list_dict.iteritems():
for m in message_list: for m in message_list:
try: try:
m.reactivate(aq_inner(self)) m.reactivate(aq_inner(self), activity=activity)
except ConflictError: except ConflictError:
raise raise
except: except:
......
...@@ -630,7 +630,7 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -630,7 +630,7 @@ class TestCMFActivity(ERP5TypeTestCase):
self.tic() self.tic()
self.assertEquals(o.getTitle(), 'last') self.assertEquals(o.getTitle(), 'last')
def CheckClearActivities(self, activity): def CheckClearActivities(self, activity, activity_count=1):
""" """
Check if active objects are held even after clearing the tables. Check if active objects are held even after clearing the tables.
""" """
...@@ -643,12 +643,13 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -643,12 +643,13 @@ class TestCMFActivity(ERP5TypeTestCase):
def check(o): def check(o):
message_list = portal.portal_activities.getMessageList() message_list = portal.portal_activities.getMessageList()
self.assertEquals(len(message_list), 1) self.assertEquals(len(message_list), activity_count)
m = message_list[0] m = message_list[0]
self.assertEquals(m.object_path, o.getPhysicalPath()) self.assertEquals(m.object_path, o.getPhysicalPath())
self.assertEquals(m.method_id, '_setTitle') self.assertEquals(m.method_id, '_setTitle')
o = portal.organisation._getOb(self.company_id) o = portal.organisation._getOb(self.company_id)
for i in range(activity_count):
o.activate(activity=activity)._setTitle('foo') o.activate(activity=activity)._setTitle('foo')
get_transaction().commit() get_transaction().commit()
check(o) check(o)
...@@ -1472,7 +1473,7 @@ class TestCMFActivity(ERP5TypeTestCase): ...@@ -1472,7 +1473,7 @@ class TestCMFActivity(ERP5TypeTestCase):
message = '\nCheck Clearing Activities With SQL Queue' message = '\nCheck Clearing Activities With SQL Queue'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
self.CheckClearActivities('SQLQueue') self.CheckClearActivities('SQLQueue', activity_count=2)
def flushAllActivities(self, silent=0, loop_size=1000): def flushAllActivities(self, silent=0, loop_size=1000):
"""Executes all messages until the queue only contains failed """Executes all messages until the queue only contains failed
......
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