Commit 35311b33 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Keep active objects when clearing the tables.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4877 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2347555d
...@@ -428,6 +428,16 @@ class SQLDict(RAMDict): ...@@ -428,6 +428,16 @@ class SQLDict(RAMDict):
message_list.append(m) message_list.append(m)
return message_list return message_list
def dumpMessageList(self, activity_tool):
# Dump all messages in the table.
message_list = []
if hasattr(activity_tool, 'SQLDict_dumpMessageList'):
result = activity_tool.SQLDict_dumpMessageList()
for line in result:
m = self.loadMessage(line.message, uid = line.uid)
message_list.append(m)
return message_list
def distribute(self, activity_tool, node_count): def distribute(self, activity_tool, node_count):
processing_node = 1 processing_node = 1
if hasattr(activity_tool,'SQLDict_readMessageList'): if hasattr(activity_tool,'SQLDict_readMessageList'):
......
...@@ -212,6 +212,16 @@ class SQLQueue(RAMQueue): ...@@ -212,6 +212,16 @@ class SQLQueue(RAMQueue):
message_list.append(m) message_list.append(m)
return message_list return message_list
def dumpMessageList(self, activity_tool):
# Dump all messages in the table.
message_list = []
if hasattr(activity_tool, 'SQLQueue_dumpMessageList'):
result = activity_tool.SQLQueue_dumpMessageList()
for line in result:
m = self.loadMessage(line.message, uid = line.uid)
message_list.append(m)
return message_list
def distribute(self, activity_tool, node_count): def distribute(self, activity_tool, node_count):
processing_node = 1 processing_node = 1
if hasattr(activity_tool,'SQLQueue_readMessageList'): if hasattr(activity_tool,'SQLQueue_readMessageList'):
......
...@@ -47,7 +47,7 @@ import sys ...@@ -47,7 +47,7 @@ import sys
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from zLOG import LOG, INFO from zLOG import LOG, INFO, WARNING
try: try:
from Products.TimerService import getTimerService from Products.TimerService import getTimerService
...@@ -136,16 +136,18 @@ class Message: ...@@ -136,16 +136,18 @@ class Message:
try: try:
# LOG('WARNING ActivityTool', 0, # LOG('WARNING ActivityTool', 0,
# 'Trying to call method %s on object %s' % (self.method_id, self.object_path)) # 'Trying to call method %s on object %s' % (self.method_id, self.object_path))
object = self.getObject(activity_tool) obj = self.getObject(activity_tool)
# Change user if required (TO BE DONE) # Change user if required (TO BE DONE)
# We will change the user only in order to execute this method # We will change the user only in order to execute this method
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)
result = getattr(object, self.method_id)(*self.args, **self.kw) try:
# Use again the previous user result = getattr(obj, self.method_id)(*self.args, **self.kw)
if user is not None: finally:
self.changeUser(current_user, activity_tool) # Use again the previous user
self.activateResult(activity_tool, result, object) if user is not None:
self.changeUser(current_user, activity_tool)
self.activateResult(activity_tool, result, obj)
self.is_executed = 1 self.is_executed = 1
except: except:
self.is_executed = 0 self.is_executed = 0
...@@ -176,6 +178,21 @@ Method: %s ...@@ -176,6 +178,21 @@ Method: %s
activity_tool.MailHost.send( mail_text ) activity_tool.MailHost.send( mail_text )
#LOG('notifyUser send', 0, '') #LOG('notifyUser send', 0, '')
def reactivate(self, activity_tool):
# Reactivate the original object.
obj= self.getObject(activity_tool)
# Change user if required (TO BE DONE)
# We will change the user only in order to execute this method
current_user = str(_getAuthenticatedUser(self))
user = self.changeUser(self.user_name, activity_tool)
try:
active_obj = obj.activate(**self.activity_kw)
getattr(active_obj, self.method_id)(*self.args, **self.kw)
finally:
# Use again the previous user
if user is not None:
self.changeUser(current_user, activity_tool)
class Method: class Method:
def __init__(self, passive_self, activity, active_process, kw, method_id): def __init__(self, passive_self, activity, active_process, kw, method_id):
...@@ -674,6 +691,17 @@ class ActivityTool (Folder, UniqueObject): ...@@ -674,6 +691,17 @@ class ActivityTool (Folder, UniqueObject):
""" """
folder = getToolByName(self, 'portal_skins').activity folder = getToolByName(self, 'portal_skins').activity
# Obtain all pending messages.
message_list = []
for activity in activity_list:
if hasattr(activity, 'dumpMessageList'):
try:
message_list.extend(activity.dumpMessageList(self))
except ConflictError:
raise
except:
LOG('ActivityTool', WARNING, 'could not dump messages from %s' % (activity,), error=sys.exc_info())
if hasattr(folder, 'SQLDict_createMessageTable'): if hasattr(folder, 'SQLDict_createMessageTable'):
try: try:
folder.SQLDict_dropMessageTable() folder.SQLDict_dropMessageTable()
...@@ -681,8 +709,8 @@ class ActivityTool (Folder, UniqueObject): ...@@ -681,8 +709,8 @@ class ActivityTool (Folder, UniqueObject):
raise raise
except: except:
LOG('CMFActivities', LOG('CMFActivities',
0, WARNING,
'WARNING: could not drop the message table', 'could not drop the message table',
error=sys.exc_info()) error=sys.exc_info())
folder.SQLDict_createMessageTable() folder.SQLDict_createMessageTable()
...@@ -693,11 +721,22 @@ class ActivityTool (Folder, UniqueObject): ...@@ -693,11 +721,22 @@ class ActivityTool (Folder, UniqueObject):
raise raise
except: except:
LOG('CMFActivities', LOG('CMFActivities',
0, WARNING,
'WARNING: could not drop the message queue table', 'could not drop the message queue table',
error=sys.exc_info()) error=sys.exc_info())
folder.SQLQueue_createMessageTable() folder.SQLQueue_createMessageTable()
# Reactivate the messages.
for m in message_list:
try:
m.reactivate(self)
except ConflictError:
raise
except:
LOG('ActivityTool', WARNING,
'could not reactivate the message %r, %r' % (m.object_path, m.method_id),
error=sys.exc_info())
if REQUEST is not None: if REQUEST is not None:
return REQUEST.RESPONSE.redirect('%s/%s' % (self.absolute_url(), 'manageActivitiesAdvanced?manage_tabs_message=Activities%20Cleared')) return REQUEST.RESPONSE.redirect('%s/%s' % (self.absolute_url(), 'manageActivitiesAdvanced?manage_tabs_message=Activities%20Cleared'))
......
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params></params>
SELECT * FROM
message
ORDER BY
uid
<dtml-comment>
title:
connection_id:cmf_activity_sql_connection
max_rows:0
max_cache:0
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>path
method_id
processing_node
priority</params>
SELECT * FROM
message_queue
ORDER BY
uid
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