From 8f90f3e9b8fafab8abd5faeeafe2fa5b6ac385f1 Mon Sep 17 00:00:00 2001
From: Leonardo Rochael Almeida <leonardo@nexedi.com>
Date: Thu, 8 Oct 2009 14:34:05 +0000
Subject: [PATCH] Concentrate all imports of addWorkflowFactory to a location
 under our control. For CMF 2.x we will emulate this function by creating
 actual Zope2 Factories for our workflows.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29477 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/InteractionWorkflow.py    |  2 +-
 product/ERP5Type/patches/DCWorkflow.py | 27 +++++++++++++++++++-------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/product/ERP5/InteractionWorkflow.py b/product/ERP5/InteractionWorkflow.py
index b1f55e5075..eab5d01792 100644
--- a/product/ERP5/InteractionWorkflow.py
+++ b/product/ERP5/InteractionWorkflow.py
@@ -26,7 +26,7 @@ from Products.CMFCore.utils import getToolByName
 from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
 from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD
 from Products.DCWorkflow.Expression import StateChangeInfo, createExprContext
-from Products.CMFCore.WorkflowTool import addWorkflowFactory
+from Products.ERP5Type.patches.DCWorkflow import addWorkflowFactory
 from Products.CMFActivity.ActiveObject import ActiveObject
 from Products.ERP5Type import Permissions
 
diff --git a/product/ERP5Type/patches/DCWorkflow.py b/product/ERP5Type/patches/DCWorkflow.py
index 9a794f0fc9..9236568ba9 100644
--- a/product/ERP5Type/patches/DCWorkflow.py
+++ b/product/ERP5Type/patches/DCWorkflow.py
@@ -609,13 +609,26 @@ TransitionDefinition.getAvailableScriptIds = getAvailableScriptIds
 try:
     from Products.CMFCore.WorkflowTool import addWorkflowFactory
 except ImportError:
-    import zLOG
-    zLOG.LOG('Products.ERP5Type.patches.DCWorkflow',
-        zLOG.ERROR,
-        'Products.CMFCore.WorkflowTool.addWorkflowFactory has been removed. '
-        'ERP5 Workflow factory not installed',
-        error=sys.exc_info())
-    addWorkflowFactory = lambda factory, id, title: None 
+    def addWorkflowFactory(factory, id, title):
+        """addWorkflowFactory replacement
+        
+        addWorkflowFactory has been removed from CMF 2.x.
+        DCWorkflow, which actually handled the workflows added by this function
+        now consults the GenericSetup tool, at runtime to determine all valid
+        workflows.
+        
+        Instead of providing GenericSetup profiles for our workflows, we
+        install our own Zope2 style factories for the Workflow Tool
+        """ 
+        import zLOG
+        zLOG.LOG('Products.ERP5Type.patches.DCWorkflow.addWorkflowFactory',
+                 zLOG.ERROR,
+                 summary='Workflow Factory not registered',
+                 detail='Products.CMFCore.WorkflowTool.addWorkflowFactory has '
+                 'been removed from CMFCore, and a replacement has not been '
+                 'written yet. ERP5 Workflow factory for '
+                 '%s (%s) not installed.' % (id, title))
+
 from Products.ERP5Type import Permissions
 
 def setupERP5Workflow(wf):
-- 
2.30.9