added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 04 Dec 2009 19:45:19 +0100
branchstable
changeset 3999 5dd6ffc2ccae
parent 3997 354e50e5bc61
child 4000 4b16a7c01a25
added replace_state method to ease workflow migration. backported from forge as a reminder, not really tested yet
entities/wfobjs.py
--- a/entities/wfobjs.py	Thu Dec 03 16:32:35 2009 +0100
+++ b/entities/wfobjs.py	Fri Dec 04 19:45:19 2009 +0100
@@ -152,6 +152,19 @@
             tr.add_exit_point(fromstate, tostate)
         return tr
 
+    def replace_state(self, todelstate, replacement):
+        """migration convenience method"""
+        if not hasattr(todelstate, 'eid'):
+            todelstate = self.state_by_name(todelstate)
+        if not hasattr(replacement, 'eid'):
+            replacement = self.state_by_name(replacement)
+        execute = self._cw.unsafe_execute
+        execute('SET X in_state S WHERE S eid %(s)s', {'s': todelstate.eid}, 's')
+        execute('SET X from_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s',
+                {'os': todelstate.eid, 'ns': newstate.eid}, 's')
+        execute('SET X to_state NS WHERE X to_state OS, OS eid %(os)s, NS eid %(ns)s',
+                {'os': todelstate.eid, 'ns': newstate.eid}, 's')
+
 
 class BaseTransition(AnyEntity):
     """customized class for abstract transition