Index: openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	10 Apr 2001 23:53:26 -0000	1.2
+++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	11 Apr 2001 04:47:19 -0000	1.3
@@ -158,6 +158,9 @@
   new__creation_date          alias for $5;  
   new__creation_user          alias for $6;  
   new__creation_ip            alias for $7;  
+  v_case_id                   number;
+  v_workflow_case_table       varchar;
+  v_context_key_for_query     varchar;
 begin
         if new__context_key is null then
             v_context_key_for_query := ''default'';
@@ -1766,17 +1769,19 @@
 create function workflow_case__start_task (number,number,number)
 returns integer as '
 declare
-  task_id                alias for $1;  
-  user_id                alias for $2;  
-  journal_id             alias for $3;  
-  v_case_id              number;        
-  v_workflow_key         wf_workflows.workflow_key%TYPE;
-  v_transition_key       varchar(100);  
-  v_hold_timeout_callback   varchar(100);  
-  v_hold_timeout_custom_arg   varchar(4000); 
-  v_hold_timeout         timestamp;     
+  start_task__task_id                alias for $1;  
+  start_task__user_id                alias for $2;  
+  start_task__journal_id             alias for $3;  
+  v_case_id                          number;        
+  v_workflow_key                     wf_workflows.workflow_key%TYPE;
+  v_transition_key                   varchar(100);  
+  v_hold_timeout_callback            varchar(100);  
+  v_hold_timeout_custom_arg          varchar(4000); 
+  v_hold_timeout                     timestamp;     
+  place_rec                          record;
 begin
-        ensure_task_in_state(task_id => start_task__task_id, state => ''enabled'');
+        PERFORM workflow_case__ensure_task_in_state(start_task__task_id, 
+                                                    ''enabled'');
     
         select t.case_id, t.workflow_key, t.transition_key, ti.hold_timeout_callback, ti.hold_timeout_custom_arg 
         into   v_case_id, v_workflow_key, v_transition_key, v_hold_timeout_callback, v_hold_timeout_custom_arg
@@ -1787,41 +1792,50 @@
         and    ti.workflow_key = t.workflow_key
         and    ti.transition_key = t.transition_key;
 
-        v_hold_timeout := execute_hold_timeout_callback(v_hold_timeout_callback, 
-            v_hold_timeout_custom_arg, v_case_id, v_transition_key);
+        v_hold_timeout := workflow_case__execute_hold_timeout_callback(
+                       v_hold_timeout_callback, 
+                       v_hold_timeout_custom_arg, 
+                       v_case_id, v_transition_key);
 
         /* Mark it started */
 
         update wf_tasks 
         set    state = ''started'', 
-               started_date = sysdate,
+               started_date = now(),
                holding_user = start_task__user_id, 
                hold_timeout = v_hold_timeout
         where task_id = start_task__task_id;
     
         
         /* Reserve one token from each input place */
 
-        for place_rec in input_places(v_workflow_key,v_transition_key) loop
-            lock_token( 
-                case_id => v_case_id,
-                place_key => place_rec.place_key,
-                journal_id => start_task__journal_id,
-                task_id => start_task__task_id
+        for place_rec in select *
+        from   wf_transition_places tp
+        where  tp.workflow_key = v_workflow_key
+        and    tp.transition_key = v_transition_key
+        and    direction = ''in''
+        LOOP
+            PERFORM workflow_case__lock_token( 
+                v_case_id,
+                place_rec.place_key,
+                start_task__journal_id,
+                start_task__task_id
             );
         end loop;
-    return 0; 
+
+        return 0; 
 end;' language 'plpgsql';
 
 
 -- procedure cancel_task
 create function workflow_case__cancel_task (number,number)
 returns integer as '
 declare
-  task_id                alias for $1;  
-  journal_id             alias for $2;  
+  cancel_task__task_id                alias for $1;  
+  cancel_task__journal_id             alias for $2;  
 begin
-        ensure_task_in_state(task_id => cancel_task__task_id, state => ''started'');
+        PERFORM workflow_case__ensure_task_in_state(cancel_task__task_id, 
+                                                    ''started'');
         select case_id into v_case_id 
         from wf_tasks 
         where task_id = cancel_task__task_id;
@@ -1830,48 +1844,50 @@
 
         update wf_tasks 
         set    state = ''canceled'',
-               canceled_date =  sysdate
+               canceled_date =  now()
         where  task_id = cancel_task__task_id;
 
     
         /* Release our reserved tokens */
 
-        release_token(
-            task_id => cancel_task__task_id,
-            journal_id => cancel_task__journal_id
+        PERFORM workflow_case__release_token(
+            cancel_task__task_id,
+            cancel_task__journal_id
         );
 
         /* The workflow state has now changed, so we must run this */
         
-        sweep_automatic_transitions(
-            case_id => v_case_id,
-            journal_id => cancel_task__journal_id
+        PERFORM workflow_case__sweep_automatic_transitions(
+            v_case_id,
+            cancel_task__journal_id
         );
-    return 0; 
+
+        return 0; 
 end;' language 'plpgsql';
 
 
 -- procedure finish_task
 create function workflow_case__finish_task (number,number)
 returns integer as '
 declare
-  task_id                alias for $1;  
-  journal_id             alias for $2;  
+  finish_task__task_id                alias for $1;  
+  finish_task__journal_id             alias for $2;  
 begin
         select case_id into v_case_id
         from   wf_tasks
         where  task_id = finish_task__task_id;
 
-        fire_transition_internal(
-            task_id => finish_task__task_id,
-            journal_id => finish_task__journal_id
+        PERFORM workflow_case__fire_transition_internal(
+            finish_task__task_id,
+            finish_task__journal_id
         );
 
-        sweep_automatic_transitions(
-            case_id => v_case_id,
-            journal_id => finish_task__journal_id
+        PERFORM workflow_case__sweep_automatic_transitions(
+            v_case_id,
+            finish_task__journal_id
         );
-    return 0; 
+
+        return 0; 
 end;' language 'plpgsql';
 
 
@@ -1886,12 +1902,9 @@
 create function inline_0 ()
 returns integer as '
 begin
-    select nt__schedule_process (1,'localhost',25);
-    NONE,
-    NONE,
-    25
-    );
-  return 0;
+    PERFORM  nt__schedule_process (1,'localhost',25);
+
+    return 0;
 end;' language 'plpgsql';
 
 select inline_0 ();
