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.5 -r1.6
--- openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	13 Apr 2001 04:31:27 -0000	1.5
+++ openacs-4/contrib/obsolete-packages/acs-workflow/sql/postgresql/workflow-case-package.sql	13 Apr 2001 13:27:42 -0000	1.6
@@ -1016,7 +1016,7 @@
 
 -- function get_task_deadline
 create function workflow_case__get_task_deadline (varchar,varchar,varchar,integer,varchar)
-returns integer as '
+returns timestamp as '
 declare
   get_task_deadline__callback               alias for $1;  
   get_task_deadline__custom_arg             alias for $2;  
@@ -1069,7 +1069,7 @@
 
 -- function execute_hold_timeout_callback
 create function workflow_case__execute_hold_timeout_callback (varchar,varchar,integer,varchar)
-returns integer as '
+returns timestamp as '
 declare
   execute_hold_timeout_callback__callback               alias for $1;  
   execute_hold_timeout_callback__custom_arg             alias for $2;  
@@ -1435,7 +1435,93 @@
 
 
 
+    /* This procedure should be scheduled to run as a dbms_job. */
+create function sweep_timed_transitions () returns integer as '
+declare
+        v_journal_id    integer;
+        trans_rec       record;
+begin
+        for trans_rec in select t.task_id, t.case_id, tr.transition_name
+            from   wf_tasks t, wf_transitions tr
+            where  trigger_time <= now()
+            and    state = ''enabled''
+            and    tr.workflow_key = t.workflow_key
+            and    tr.transition_key = t.transition_key 
+        LOOP
+ 
+            /* Insert an entry to the journal so people will know it fired */
 
+            v_journal_id := journal_entry__new(
+                null,
+                trans_rec.case_id, 
+                ''task '' || trans_rec.task_id || '' fire time'',
+                trans_rec.transition_name || '' automatically finished'',
+                now(),
+                null,
+                null,
+                ''Timed transition fired.''
+            );
+        
+            /* Fire the transition */
+
+            PERFORM workflow_case__fire_transition_internal(
+                trans_rec.task_id,
+                v_journal_id
+            );
+
+            /* Update the workflow internal state */
+
+            PERFORM workflow_case___sweep_automatic_transitions(
+                trans_rec.case_id,
+                v_journal_id
+            );
+
+        end loop;
+
+        return 0;
+end;' language 'plpgsql';
+
+
+    /* This procedure should be scheduled to run as a dbms_job. */
+create function sweep_hold_timeout () returns integer as '
+declare
+        v_journal_id    integer;
+        task_rec        record;
+begin
+        for task_rec in select t.task_id, t.case_id, tr.transition_name
+            from   wf_tasks t, wf_transitions tr
+            where  hold_timeout <= now()
+            and    state = ''started''
+            and    tr.workflow_key = t.workflow_key
+            and    tr.transition_key = t.transition_key
+        LOOP
+ 
+            /* Insert an entry to the journal so people will know it was canceled */
+
+            v_journal_id := journal_entry__new(
+                null,
+                task_rec.case_id, 
+                ''task '' || task_rec.task_id || '' cancel timeout'',
+                task_rec.transition_name || '' timed out'', 
+                now(),
+                null,
+                null,
+                ''The user''''s hold on the task timed out and the task was automatically canceled''
+            );
+
+
+            /* Cancel the task */
+
+            PERFORM workflow_case__cancel_task(
+                task_rec.task_id,
+                v_journal_id
+            );
+
+        end loop;
+
+        returns 0;
+end;' language 'plpgsql';
+
 -- procedure notify_assignee
 create function workflow_case__notify_assignee (integer,integer,varchar,varchar)
 returns integer as '
