entities/wfobjs.py
branchstable
changeset 3999 5dd6ffc2ccae
parent 3986 cc29eddf51ad
child 4002 4edff8bce44b
--- 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