before-commit-hook API for the transaction object changed. Temporarily patch...

before-commit-hook API for the transaction object changed. Temporarily patch transaction on Zope 2.8 with the new API and adapt all uses (approved by jm)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29871 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4d92f5bc
No related merge requests found
......@@ -27,10 +27,7 @@ from Shared.DC.ZRDB.TM import TM
from zLOG import LOG, ERROR, INFO
import sys
try:
from transaction import get as get_transaction
except ImportError:
pass
import transaction
class ActivityBuffer(TM):
......@@ -81,13 +78,11 @@ class ActivityBuffer(TM):
for activity in activity_dict.itervalues():
activity.registerActivityBuffer(self)
# In Zope 2.8 (ZODB 3.4), use beforeCommitHook instead of
# patching Trasaction.
transaction = get_transaction()
try:
transaction.beforeCommitHook(self.tpc_prepare, transaction, activity_tool=activity_tool)
except AttributeError:
pass
# Notice: The operation below cannot fail silently, or we get errors late
# in the transaction that are very hard to understand.
transaction.get().addBeforeCommitHook(self.tpc_prepare,
(transaction,),
dict(activity_tool=activity_tool))
except:
LOG('ActivityBuffer', ERROR, "exception during _begin",
error=sys.exc_info())
......
......@@ -306,7 +306,7 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
# Execute Before Commit
for script_name in tdef.before_commit_script_name:
script = self.scripts[script_name]
transaction.get().beforeCommitHook(script, sci)
transaction.get().addBeforeCommitHook(script, (sci,))
# Execute "activity" scripts
for script_name in tdef.activate_script_name:
......@@ -329,4 +329,4 @@ class InteractionWorkflowDefinition (DCWorkflowDefinition, ActiveObject):
Globals.InitializeClass(InteractionWorkflowDefinition)
addWorkflowFactory(InteractionWorkflowDefinition, id='interaction_workflow',
title='Web-configurable interaction workflow')
title='Web-configurable interaction workflow')
......@@ -56,6 +56,9 @@ from Products.ERP5Type.patches import http_server
from Products.ERP5Type.patches import memcache_client
from Products.ERP5Type.patches import StateChangeInfoPatch
from Products.ERP5Type.patches import OFSPdata
# Forward Compatibility with Zope 2.12 or CMF 2.2. Remove when we've dropped
# support for old versions
from Products.ERP5Type.patches import TransactionAddBeforeCommitHook
# These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from transaction._transaction import Transaction
if not hasattr(Transaction, 'addBeforeCommitHook'):
def Transaction_addBeforeCommitHook(self, hook, args=(), kws=None):
if kws is None:
kws = {}
self.beforeCommitHook(hook, *args, **kws)
import logging
logger = logging.getLogger(__name__)
logger.info("Patching Transaction with forward compatibility for "
".addBeforeCommitHook()")
Transaction.addBeforeCommitHook = Transaction_addBeforeCommitHook
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